From b663a0b722e889cb1a057478764815c7a95875f9 Mon Sep 17 00:00:00 2001 From: Mahiro Komura Date: Sat, 28 Jul 2018 00:04:26 +0900 Subject: [PATCH] Fixed #2869 Improved to match line breaks using regular expressions in search box. --- lib/ace/ext/searchbox.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ace/ext/searchbox.js b/lib/ace/ext/searchbox.js index 854bc23860e..30bc57f09b2 100644 --- a/lib/ace/ext/searchbox.js +++ b/lib/ace/ext/searchbox.js @@ -265,7 +265,10 @@ var SearchBox = function(editor, range, showReplaceForm) { this.editor.renderer.updateBackMarkers(); }; this.find = function(skipCurrent, backwards, preventScroll) { - var range = this.editor.find(this.searchInput.value, { + var needle = this.searchInput.value; + if (this.regExpOption.checked) + needle = needle.replace(/\\r\\n/g, "\r\n").replace(/\\r/g, "\r").replace(/\\n/g, "\n"); + var range = this.editor.find(needle, { skipCurrent: skipCurrent, backwards: backwards, wrap: true, @@ -275,7 +278,7 @@ var SearchBox = function(editor, range, showReplaceForm) { preventScroll: preventScroll, range: this.searchRange }); - var noMatch = !range && this.searchInput.value; + var noMatch = !range && needle; dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); this.editor._emit("findSearchBox", { match: !noMatch }); this.highlight(); @@ -283,7 +286,8 @@ var SearchBox = function(editor, range, showReplaceForm) { }; this.updateCounter = function() { var editor = this.editor; - var regex = editor.$search.$options.re; + var re = editor.$search.$options.re; + var regex = re ? Array.isArray(re) ? new RegExp(re.map(x => x.source.replace(/\^?((?!\^).+?)\$?$/, "$1")).join("\n"), "gim") : re : null; var all = 0; var before = 0; if (regex) {