Adds search options to find / find&replace

I use regex searches all the time for finding and replacing text
so I changed the searchbox extension a little bit to do what I want.
I added in the whole word and case sensitive options too. It works
nicely and updates the highlighted bits when the checkboxes change.
This commit is contained in:
Matthew Kastor 2013-03-25 05:15:32 -03:00 • committed by nightwing
commit 38a96a2a32

View file

@ -52,6 +52,11 @@ var html = '<div class="ace_search right">\
<button type="button" action="replace" class="ace_replacebtn">Replace</button>\
<button type="button" action="replaceAll" class="ace_replacebtn">All</button>\
</div>\
<div class="ace_search_options">\
<input id="regExp" type="checkbox"></input><label for="regExp">RegExp Search</label><br>\
<input id="caseSensitive" type="checkbox"></input><label for="caseSensitive">caseSensitive Search</label><br>\
<input id="wholeWord" type="checkbox"></input><label for="wholeWord">wholeWord Search</label>\
</div>\
</div>'.replace(/>\s+/g, ">");
var SearchBox = function(editor, range, showReplaceForm) {
@ -75,6 +80,10 @@ var SearchBox = function(editor, range, showReplaceForm) {
this.searchBox = sb.querySelector(".ace_search_form");
this.replaceBox = sb.querySelector(".ace_replace_form");
this.searchOptions = sb.querySelector(".ace_search_options");
this.regExp_option = sb.querySelector(".ace_search_options #regExp");
this.caseSensitive_option = sb.querySelector(".ace_search_options #caseSensitive");
this.wholeWord_option = sb.querySelector(".ace_search_options #wholeWord");
this.searchInput = this.searchBox.querySelector(".ace_search_field");
this.replaceInput = this.replaceBox.querySelector(".ace_search_field");
@ -115,6 +124,9 @@ var SearchBox = function(editor, range, showReplaceForm) {
event.addListener(this.replaceInput, "focus", function() {
_this.activeInput = _this.replaceInput;
});
event.addListener(this.searchOptions, "change", function() {
_this.find(false, false);
});
};
//keybinging outsite of the searchbox
@ -163,7 +175,10 @@ var SearchBox = function(editor, range, showReplaceForm) {
this.editor.find(this.searchInput.value, {
skipCurrent: skipCurrent,
backwards: backwards,
wrap: true
wrap: true,
regExp: this.regExp_option.checked,
caseSensitive: this.caseSensitive_option.checked,
wholeWord: this.wholeWord_option.checked
});
this.editor.session.highlight(this.editor.$search.$options.re);
};