- old_callback.call(this);
- };
-
- $.wiki.Perspective.call(this, options);
- };
-
- SearchPerspective.prototype = new $.wiki.Perspective();
-
- SearchPerspective.prototype.search = function(){
- var self = this;
- var query = self.$searchInput.val();
+ search(forward=true) {
+ var self = this;
+ var query = self.$searchInput.val();
+
+ if (!self.editor)
+ self.editor = $.wiki.perspectiveForTab('#CodeMirrorPerspective').codemirror
+
+ if (!self.searchCursor) {
+ var options = {};
+ options.caseFold = !self.options['search-case-sensitive'];
+ var start = 0;
+ if (self.options['search-from-cursor']) {
+ start = self.editor.getCursor();
+ }
+ self.searchCursor = self.editor.getSearchCursor(
+ self.$searchInput.val(),
+ start,
+ options
+ );
+ }
+ if (forward ? self.searchCursor.findNext() : self.searchCursor.findPrevious()) {
+ self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to());
+ self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20);
+ self.$replaceButton.removeAttr("disabled");
+ return true;
+ }
+ else {
+ self.searchCursor = null;
+ this.$replaceButton.attr("disabled","disabled");
+ return false;
+ }
+ }