我在我的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
,您会得到预填充文本的查找控件,因此我相信可以实现。任何帮助都将不胜感激。
查找控件:
![Find control](https://istack.dev59.com/kkC2f.webp)