codemirror搜索使用javascript模拟CTRL + F键(codemirror search simulate CTRL+F keys with javascript)

我正在尝试打开codemirror搜索对话框(通常按CTRL + F激活) 按下按钮:

我试着用

window.find()

但它没有打开对话框,它只突出显示编辑器中的文字...

DEMO

I'm trying to open the codemirror search dialog (normally activated by pressing CTRL+F) by pressing a button:

I tried to use

window.find()

but it does not open the dialog, it only highlights the text in the editor...

DEMO

最满意答案

您不想模拟实际按键。 相反,只需使用execCommand运行CodeMirror的find命令,如http://jsfiddle.net/cb1fd72k/1/

You don't want to simulate the actual key press. Rather, simply run CodeMirror's find command using execCommand, as in http://jsfiddle.net/cb1fd72k/1/

codemirror搜索使用javascript模拟CTRL + F键(codemirror search simulate CTRL+F keys with javascript)

我正在尝试打开codemirror搜索对话框(通常按CTRL + F激活) 按下按钮:

我试着用

window.find()

但它没有打开对话框,它只突出显示编辑器中的文字...

DEMO

I'm trying to open the codemirror search dialog (normally activated by pressing CTRL+F) by pressing a button:

I tried to use

window.find()

but it does not open the dialog, it only highlights the text in the editor...

DEMO

最满意答案

您不想模拟实际按键。 相反,只需使用execCommand运行CodeMirror的find命令,如http://jsfiddle.net/cb1fd72k/1/

You don't want to simulate the actual key press. Rather, simply run CodeMirror's find command using execCommand, as in http://jsfiddle.net/cb1fd72k/1/