我正在尝试在 Monaco Editor 中对事件进行一些基本播放,但是,每当我将编辑传递给 时,它总是将我的编辑executeEdits
重置为(如果我在调用之后收到消息,这就是我得到的)。实际上,我尝试插入或替换的任何文本总是在第一行的开头结束,并有效地反向键入文本。range
{ startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 }
console.log
executeEdits
import * as React from 'react'
import * as monaco from 'monaco-editor'
import { PlayerContext } from './player-context'
const defaultOptions = {
minimap: {
enabled: false
}
}
export default class MonacoEditor extends React.Component {
static contextType = PlayerContext
handleMessage = message => {
this._editor.executeEdits('', [
{ ...message, forceMoveMarkers: true }
])
}
componentDidMount() {
const { path, value, language, ...options } = this.props
const model = monaco.editor.createModel(value, language, path)
this._editor = monaco.editor.create(this._node, {
...defaultOptions,
...options
})
this._editor.setModel(model)
this.context.addMessageHandler('didChange', this.handleMessage)
}
componentWillUnmount() {
this._editor && this._editor.dispose()
this.context.removeMessageHandler('didChange', this.handleMessage)
}
render() {
return <div style={{ height: 500 }} ref={c => (this._node = c)} />
}
}
我正在使用 react 来渲染 Monaco 编辑器,如上所示。上下文提供了一个对象,它基本上允许我订阅播放事件,message
传递给的对象handleMessage
是IIdentifiedSingleEditOperation的形状
{
range: {
startLineNumber: 0,
startColumn: 47,
endLineNumber: 0,
endColumn: 47
},
text: '!'
}
为什么摩纳哥会重置我的编辑操作范围?