Skip to content

Commit

Permalink
More fixes.
Browse files Browse the repository at this point in the history
- Only highlight selected words.
- Highlight selected words by keyboard as well, not just mouse double click.
  • Loading branch information
mihaisucan committed Feb 13, 2011
1 parent 24e1357 commit 0c95983
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
32 changes: 25 additions & 7 deletions lib/ace/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -356,7 +374,7 @@ var Editor =function(renderer, session) {
}

this.onCursorChange(e);
this.clearSelectionHighlight();
this.highlightSelection();
};

this.onDocumentChangeBreakpoint = function() {
Expand Down
1 change: 0 additions & 1 deletion lib/ace/mouse_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ var MouseHandler = function(editor) {

this.onMouseDoubleClick = function(e) {
this.editor.selection.selectWord();
this.editor.highlightSelection();
this.$clickSelection = this.editor.getSelectionRange();
};

Expand Down

0 comments on commit 0c95983

Please sign in to comment.