[incremental search] refining forward/backward behavior
This commit is contained in:
parent
1423893c3b
commit
901585024b
2 changed files with 14 additions and 6 deletions
|
|
@ -105,14 +105,15 @@ oop.inherits(IncrementalSearch, Search);
|
|||
} else {
|
||||
options.start = moveToNext ? range.start : range.end;
|
||||
}
|
||||
range = this.find(session) || range;
|
||||
var oldRange = this.$editor.selection.toOrientedRange();
|
||||
var found = this.find(session);
|
||||
|
||||
// if (dir === "backward") range = Range.fromPoints(range.end, range.start);
|
||||
this.$editor.selection.setRange(range, options.backwards);
|
||||
this.$currentRange = range;
|
||||
this.$editor.selection.setRange(found || oldRange || range, options.backwards);
|
||||
if (found && moveToNext) this.$currentRange = found;
|
||||
|
||||
session.highlight(options.re);
|
||||
return range;
|
||||
return found || oldRange || range;
|
||||
}
|
||||
|
||||
this.addChar = function(c) {
|
||||
|
|
@ -128,6 +129,7 @@ oop.inherits(IncrementalSearch, Search);
|
|||
}
|
||||
|
||||
iSearch.next = function(backwards) {
|
||||
this.$currentRange = this.$editor.selection.toOrientedRange();
|
||||
this.$options.backwards = backwards;
|
||||
return this.highlightAndFindWithNeedle(true);
|
||||
}
|
||||
|
|
@ -173,8 +175,7 @@ oop.inherits(IncrementalSearch, Search);
|
|||
if (key === 's' || key === 'r') {
|
||||
if (this.$options.needle.length === 0)
|
||||
this.$options.needle = this.$prevNeedle || '';
|
||||
this.$options.backwards = key === 'r';
|
||||
this.forward();
|
||||
this.next(key === 'r');
|
||||
result = stop;
|
||||
}
|
||||
if (key === 'g') { this.deactivate(true); this.message(''); return stop; }
|
||||
|
|
|
|||
|
|
@ -130,6 +130,13 @@ module.exports = {
|
|||
iSearch.addChar('1'); iSearch.addChar('2');
|
||||
var range = iSearch.addChar('x');
|
||||
testRanges("Range: [0/3] -> [0/5]", [range], "range");
|
||||
},
|
||||
|
||||
"test: backwards search" : function() {
|
||||
editor.moveCursorTo(1,0);
|
||||
iSearch.activate(editor, true);
|
||||
iSearch.addChar('1'); var range = iSearch.addChar('2');;
|
||||
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