gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:20:08 31 4
gpt4 key购买 nike

您好 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")
});

有人可以帮我弄清楚要导入哪些脚本以及如何启用它吗?
谢谢。

最佳答案

它应该内置在标准版本中。

editor.execCommand('find');
应该显示搜索框。你也可以使用
editor.searchBox.show();
editor.searchBox.hide();
手动显示它(即实现您自己的键绑定(bind))。 Ace 内置了键绑定(bind),使用它们有优点(也有缺点,例如它们仅在您专注于编辑器时才有效)。如果你要实现自己的,你应该禁用内部的“find”命令。

关于javascript - 如何在 Ace 编辑器中启用搜索框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66681593/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com