forked from ajaxorg/ace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Only highlight selected words. - Highlight selected words by keyboard as well, not just mouse double click.
- Loading branch information
1 parent
24e1357
commit 0c95983
Showing
2 changed files
with
25 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
* Fabian Jakobs <fabian AT ajax DOT org> | ||
* Irakli Gozalishvili <[email protected]> (http://jeditoolkit.com) | ||
* Julian Viereck <[email protected]> | ||
* Mihai Sucan <[email protected]> | ||
* | ||
* 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() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters