javascript - How can I enable the Search Box in an Ace Editor? - Stack Overflow

Hello stackOverflow munity, this is my first question here and I'm wondering how to enable the Sea

Hello stackOverflow munity, this is my first question here and I'm wondering how to enable the Search Box in an Ace Editor.

I have a current demo of the project here. So far the editor has Emmet and Autoplete. The next feature I need is the search box showing when the user presses CTRL+F in the editor.

Here is the code I used to configure the editor:

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,
    enableBasicAutopletion: true,
    enableSnippets: true,
    enableLiveAutopletion: 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")
});

Can someone please help me to figure out what scripts to import and how to enable it? Thanks.

Hello stackOverflow munity, this is my first question here and I'm wondering how to enable the Search Box in an Ace Editor.

I have a current demo of the project here. So far the editor has Emmet and Autoplete. The next feature I need is the search box showing when the user presses CTRL+F in the editor.

Here is the code I used to configure the editor:

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,
    enableBasicAutopletion: true,
    enableSnippets: true,
    enableLiveAutopletion: 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")
});

Can someone please help me to figure out what scripts to import and how to enable it? Thanks.

Share Improve this question asked Mar 17, 2021 at 21:35 IroncladDevIroncladDev 1522 silver badges10 bronze badges 1
  • 1 ace.config.set("basePath", "path"); is probably a mistake ext-searchbox.js file is located at /path/ext-searchbox.js on your site – a user Commented Apr 13, 2021 at 13:14
Add a ment  | 

1 Answer 1

Reset to default 6

It should be built into a standard build.

editor.execCommand('find');

should display the searchBox. You can also use

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

to show it manually (ie to implement your own key bindings). Ace has built in key bindings and there are advantages to using them (as well as disadvantages, such as they only work when you are focused on the editor). You should disable the internal "find" mand if you're going to implement your own.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744748034a4591424.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信