Skip to content

Commit

Permalink
fix(frontend): emojiPickerを使用して絵文字を挿入する際、refに直接挿入するように (#14282)
Browse files Browse the repository at this point in the history
* fix(frontend): emojiPickerを使用して絵文字を挿入する際、refに直接挿入するように

* add comment
  • Loading branch information
kakkokari-gtyih authored Jul 30, 2024
1 parent 3548ffb commit 9181eb2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/frontend/src/components/MkPostForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,23 @@ async function insertEmoji(ev: MouseEvent) {
textAreaReadOnly.value = true;
const target = ev.currentTarget ?? ev.target;
if (target == null) return;

// emojiPickerはダイアログが閉じずにtextareaとやりとりするので、
// focustrapをかけているとinsertTextAtCursorが効かない
// そのため、投稿フォームのテキストに直接注入する
// See: https://github.com/misskey-dev/misskey/pull/14282
// https://github.com/misskey-dev/misskey/issues/14274

let pos = textareaEl.value?.selectionStart ?? 0;
let posEnd = textareaEl.value?.selectionEnd ?? text.value.length;
emojiPicker.show(
target as HTMLElement,
emoji => {
insertTextAtCursor(textareaEl.value, emoji);
const textBefore = text.value.substring(0, pos);
const textAfter = text.value.substring(posEnd);
text.value = textBefore + emoji + textAfter;
pos += emoji.length;
posEnd += emoji.length;
},
() => {
textAreaReadOnly.value = false;
Expand Down

0 comments on commit 9181eb2

Please sign in to comment.