Skip to content

Commit

Permalink
Properly track first composition change for edit context changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Apr 19, 2024
1 parent ae1c551 commit df2cb96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/domchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions src/domobserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df2cb96

Please sign in to comment.