Javascript 摩纳哥编辑器:如何以';操作。查找';

Javascript 摩纳哥编辑器:如何以';操作。查找';,javascript,typescript,visual-studio-code,monaco-editor,Javascript,Typescript,Visual Studio Code,Monaco Editor,很长一段时间以来,我一直在寻找一种方法、示例或信息,以了解如何将本机命令/操作订阅或侦听为actions.find 我的情况是——当用户使用编辑器工作台中的“查找匹配项”功能(通过键盘快捷键或上下文菜单调用)时,产生一些副作用,最后我希望在效果中获得“搜索”子字符串作为参数 希望社区能帮助我或放置一些类似的案例解决示例。在调试和研究monaco editor的源代码后,我发现,在我看来,使用API(IMHO)解决我的案例是正确的 我们可以使用FindController的API,这是每个实例中的

很长一段时间以来,我一直在寻找一种方法、示例或信息,以了解如何将本机命令/操作订阅或侦听为
actions.find

我的情况是——当用户使用编辑器工作台中的“查找匹配项”功能(通过键盘快捷键或上下文菜单调用)时,产生一些副作用,最后我希望在效果中获得“搜索”子字符串作为参数


希望社区能帮助我或放置一些类似的案例解决示例。

在调试和研究monaco editor的源代码后,我发现,在我看来,使用API(IMHO)解决我的案例是正确的

我们可以使用FindController的API,这是每个实例中的永久性贡献之一,我们可以使用公共方法onFindReplaceStateChange

//要从编辑器实例获取相关FindController,我们可以使用
var findController=editor.getContribution('editor.contrib.findController'))
//从FindController获取FindReplaceState的步骤
var findsearchtate=editor.getContribution('editor.contrib.findController').getState();
//订阅“查找匹配项”事件总线
editor.getContribution('editor.contrib.findController')
.getState().onFindReplaceStateChange(
(…rest)=>console.log('FindReplaceStateChange:',…rest)
);
//强制设置当前搜索子字符串(&S)
editor.getContribution('editor.contrib.findController').setSearchString('foo-bar');
//要以编程方式调用带有选项的搜索,
//不是“editor.getAction('actions.find').run()”(没有参数)
editor.getContribution('editor.contrib.findController').start({
forceRevealReplace:错误,
seedSearchStringFromSelection:false,
来自GlobalClipboard的种子搜索字符串:false,
应该关注:错误,
应该动画:错误,
updateSearchScope:false
});
我准备了一个示例,解释了如何在CodeSandbox上解决我的案例(多个编辑器之间的搜索同步)-


在调试和研究monaco editor的源代码后,我发现,在我看来,使用API(IMHO)解决我的问题是正确的

我们可以使用FindController的API,这是每个实例中的永久性贡献之一,我们可以使用公共方法onFindReplaceStateChange

//要从编辑器实例获取相关FindController,我们可以使用
var findController=editor.getContribution('editor.contrib.findController'))
//从FindController获取FindReplaceState的步骤
var findsearchtate=editor.getContribution('editor.contrib.findController').getState();
//订阅“查找匹配项”事件总线
editor.getContribution('editor.contrib.findController')
.getState().onFindReplaceStateChange(
(…rest)=>console.log('FindReplaceStateChange:',…rest)
);
//强制设置当前搜索子字符串(&S)
editor.getContribution('editor.contrib.findController').setSearchString('foo-bar');
//要以编程方式调用带有选项的搜索,
//不是“editor.getAction('actions.find').run()”(没有参数)
editor.getContribution('editor.contrib.findController').start({
forceRevealReplace:错误,
seedSearchStringFromSelection:false,
来自GlobalClipboard的种子搜索字符串:false,
应该关注:错误,
应该动画:错误,
updateSearchScope:false
});
我准备了一个示例,解释了如何在CodeSandbox上解决我的案例(多个编辑器之间的搜索同步)-