你好,stackOverflow社区,这是我在这里的第一个问题,我想知道如何在Ace编辑器中启用搜索框。
我有一个here项目的最新演示。到目前为止,编辑器具有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")
});
有没有人可以帮我弄清楚要导入什么脚本以及如何启用它?谢谢。
发布于 2021-04-02 09:24:48
它应该被构建到一个标准构建中。
editor.execCommand('find');
应显示searchBox。您还可以使用
editor.searchBox.show();
editor.searchBox.hide();
手动显示它(即实现您自己的密钥绑定)。Ace内置了键绑定,使用它们有好处(也有缺点,比如只有当你专注于编辑器时才能工作)。如果你要实现自己的命令,你应该禁用内部的"find“命令。
https://stackoverflow.com/questions/66681593
复制相似问题