Skip to content

Commit

Permalink
React to selection-only changes in the edit context
Browse files Browse the repository at this point in the history
FIX: Fix an issue where native selection changes, such as mobile spacebar-drag,
weren't being picked up in edit context mode.

Closes codemirror/dev#1503
  • Loading branch information
marijnh committed Jan 9, 2025
1 parent 9c77d6d commit 4415fa9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/domobserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class EditContextManager {
selectionEnd: this.toContextPos(view.state.selection.main.head)
})
this.handlers.textupdate = e => {
let {anchor, head} = view.state.selection.main
let main = view.state.selection.main, {anchor, head} = main
let from = this.toEditorPos(e.updateRangeStart), to = this.toEditorPos(e.updateRangeEnd)
if (view.inputState.composing >= 0 && !this.composing)
this.composing = {contextBase: e.updateRangeStart, editorBase: from, drifted: false}
Expand All @@ -564,7 +564,11 @@ class EditContextManager {
else if (change.to == this.to && anchor > this.to) change.to = anchor

// Edit contexts sometimes fire empty changes
if (change.from == change.to && !change.insert.length) return
if (change.from == change.to && !change.insert.length) {
let newSel = EditorSelection.single(this.toEditorPos(e.selectionStart), this.toEditorPos(e.selectionEnd))
if (!newSel.main.eq(main)) view.dispatch({selection: newSel, userEvent: "select"})
return
}
if ((browser.mac || browser.android) && change.from == head - 1 &&
/^\. ?$/.test(e.text) && view.contentDOM.getAttribute("autocorrect") == "off")
change = {from, to, insert: Text.of([e.text.replace(".", " ")])}
Expand Down

0 comments on commit 4415fa9

Please sign in to comment.