diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 74a82d1e..0471d6cc 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -23,6 +23,7 @@ * Fabian Jakobs * Irakli Gozalishvili (http://jeditoolkit.com) * Julian Viereck + * Mihai Sucan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -240,22 +241,39 @@ var Editor =function(renderer, session) { if (this.$selectionOccurrences.length) this.clearSelectionHighlight(); - var selectedRange = this.getSelectionRange(); - if (selectedRange.isEmpty()) + var selection = this.getSelectionRange(); + if (selection.isEmpty() || selection.isMultiLine()) return; - var newOptions = {wrap:true, wholeWord: true}; - newOptions.needle = this.session.getTextRange(selectedRange); - if (!newOptions.needle) + var startOuter = selection.start.column - 1; + var endOuter = selection.end.column + 1; + var line = this.session.getLine(selection.start.row); + var lineCols = line.length - 1; + var needle = line.substring(Math.max(startOuter, 0), + Math.min(endOuter, lineCols)); + + // Make sure the outer characters are not part of the word. + if ((startOuter >= 0 && !/[^\w\d]/.test(needle.charAt(0))) || + (endOuter <= lineCols && !/[^\w\d]/.test(needle.charAt(needle.length - 1)))) return; + needle = line.substring(selection.start.column, selection.end.column); + if (!/^[\w\d]+$/.test(needle)) + return; + + var newOptions = { + wrap: true, + wholeWord: true, + needle: needle, + }; + var currentOptions = this.$search.getOptions(); this.$search.set(newOptions); var ranges = this.$search.findAll(this.session); this.$selectionOccurrences = []; ranges.forEach(function(range) { - if (!range.contains(selectedRange.start.row, selectedRange.start.column)) + if (!range.contains(selection.start.row, selection.start.column)) this.$selectionOccurrences.push(this.renderer.addMarker(range, "ace_selected_word")); }, this); @@ -356,7 +374,7 @@ var Editor =function(renderer, session) { } this.onCursorChange(e); - this.clearSelectionHighlight(); + this.highlightSelection(); }; this.onDocumentChangeBreakpoint = function() { diff --git a/lib/ace/mouse_handler.js b/lib/ace/mouse_handler.js index 244fc461..b3a16833 100644 --- a/lib/ace/mouse_handler.js +++ b/lib/ace/mouse_handler.js @@ -146,7 +146,6 @@ var MouseHandler = function(editor) { this.onMouseDoubleClick = function(e) { this.editor.selection.selectWord(); - this.editor.highlightSelection(); this.$clickSelection = this.editor.getSelectionRange(); };