我试图在摩纳哥编辑器中对事件进行一些基本的回放,但是,每当我将编辑传递给 executeEdits 时,它总是将我的编辑的 range 重置为 { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } (如果我在调用 executeEdits 后生成消息,就会得到这个消息)。实际上,我试图插入或替换的任何文本总是在第一行开头结束,并有效地反向键入文本。
executeEdits
range
{ startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 }
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渲染摩纳哥编辑器,如上面所示。上下文提供了一个对象,它基本上允许我订阅回放事件,传递给 handleMessage 的 handleMessage 对象的形状是 IIdentifiedSingleEditOperation 。
handleMessage
{ range: { startLineNumber: 0,