From 38a96a2a32b0b716509c296c6f3384f4f91f9e10 Mon Sep 17 00:00:00 2001 From: Matthew Kastor Date: Mon, 25 Mar 2013 05:15:32 -0300 Subject: [PATCH] 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. --- lib/ace/ext/searchbox.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/ace/ext/searchbox.js b/lib/ace/ext/searchbox.js index e2d97366..01a7adea 100644 --- a/lib/ace/ext/searchbox.js +++ b/lib/ace/ext/searchbox.js @@ -52,6 +52,11 @@ var html = '\ +
\ +
\ +
\ + \ +
\ '.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); };