search rewrite
This commit is contained in:
parent
675386fc4c
commit
3d774aa2b6
4 changed files with 300 additions and 269 deletions
|
|
@ -1954,65 +1954,84 @@ var Editor = function(renderer, session) {
|
|||
};
|
||||
|
||||
/** related to: Search.find
|
||||
* Editor.find(needle, options)
|
||||
* - needle (String): The text to search for
|
||||
* Editor.find(needle, options)
|
||||
* - needle (String): The text to search for (optional)
|
||||
* - options (Object): An object defining various search properties
|
||||
* - animate (Boolean): If `true` animate scrolling
|
||||
*
|
||||
* Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]].
|
||||
**/
|
||||
this.find = function(needle, options, animate) {
|
||||
this.clearSelection();
|
||||
options = options || {};
|
||||
options.needle = needle;
|
||||
if (!options)
|
||||
options = {};
|
||||
|
||||
if (typeof needle == "string" || needle instanceof RegExp)
|
||||
options.needle = needle;
|
||||
else if (typeof needle == "object")
|
||||
oop.mixin(options, needle);
|
||||
|
||||
var range = this.selection.getRange();
|
||||
if (options.needle == null) {
|
||||
needle = this.session.getTextRange(range)
|
||||
|| this.$search.$options.needle;
|
||||
if (!needle) {
|
||||
range = this.session.getWordRange(range.start.row, range.start.column);
|
||||
needle = this.session.getTextRange(range);
|
||||
}
|
||||
this.$search.set({needle: needle});
|
||||
}
|
||||
|
||||
this.$search.set(options);
|
||||
this.$find(options.backwards, animate);
|
||||
if (!options.start)
|
||||
this.$search.set({start: range});
|
||||
|
||||
var newRange = this.$search.find(this.session);
|
||||
if (options.preventScroll)
|
||||
return newRange;
|
||||
if (newRange) {
|
||||
this.revealRange(newRange, animate);
|
||||
return newRange;
|
||||
}
|
||||
// clear selection if nothing is found
|
||||
if (options.backwards)
|
||||
range.start = range.end;
|
||||
else
|
||||
range.end = range.start;
|
||||
this.selection.setRange(range);
|
||||
};
|
||||
|
||||
/** related to: Editor.find
|
||||
* Editor.findNext(options)
|
||||
* Editor.findNext(options)
|
||||
* - options (Object): search options
|
||||
* - animate (Boolean): If `true` animate scrolling
|
||||
*
|
||||
*
|
||||
* Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]].
|
||||
**/
|
||||
this.findNext = function(options, animate) {
|
||||
options = options || {};
|
||||
this.$search.set(options);
|
||||
this.$find(false, animate);
|
||||
this.find({skipCurrent: true, backwards: false}, options, animate);
|
||||
};
|
||||
|
||||
/** related to: Editor.find
|
||||
* Editor.findPrevious(options)
|
||||
* Editor.findPrevious(options)
|
||||
* - options (Object): search options
|
||||
* - animate (Boolean): If `true` animate scrolling
|
||||
*
|
||||
*
|
||||
* Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]].
|
||||
**/
|
||||
this.findPrevious = function(options, animate) {
|
||||
options = options || {};
|
||||
this.$search.set(options);
|
||||
this.$find(true, animate);
|
||||
this.find(options, {skipCurrent: true, backwards: true}, animate);
|
||||
};
|
||||
|
||||
this.$find = function(backwards, animate) {
|
||||
if (!this.selection.isEmpty())
|
||||
this.$search.set({needle: this.session.getTextRange(this.getSelectionRange())});
|
||||
this.revealRange = function(range, animate) {
|
||||
this.$blockScrolling += 1;
|
||||
this.session.unfold(range);
|
||||
this.selection.setSelectionRange(range);
|
||||
this.$blockScrolling -= 1;
|
||||
|
||||
if (typeof backwards != "undefined")
|
||||
this.$search.set({backwards: backwards});
|
||||
|
||||
var range = this.$search.find(this.session);
|
||||
if (range) {
|
||||
this.$blockScrolling += 1;
|
||||
this.session.unfold(range);
|
||||
this.selection.setSelectionRange(range);
|
||||
this.$blockScrolling -= 1;
|
||||
|
||||
var scrollTop = this.renderer.scrollTop;
|
||||
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
|
||||
var scrollTop = this.renderer.scrollTop;
|
||||
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
|
||||
if (animate != false)
|
||||
this.renderer.animateScrolling(scrollTop);
|
||||
}
|
||||
};
|
||||
|
||||
/** related to: UndoManager.undo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue