文章目录

playground https://microsoft.github.io/monaco-editor/playground.html#interacting-with-the-editor-listening-to-key-events

javascript 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var editor = monaco.editor.create(document.getElementById('container'), {
value: "function hello() {\n\talert('Hello world!');\n}",
language: 'javascript'
});

var myBinding = editor.addCommand(monaco.KeyCode.F9, function () {
alert('F9 pressed!');
});

// You can't dispose `addCommand`
// If you need to dispose it you might use `addAction` or `registerCommand`
changeModelContent = e => {
console.log('内容改变', this.editor.getValue());
let caretOffset = e.changes[0].rangeOffset; //获取光标位置
console.log(caretOffset)
};
editor.onDidChangeModelContent(this.changeModelContent);
文章目录