Fix for issue 57: highlight all instances of a selected word.
This commit is contained in:
parent
b903679c1c
commit
b6e136201d
4 changed files with 45 additions and 2 deletions
|
|
@ -143,3 +143,8 @@
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 2;
|
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.$selectionMarker = null;
|
||||||
this.$highlightLineMarker = null;
|
this.$highlightLineMarker = null;
|
||||||
this.$blockScrolling = 0;
|
this.$blockScrolling = 0;
|
||||||
|
this.$selectedWordMarkers = [];
|
||||||
|
|
||||||
this.$search = new Search().set({
|
this.$search = new Search().set({
|
||||||
wrap: true
|
wrap: true
|
||||||
|
|
@ -235,6 +236,36 @@ var Editor =function(renderer, session) {
|
||||||
}, 10);
|
}, 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() {
|
this.focus = function() {
|
||||||
// Safari need the timeout
|
// Safari need the timeout
|
||||||
// iOS and Firefox need it called immediately
|
// iOS and Firefox need it called immediately
|
||||||
|
|
@ -323,6 +354,7 @@ var Editor =function(renderer, session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onCursorChange(e);
|
this.onCursorChange(e);
|
||||||
|
this.clearSelectionHighlight();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onDocumentChangeBreakpoint = function() {
|
this.onDocumentChangeBreakpoint = function() {
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,7 @@ var MouseHandler = function(editor) {
|
||||||
|
|
||||||
this.onMouseDoubleClick = function(e) {
|
this.onMouseDoubleClick = function(e) {
|
||||||
this.editor.selection.selectWord();
|
this.editor.selection.selectWord();
|
||||||
|
this.editor.highlightSelection();
|
||||||
this.$clickSelection = this.editor.getSelectionRange();
|
this.$clickSelection = this.editor.getSelectionRange();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -165,4 +166,4 @@ var MouseHandler = function(editor) {
|
||||||
}).call(MouseHandler.prototype);
|
}).call(MouseHandler.prototype);
|
||||||
|
|
||||||
exports.MouseHandler = MouseHandler;
|
exports.MouseHandler = MouseHandler;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,11 @@
|
||||||
background: rgb(232, 242, 254);
|
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 {
|
.ace-tm .ace_string.ace_regex {
|
||||||
color: rgb(255, 0, 0)
|
color: rgb(255, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue