From 55bc02435155646642ac2ea773625324520b5a4e Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 8 Apr 2018 20:43:40 -0400 Subject: [PATCH] implemented right-click search --- inc/edit.h | 1 + lib/buf.c | 10 ++++++++-- lib/view.c | 13 +++---------- lib/x11.c | 3 ++- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index 81e16ee..cec7c0f 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -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 *****************************************************************************/ diff --git a/lib/buf.c b/lib/buf.c index 6f9bd5a..45e6562 100644 --- 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; } - - diff --git a/lib/view.c b/lib/view.c index 16b5fd8..edfbf5e 100644 --- a/lib/view.c +++ b/lib/view.c @@ -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) diff --git a/lib/x11.c b/lib/x11.c index 3f430fa..fecfaf9 100644 --- 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); } } -- 2.52.0