Fix for issue 57: highlight all instances of a selected word.
This commit is contained in:
parent
ce36cf2922
commit
71c347aacd
4 changed files with 45 additions and 2 deletions
|
|
@ -143,3 +143,8 @@
|
|||
position: absolute;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.ace_marker-layer .ace_selected_word {
|
||||
position: absolute;
|
||||
z-index: 6;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ var Editor =function(renderer, session) {
|
|||
this.$selectionMarker = null;
|
||||
this.$highlightLineMarker = null;
|
||||
this.$blockScrolling = 0;
|
||||
this.$selectedWordMarkers = [];
|
||||
|
||||
this.$search = new Search().set({
|
||||
wrap: true
|
||||
|
|
@ -235,6 +236,36 @@ var Editor =function(renderer, session) {
|
|||
}, 10);
|
||||
};
|
||||
|
||||
this.highlightSelection = function() {
|
||||
if (this.$selectedWordMarkers.length)
|
||||
this.clearSelectionHighlight();
|
||||
|
||||
var selectedRange = this.getSelectionRange();
|
||||
if (selectedRange.isEmpty())
|
||||
return;
|
||||
|
||||
var newOptions = {wrap:true, wholeWord: true};
|
||||
newOptions.needle = this.session.getTextRange(selectedRange);
|
||||
if (!newOptions.needle)
|
||||
return;
|
||||
|
||||
var currentOptions = this.$search.getOptions();
|
||||
this.$search.set(newOptions);
|
||||
|
||||
var ranges = this.$search.findAll(this.session);
|
||||
this.$selectedWordMarkers = [];
|
||||
ranges.forEach(function(range) {
|
||||
if (!range.contains(selectedRange.start.row, selectedRange.start.column))
|
||||
this.$selectedWordMarkers.push(this.renderer.addMarker(range, "ace_selected_word"));
|
||||
}, this);
|
||||
};
|
||||
|
||||
this.clearSelectionHighlight = function() {
|
||||
this.$selectedWordMarkers.forEach(function(marker) {
|
||||
this.renderer.removeMarker(marker);
|
||||
}, this);
|
||||
};
|
||||
|
||||
this.focus = function() {
|
||||
// Safari need the timeout
|
||||
// iOS and Firefox need it called immediately
|
||||
|
|
@ -323,6 +354,7 @@ var Editor =function(renderer, session) {
|
|||
}
|
||||
|
||||
this.onCursorChange(e);
|
||||
this.clearSelectionHighlight();
|
||||
};
|
||||
|
||||
this.onDocumentChangeBreakpoint = function() {
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ var MouseHandler = function(editor) {
|
|||
|
||||
this.onMouseDoubleClick = function(e) {
|
||||
this.editor.selection.selectWord();
|
||||
this.editor.highlightSelection();
|
||||
this.$clickSelection = this.editor.getSelectionRange();
|
||||
};
|
||||
|
||||
|
|
@ -165,4 +166,4 @@ var MouseHandler = function(editor) {
|
|||
}).call(MouseHandler.prototype);
|
||||
|
||||
exports.MouseHandler = MouseHandler;
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -131,6 +131,11 @@
|
|||
background: rgb(232, 242, 254);
|
||||
}
|
||||
|
||||
.ace-tm .ace_marker-layer .ace_selected_word {
|
||||
background: rgb(250, 250, 255);
|
||||
border: 1px solid rgb(200, 200, 250);
|
||||
}
|
||||
|
||||
.ace-tm .ace_string.ace_regex {
|
||||
color: rgb(255, 0, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue