小编owe*_*col的帖子

摩纳哥编辑器 - 用文本预填充查找控件

我在我的 React 应用程序中托管了一个摩纳哥编辑器。

到目前为止,我已经让编辑器在编辑器安装后打开查找控件,但我需要用一些文本预先填充它。

目前的代码如下所示:

... 

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>
    )
  }
}
...
Run Code Online (Sandbox Code Playgroud)

我认为 API 文档并不清楚这是否可行。

我的第一直觉是这样做, editor.getAction('actions.find').run('text here') 但这似乎行不通

当您在编辑器本身中突出显示一个单词,然后按下时,CMD+F您将获得预先填充文本的查找控件,因此我相信这是可以实现的。

任何帮助,将不胜感激。

查找控件: 查找控件

javascript reactjs visual-studio-monaco monaco-editor

3
推荐指数
1
解决办法
1828
查看次数