如何在Ace编辑器中启用搜索框



你好,stackOverflow社区,这是我在这里的第一个问题,我想知道如何在Ace编辑器中启用搜索框。

我在这里有一个项目的最新演示。到目前为止,编辑有Emmet和Autocomplete。我需要的下一个功能是当用户在编辑器中按下CTRL+F时显示的搜索框。

这是我用来配置编辑器的代码:

let e = document.querySelector("#editor");
let editor = ace.edit(e);
let langTools = ace.require("ace/ext/language_tools");
let Emmet = require("ace/ext/emmet");
ace.config.set("basePath", "path");
ace.config.loadModule("ace/ext/searchbox", function(m) {m.Search(editor)});

editor.getSession().setMode("ace/mode/html");
editor.setOptions({
minLines: 24,
maxLines: 24,
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
enableEmmet: true
});
editor.session.setUseWrapMode(true);
editor.session.on("change", function () {
window.onbeforeunload = function () {
return "Changes you made might not be saved";
};
var unloadListener = function () {
return "Changes you made might not be saved";
};
window.addEventListener("beforeunload", unloadListener);
editor.execCommand("find")
});

有人能帮我弄清楚要导入什么脚本以及如何启用它吗?谢谢

它应该构建到标准构建中。

editor.execCommand('find');

应显示searchBox。你也可以使用

editor.searchBox.show();
editor.searchBox.hide();

手动显示(即实现自己的密钥绑定(。Ace内置了键绑定,使用它们有好处(也有缺点,比如它们只在您专注于编辑器时才起作用(。您应该禁用内部";查找";如果您要实现自己的命令。

最新更新