]> git.mdlowis.com Git - projs/tide.git/commitdiff
implemented right-click search
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 9 Apr 2018 00:43:40 +0000 (20:43 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 9 Apr 2018 00:43:40 +0000 (20:43 -0400)
inc/edit.h
lib/buf.c
lib/view.c
lib/x11.c

index 81e16ee2678d37f1d414af5489cf50cd269053fb..cec7c0f9771d089dea207a13a01b13fb40d52d83 100644 (file)
@@ -81,6 +81,7 @@ void buf_setcol(Buf* buf);
 size_t buf_selsz(Buf* buf);
 void buf_selclr(Buf* buf, int dir);
 bool buf_insel(Buf* buf, size_t off);
+char* buf_fetch(Buf* buf, bool (*isword)(Rune), size_t off);
 
 /* Screen management functions
  *****************************************************************************/
index 6f9bd5a14267ba199e8f6dcda898dcfeaf37dec4..45e65626295b0731f0ce7959bdc46617f6c8c7dd 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -426,6 +426,14 @@ bool buf_insel(Buf* buf, size_t off) {
     return (off >= sel.beg && off < sel.end);
 }
 
+char* buf_fetch(Buf* buf, bool (*isword)(Rune), size_t off) {
+    if (!buf_insel(buf, off)) {
+        buf->selection = (Sel){ .beg = off, .end = off };
+        buf_selword(buf, isword);
+    }
+    return buf_gets(buf);
+}
+
 /******************************************************************************/
 
 static void selblock(Buf* buf, Rune first, Rune last) {
@@ -461,5 +469,3 @@ static void selblock(Buf* buf, Rune first, Rune last) {
     if (end > beg) beg++; else end++;
     buf->selection.beg = beg, buf->selection.end = end;
 }
-
-
index 16b5fd8e21259ccbd1f3fc2fa529ff987120b318..edfbf5e3e578402c2f54008270d07b305d8eb3fc 100644 (file)
@@ -141,15 +141,8 @@ size_t view_selsize(View* view) {
 char* view_fetch(View* view, size_t row, size_t col, bool (*isword)(Rune)) {
    char* str = NULL;
     size_t off = getoffset(view, row, col);
-    if (off != SIZE_MAX) {
-        /* str = buf_fetchat(buf, isword, off) */
-//        Sel sel = { .beg = off, .end = off };
-//        if (buf_insel(BUF, NULL, off))
-//            sel = *(getsel(view));
-//        else
-//            buf_selword(BUF, isword, &sel);
-//        str = view_getstr(view, &sel);
-    }
+    if (off != SIZE_MAX)
+        str = buf_fetch(BUF, isword, off);
     return str;
 }
 
@@ -298,7 +291,7 @@ static void move_selection(View* view, bool extsel, int move, movefn_t bything)
         if (bything == buf_byline)
             buf_setcol(BUF);
         if (!extsel)
-            buf_selclr(BUF, move);
+            buf_selclr(BUF, RIGHT);
     }
     /* only update column if not moving vertically */
     if (bything != buf_byline)
index 3f430fa0481ba44d6fa2f47bc108e60eae31e359..fecfaf96670052e64c603e0e388ecf5f1f2f98e2 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -30,6 +30,7 @@ static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col);
 static void draw_view(int i, size_t nrows, drawcsr* csr, int bg, int fg, int sel);
 static void draw_hrule(drawcsr* csr);
 static void draw_scroll(drawcsr* csr);
+static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t ncols);
 
 static void xupdate(Job* job);
 static void xfocus(XEvent* e);
@@ -65,7 +66,6 @@ static void (*EventHandlers[LASTEvent])(XEvent*) = {
 
 enum { FontCacheSize = 16 };
 
-static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t ncols);
 static WinRegion getregion(size_t x, size_t y);
 static struct XSel* selfetch(Atom atom);
 static void xftcolor(XftColor* xc, int id);
@@ -710,6 +710,7 @@ static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col) {
         SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1);
         free(SearchTerm);
         SearchTerm = view_fetch(win_view(id), row, col, risfile);
+        view_findstr(win_view(id), SearchDir, SearchTerm);
     }
 }