diff --git a/src/features/editor/context.ts b/src/features/editor/context.ts index c102c98..732db12 100644 --- a/src/features/editor/context.ts +++ b/src/features/editor/context.ts @@ -113,6 +113,26 @@ export function createEditor(ref: Accessor, value: Accessor }, }); + DocumentEventListener({ + onSelectionchange(e) { + const selection = document.getSelection(); + + if (selection === null) { + return; + } + + if (selection.rangeCount === 0) { + return; + } + + if (document.activeElement !== ref()) { + return; + } + + updateSelection(selection.getRangeAt(0)!); + }, + }); + createEventListenerMap(() => ref()!, { keydown(e: KeyboardEvent) { // keyCode === 229 is a special code that indicates an IME event. @@ -134,26 +154,6 @@ export function createEditor(ref: Accessor, value: Accessor }, }); - DocumentEventListener({ - onSelectionchange(e) { - const selection = document.getSelection(); - - if (selection === null) { - return; - } - - if (selection.rangeCount === 0) { - return; - } - - if (document.activeElement !== ref()) { - return; - } - - updateSelection(selection.getRangeAt(0)!); - }, - }); - onMount(() => { updateControlBounds(); });