Skip to content

Commit

Permalink
[ISSUE #7] ITextModel.pushEditOperations will eventually create delet…
Browse files Browse the repository at this point in the history
…e ops when local ops are applied, which can lead to inconsistent ITextModels on the different clients. Using the ITextModel.applyEdits prevents these ops
  • Loading branch information
raedle committed Jan 7, 2021
1 parent 577f4ae commit 8ed54ef
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/y-monaco.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ export class MonacoBinding {
} else if (op.insert !== undefined) {
const pos = monacoModel.getPositionAt(index)
const range = new monaco.Selection(pos.lineNumber, pos.column, pos.lineNumber, pos.column)
monacoModel.pushEditOperations([], [{ range, text: op.insert }], () => null)
monacoModel.applyEdits([{ range, text: op.insert }])
index += op.insert.length
} else if (op.delete !== undefined) {
const pos = monacoModel.getPositionAt(index)
const endPos = monacoModel.getPositionAt(index + op.delete)
const range = new monaco.Selection(pos.lineNumber, pos.column, endPos.lineNumber, endPos.column)
monacoModel.pushEditOperations([], [{ range, text: '' }], () => null)
monacoModel.applyEdits([{ range, text: '' }])
} else {
throw error.unexpectedCase()
}
})
monacoModel.pushStackElement()
this._savedSelections.forEach((rsel, editor) => {
const sel = createMonacoSelectionFromRelativeSelection(editor, ytext, rsel, this.doc)
if (sel !== null) {
Expand Down

0 comments on commit 8ed54ef

Please sign in to comment.