打开Monaco编辑器中的查找小部件并通过编程方式设置内容。

huangapple go评论72阅读模式
英文:

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 如下所示:

打开Monaco编辑器中的查找小部件并通过编程方式设置内容。

附言:截止今天,修复尚未在可下载版本中发布。

英文:

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:

打开Monaco编辑器中的查找小部件并通过编程方式设置内容。

PS: The fix is not yet release in the downloadable version as of today.

huangapple
  • 本文由 发表于 2023年3月9日 22:31:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685974.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定