英文:
Open find widget with content programatically in Monaco
问题
我不知道如何在Monaco中打开带有内容的查找小部件。从查看其他扩展程序的代码,看起来我应该这样做:
editor.trigger("find", "editor.actions.findWithArgs", { searchString: "test" })
虽然这会打开查找小部件,但它不会更改搜索字符串。我也尝试了其他方法,尽管我可以像这样设置内容:
const controller = editor.getContribution("editor.contrib.findController")
controller.setSearchString("test")
我宁愿使用.trigger
,或者至少了解为什么它不起作用。
英文:
I can't figure out how to open the find widget with content in Monaco. From looking at some other extensions' code, it looks like I should do something like this:
editor.trigger("find", "editor.actions.findWithArgs", { searchString: "test" })
While this opens the find widget, it doesn't change the search string. I tried other ways too, and while I could do something like this to set the content:
const controller = editor.getContribution("editor.contrib.findController")
controller.setSearchString("test")
I would rather use .trigger, or at least understand why it doesn't work
答案1
得分: 0
第一行应该可以工作,但不管你信不信,这是一个已经在昨天修复的 2 年 bug:无法访问操作方法中的 payload
问题在于 payload
(这里是 { searchString: "test" }
)根本没有传递给操作的 run
方法 修复 https://github.com/microsoft/monaco-editor/issues/2547 #176504 如下所示:
附言:截止今天,修复尚未在可下载版本中发布。
英文:
The first line should work but, believe it or not, it's a 2 years bug that's been fixed yesterday: Can't access payload in action method
The issue is the payload
(so here { searchString: "test" }
) was simply not passed to the action's run
method Fixes https://github.com/microsoft/monaco-editor/issues/2547 #176504 as shown here:
PS: The fix is not yet release in the downloadable version as of today.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论