[incremental search] forward / backward movement
This commit is contained in:
parent
3e6a036995
commit
d6be35e8e1
2 changed files with 47 additions and 10 deletions
|
|
@ -76,24 +76,36 @@ oop.inherits(IncrementalSearch, Search);
|
|||
delete this.$editor;
|
||||
}
|
||||
|
||||
iSearch.highlightAndFindWithNeedle = function(dir, moveToMatch, needleUpdateFunc) {
|
||||
iSearch.cancelSearch = function() {
|
||||
var session = this.$editor.session,
|
||||
sel = this.$editor.selection;
|
||||
this.$options.needle = '';
|
||||
session.highlight(null);
|
||||
sel.setRange(this.$startRange);
|
||||
return this.$currentRange = this.$startRange;
|
||||
}
|
||||
|
||||
iSearch.highlightAndFindWithNeedle = function(dir, moveToNext, needleUpdateFunc) {
|
||||
if (!this.$editor) return null;
|
||||
dir = dir || 'forward';
|
||||
var session = this.$editor.session,
|
||||
options = this.$options;
|
||||
if (needleUpdateFunc) options.needle = needleUpdateFunc(options.needle || '') || '';
|
||||
if (options.needle.length === 0) {
|
||||
return this.cancelSearch();
|
||||
}
|
||||
if (dir === "forward") {
|
||||
options.start = this.$currentRange.end;
|
||||
options.start = moveToNext ? this.$currentRange.end : this.$currentRange.start;
|
||||
options.backwards = false;
|
||||
} else {
|
||||
options.start = this.$currentRange.start;
|
||||
options.start = moveToNext ? this.$currentRange.start : this.$currentRange.end;
|
||||
options.backwards = true;
|
||||
}
|
||||
var range = this.find(session);
|
||||
if (range && moveToMatch) {
|
||||
this.$editor.selection.setRange(range);
|
||||
this.$currentRange = range;
|
||||
}
|
||||
if (!range) range = this.$currentRange;
|
||||
|
||||
this.$editor.selection.setRange(range);
|
||||
this.$currentRange = range;
|
||||
|
||||
session.highlight(options.re);
|
||||
return range;
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ module.exports = {
|
|||
highlightRanges = callHighlighterUpdate(editor.session);
|
||||
testRanges("Range: [0/3] -> [0/5]", [range], "range");
|
||||
testRanges("Range: [0/3] -> [0/5],Range: [1/3] -> [1/5]", highlightRanges, "highlight");
|
||||
|
||||
range = iSearch.addChar('3'); // "123"
|
||||
highlightRanges = callHighlighterUpdate(editor.session);
|
||||
testRanges("Range: [0/3] -> [0/6]", [range], "range");
|
||||
|
|
@ -99,12 +100,36 @@ module.exports = {
|
|||
highlightRanges = callHighlighterUpdate(editor.session);
|
||||
testRanges("Range: [0/3] -> [0/5]", [range], "range");
|
||||
testRanges("Range: [0/3] -> [0/5],Range: [1/3] -> [1/5]", highlightRanges, "highlight");
|
||||
},
|
||||
|
||||
range = iSearch.forward(); // "12", cursor forward
|
||||
highlightRanges = callHighlighterUpdate(editor.session);
|
||||
"test: forward / backward" : function() {
|
||||
iSearch.activate(editor);
|
||||
iSearch.addChar('1'); iSearch.addChar('2');
|
||||
var range = iSearch.forward();
|
||||
testRanges("Range: [1/3] -> [1/5]", [range], "range");
|
||||
testRanges("Range: [0/3] -> [0/5],Range: [1/3] -> [1/5]", highlightRanges, "highlight");
|
||||
|
||||
range = iSearch.forward();
|
||||
testRanges("Range: [1/3] -> [1/5]", [range], "range");
|
||||
|
||||
range = iSearch.backward();
|
||||
testRanges("Range: [0/3] -> [0/5]", [range], "range");
|
||||
},
|
||||
|
||||
"test: cancelSearch" : function() {
|
||||
iSearch.activate(editor);
|
||||
iSearch.addChar('1'); iSearch.addChar('2');
|
||||
var range = iSearch.cancelSearch();
|
||||
testRanges("Range: [0/0] -> [0/0]", [range], "range");
|
||||
|
||||
iSearch.addChar('1'); range = iSearch.addChar('2');
|
||||
testRanges("Range: [0/3] -> [0/5]", [range], "range");
|
||||
},
|
||||
|
||||
"test: failing search keeps range" : function() {
|
||||
iSearch.activate(editor);
|
||||
iSearch.addChar('1'); iSearch.addChar('2');
|
||||
var range = iSearch.addChar('x');
|
||||
testRanges("Range: [0/3] -> [0/5]", [range], "range");
|
||||
}
|
||||
|
||||
// // "test: find simple text in document" : function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue