From df2cb96ff5feab9fd988785d6157a54e45ab131b Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 19 Apr 2024 13:24:12 +0200 Subject: [PATCH] Properly track first composition change for edit context changes --- src/domchange.ts | 2 +- src/domobserver.ts | 10 ++++++++-- src/input.ts | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/domchange.ts b/src/domchange.ts index f862a05..07d3364 100644 --- a/src/domchange.ts +++ b/src/domchange.ts @@ -220,7 +220,7 @@ function applyDefaultInsert(view: EditorView, change: {from: number, to: number, } let userEvent = "input.type" if (view.composing || - view.inputState.compositionPendingChange && view.inputState.compositionEndedAt > Date.now() - 50) { + view.inputState.compositionPendingChange && view.inputState.compositionEndedAt > Date.now() - 50) { view.inputState.compositionPendingChange = false userEvent += ".compose" if (view.inputState.compositionFirstChange) { diff --git a/src/domobserver.ts b/src/domobserver.ts index 28960e6..e4a3888 100644 --- a/src/domobserver.ts +++ b/src/domobserver.ts @@ -575,9 +575,15 @@ class EditContextManager { view.dispatch({effects: setEditContextFormatting.of(Decoration.set(deco))}) }) context.addEventListener("compositionstart", () => { - if (view.inputState.composing < 0) view.inputState.composing = 0 + if (view.inputState.composing < 0) { + view.inputState.composing = 0 + view.inputState.compositionFirstChange = true + } + }) + context.addEventListener("compositionend", () => { + view.inputState.composing = -1 + view.inputState.compositionFirstChange = null }) - context.addEventListener("compositionend", () => view.inputState.composing = -1) this.measureReq = {read: view => { this.editContext!.updateControlBounds(view.contentDOM.getBoundingClientRect()) diff --git a/src/input.ts b/src/input.ts index b77b317..016d61f 100644 --- a/src/input.ts +++ b/src/input.ts @@ -820,7 +820,6 @@ observers.compositionstart = observers.compositionupdate = view => { observers.compositionend = view => { if (view.observer.editContext) return // Composition handled by edit context - // FIXME check if any of these hacks are needed with edit context view.inputState.composing = -1 view.inputState.compositionEndedAt = Date.now() view.inputState.compositionPendingKey = true