Search code examples
monaco-editor

Questions about the onDidChangeModelContent event in Monaco


The description of changes in onDidChangeModelContent in the monaco document is:

Properties

Readonly changes changes: IModelContentChange[]

Document link

What confuses me is that I only get one changes every time I type.

changes: [{…}] // one change
eol: "\n"
isFlush: false
isRedoing: false
isUndoing: false
versionId: 23

I want to ask under what circumstances will I get multiple changes. such as:

changes: [{…},{…}] // multiple change
eol: "\n"
isFlush: false
isRedoing: false
isUndoing: false
versionId: 23

I'm very much obliged to you


Solution

  • You will get multiple changes when you have multiple carets active. By default the editor control allows to set multiple carets in the text (use opt/alt and left click to set an additional caret). When you then type a letter, it will be inserted in all places where a caret is, creating so multiple change events for a single action.