src/Builder4/Editor.bjs
authorAlan <alan@roojs.com>
Thu, 18 Aug 2022 10:00:52 +0000 (18:00 +0800)
committerAlan <alan@roojs.com>
Thu, 18 Aug 2022 10:00:52 +0000 (18:00 +0800)
src/Builder4/Editor.vala

src/Builder4/Editor.bjs
src/Builder4/Editor.vala

index 1e85293..7fcf326 100644 (file)
     ""
    ],
    "| void backSearch" : [
-    "() {",
+    "(bool change_focus) {",
     "",
-    "}"
+    "\tif (this.searchcontext == null) {",
+    "\t\treturn;",
+    "\t} ",
+    "\t",
+    "\tGtk.TextIter beg, st,en;",
+    "\t ",
+    "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end);",
+    "\tif (!this.searchcontext.back(beg, out st, out en)) {",
+    "\t",
+    "\t\tthis.last_search_end = 0;",
+    "\t} else {",
+    "\t\tthis.last_search_end = en.get_offset();",
+    "\t\tif (change_focus) {",
+    "\t\t\tthis.view.el.grab_focus();",
+    "\t\t}",
+    "\t\tthis.buffer.el.place_cursor(st);",
+    "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
+    "\t}",
+    " ",
+    "}",
+    ""
    ],
    "| void forwardSearch" : [
     "(bool change_focus) {",
index 052d6e5..edeae34 100644 (file)
@@ -143,8 +143,27 @@ public class Editor : Object
         }
      
     }
-    public void backSearch () {
+    public void backSearch (bool change_focus) {
     
+       if (this.searchcontext == null) {
+               return;
+       } 
+       
+       Gtk.TextIter beg, st,en;
+        
+       this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
+       if (!this.searchcontext.back(beg, out st, out en)) {
+       
+               this.last_search_end = 0;
+       } else {
+               this.last_search_end = en.get_offset();
+               if (change_focus) {
+                       this.view.el.grab_focus();
+               }
+               this.buffer.el.place_cursor(st);
+               this.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
+       }
+     
     }
     public int search (string txt) {