Skip to content

Commit

Permalink
Make sure change touch-ups don't move the change outside the parsed r…
Browse files Browse the repository at this point in the history
…ange
  • Loading branch information
marijnh committed Mar 4, 2022
1 parent 0c3a9a3 commit a071368
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/domchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function readDOMChange(view, from, to, typeOver, addedNodes) {

let sel = view.state.selection
let parse = parseBetween(view, from, to)

// Chrome sometimes leaves the cursor before the inserted text when
// composing after a cursor wrapper. This moves it forward.
if (browser.chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from) {
Expand Down Expand Up @@ -138,9 +139,11 @@ export function readDOMChange(view, from, to, typeOver, addedNodes) {
if (view.state.selection.from < view.state.selection.to &&
change.start == change.endB &&
view.state.selection instanceof TextSelection) {
if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2) {
if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 &&
view.state.selection.from >= parse.from) {
change.start = view.state.selection.from
} else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2) {
} else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2 &&
view.state.selection.to <= parse.to) {
change.endB += (view.state.selection.to - change.endA)
change.endA = view.state.selection.to
}
Expand Down

0 comments on commit a071368

Please sign in to comment.