我在我的 React 应用程序中托管了一个 Monaco 编辑器。
到目前为止,我已经让编辑器在安装编辑器时打开查找控件,但我需要用一些文本预先填充它。
目前的代码如下所示:
...
class CodeEditorMonaco extends Component {
constructor (props) {
super(props)
this.editorDidMount = this.editorDidMount.bind(this)
this.editor = null
}
editorDidMount (editor, monaco) {
editor.focus()
editor.getAction('actions.find').run()
}
render () {
return (
<div className='code-editor'>
<MonacoEditor
width='100%'
height='75vh'
language='json'
editorDidMount={this.editorDidMount}
ref={editor => { this.editor = editor }}
/>
</div>
)
}
}
...
我认为 API 文档并不清楚这是否可行。
我的第一直觉是这样做
editor.getAction('actions.find').run('text here')
,但这似乎不起作用
当您在编辑器本身中突出显示一个单词,然后按下CMD+F
您会得到预填充文本的查找控件,所以我相信这是可以实现的。
任何帮助,将不胜感激。