[incremental search] properly forward/backward wrapping on same term

This commit is contained in:
Robert Krahn 2013-03-10 10:50:12 -07:00
commit 4708bac758
2 changed files with 19 additions and 17 deletions

View file

@ -3,7 +3,7 @@
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

View file

@ -67,7 +67,8 @@ oop.inherits(IncrementalSearch, Search);
iSearch.activate = function(editor, backwards) {
this.$editor = editor;
var pos = editor.getCursorPosition();
this.$startRange = this.$currentRange = Range.fromPoints(pos, pos);
this.$startPos = this.$currentPos = pos;
// this.$startRange = this.$currentRange = Range.fromPoints(pos, pos);
// this.$startRange = this.$currentRange = editor.selection.toOrientedRange();
this.installKeyboardHandler(editor);
this.$options.needle = '';
@ -85,9 +86,13 @@ oop.inherits(IncrementalSearch, Search);
this.$prevNeedle = this.$options.needle;
this.$options.needle = '';
e.session.highlight(null);
if (reset) e.selection.setRange(this.$startRange);
else e.selection.clearSelection();
return this.$currentRange = this.$startRange;
if (reset) {
e.moveCursorTo(this.$startPos);
this.$currentPos = this.$startPos;
} else {
e.selection.clearSelection();
}
return Range.fromPoints(this.$currentPos, this.$currentPos);
}
iSearch.highlightAndFindWithNeedle = function(moveToNext, needleUpdateFunc) {
@ -99,21 +104,17 @@ oop.inherits(IncrementalSearch, Search);
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
var session = this.$editor.session, range = this.$currentRange;
if (!options.backwards) {
options.start = moveToNext ? range.end : range.start;
} else {
options.start = moveToNext ? range.start : range.end;
}
var session = this.$editor.session, pos = this.$currentPos;
options.start = pos;
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(found || oldRange || range, options.backwards);
if (found && moveToNext) this.$currentRange = found;
this.$editor.selection.setRange(found || oldRange, options.backwards);
if (found && moveToNext) this.$currentPos = options.backwards ? found.end : found.start;
session.highlight(options.re);
return found || oldRange || range;
return found || oldRange;
}
this.addChar = function(c) {
@ -129,7 +130,8 @@ oop.inherits(IncrementalSearch, Search);
}
iSearch.next = function(backwards) {
this.$currentRange = this.$editor.selection.toOrientedRange();
var currentRange = this.$editor.selection.toOrientedRange();
this.$currentPos = this.$options.backwards ? currentRange.start : currentRange.end;
this.$options.backwards = backwards;
return this.highlightAndFindWithNeedle(true);
}
@ -184,7 +186,7 @@ oop.inherits(IncrementalSearch, Search);
// return stop;
}
this.message('isearch: ' + this.$options.needle);
this.message((this.$options.backwards ? 'reverse-' : '') + 'isearch: ' + this.$options.needle);
// this.deactivate();
return result;