X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..cf5dddce80a2b4fe4d5f8c87cc709050c0efb36e:/src/redakcja/static/js/wiki/view_search.js?ds=inline diff --git a/src/redakcja/static/js/wiki/view_search.js b/src/redakcja/static/js/wiki/view_search.js index b49671c6..09f64dab 100644 --- a/src/redakcja/static/js/wiki/view_search.js +++ b/src/redakcja/static/js/wiki/view_search.js @@ -6,8 +6,7 @@ function SearchPerspective(options){ var old_callback = options.callback || function() { }; - this.noupdate_hash_onenter = true; - this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ'; + this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ'; options.callback = function(){ var self = this; @@ -17,6 +16,7 @@ this.$searchInput = $('#search-input', this.$element); this.$replaceInput = $('#replace-input', this.$element); this.$searchButton = $('#search-button', this.$element); + this.$searchPrevButton = $('#search-prev-button', this.$element); this.$replaceButton = $('#replace-button', this.$element); this.$replaceButton.attr("disabled","disabled"); @@ -42,6 +42,11 @@ alert('Brak wyników.'); }); + this.$searchPrevButton.click(function(){ + if (!self.search(false)) + alert('Brak wyników.'); + }); + this.$replaceButton.click(function(){ self.replace(); }); @@ -49,12 +54,12 @@ old_callback.call(this); }; - $.wiki.Perspective.call(this, options); + $.wiki.SidebarPerspective.call(this, options); }; - SearchPerspective.prototype = new $.wiki.Perspective(); + SearchPerspective.prototype = new $.wiki.SidebarPerspective(); - SearchPerspective.prototype.search = function(){ + SearchPerspective.prototype.search = function(forward=true){ var self = this; var query = self.$searchInput.val(); @@ -62,14 +67,21 @@ 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(), - self.options['search-from-cursor'], - !self.options['search-case-sensitive'] + start, + options ); } - if (self.searchCursor.findNext()) { - self.searchCursor.select(); + 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; } @@ -88,7 +100,10 @@ self.search(); } else {} - self.searchCursor.select(); + + self.editor.setSelection(self.searchCursor.from(), self.searchCursor.to()); + self.editor.scrollIntoView({from: self.searchCursor.from(), to: self.searchCursor.to()}, 20); + self.searchCursor.replace(query); if(self.search() && self.options['replace-all']) { self.replace(); @@ -98,12 +113,9 @@ SearchPerspective.prototype.onEnter = function(success, failure){ var self = this; - $.wiki.Perspective.prototype.onEnter.call(this); + $.wiki.SidebarPerspective.prototype.onEnter.call(this); self.$searchCursor = null; - $('.vsplitbar').not('.active').trigger('click'); - $(".vsplitbar-title").html("↓ ZNAJDŹ I ZAMIEŃ ↓"); - if ($.wiki.activePerspective() != 'CodeMirrorPerspective') $.wiki.switchToTab('#CodeMirrorPerspective'); };