Fixes #4191: backward search.
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 19 Apr 2021 11:19:00 +0000 (13:19 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 19 Apr 2021 11:19:00 +0000 (13:19 +0200)
src/redakcja/static/js/wiki/view_search.js
src/wiki/templates/wiki/tabs/search_view.html

index e8f9e1b..09f64da 100644 (file)
@@ -16,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");
                     alert('Brak wyników.');
             });
 
+            this.$searchPrevButton.click(function(){
+                if (!self.search(false))
+                    alert('Brak wyników.');
+            });
+
             this.$replaceButton.click(function(){
                 self.replace();
             });
@@ -53,7 +59,7 @@
 
     SearchPerspective.prototype = new $.wiki.SidebarPerspective();
 
-    SearchPerspective.prototype.search = function(){
+    SearchPerspective.prototype.search = function(forward=true){
         var self = this;
         var query = self.$searchInput.val();
 
@@ -73,7 +79,7 @@
                 options
             );
         }
-        if (self.searchCursor.findNext()) {
+        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");
index e54b879..23067b5 100644 (file)
@@ -6,6 +6,7 @@
   </div>
   <div class="form-group">
     <button id='search-button' class="btn btn-primary">{% trans "Search" %}</button>
+    <button id='search-prev-button' class="btn btn-primary">&#8592;</button>
   </div>
   <div class="form-group">
     <label for="replace-input">{% trans "Replace with" %}:</label>