首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >摩纳哥编辑器-使用文本预填充查找控件

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

Stack Overflow用户
提问于 2017-08-11 08:00:33
回答 2查看 2.8K关注 0票数 3

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

到目前为止,我已经让编辑器在编辑器挂载时打开find控件,但是我需要用一些文本预填充它。

目前的代码如下所示:

代码语言:javascript
复制
... 

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控件,所以我相信这是可能的。

任何帮助都将不胜感激。

找到控制室:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-07-11 17:32:08

有一种方法可以做你想做的事,也可以做你已经描述过的事情:

  1. 为要搜索的术语选择文本。 editor.setSelection(new monaco.Range(18, 8, 18, 15));
  2. 触发查找操作 editor.trigger('', 'actions.find');editor.getAction('actions.find').run('');
票数 3
EN

Stack Overflow用户

发布于 2018-09-28 09:14:59

你可以在摩纳哥游乐场试一试。

代码语言:javascript
复制
const editor = monaco.editor.create(document.getElementById("container"), {
    value: "{\n\t\"dependencies\": {\n\t\t\n\t}\n}\n",
    language: "json"
});

const model = editor.getModel();
const range = model.findMatches('d')[0].range;

editor.setSelection(range);
editor.getAction('actions.find').run();

首先,从模型中获取要查找的字符串的范围。第二,设定选择。第三,触发选择动作。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45629937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档