From 6583bc9a5e214bb7e0fbd2c24a7f93edc8f49a9f Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 4 Apr 2017 15:50:23 -0400 Subject: [PATCH] Fixed implementation bug in right-click search --- TODO.md | 4 +++- inc/edit.h | 4 ++-- lib/view.c | 6 ++++-- xedit.c | 9 +++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index 39cdd71..8d87ad3 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,8 @@ Up Next: -* Status line should omit characters from beginning of path to make file path fit +* fix crash on saving read-only file + * clipboard does not persist after exit * Run commands in the background and don't block the main thread. * Make Fn keys execute nth command in the tags buffer @@ -14,6 +15,7 @@ Up Next: * Add a GoTo tag for ctags lookup and line number jump (or right click magic?) * Add keyboard shortcut to highlight the thing under the cursor * right click to fetch file or line +* Status line should omit characters from beginning of path to make file path fit Straight-up Bugs: diff --git a/inc/edit.h b/inc/edit.h index cfb0bc5..2a12642 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -142,8 +142,8 @@ Row* view_getrow(View* view, size_t row); void view_byrune(View* view, int move, bool extsel); void view_byword(View* view, int move, bool extsel); void view_byline(View* view, int move, bool extsel); -char* view_fetchcmd(View* view, size_t row, size_t col); -void view_findstr(View* view, int dir, char* str); +char* view_fetch(View* view, size_t row, size_t col); +bool view_findstr(View* view, int dir, char* str); void view_insert(View* view, bool indent, Rune rune); void view_delete(View* view, int dir, bool byword); void view_bol(View* view, bool extsel); diff --git a/lib/view.c b/lib/view.c index 11ae3a2..22d543b 100644 --- a/lib/view.c +++ b/lib/view.c @@ -348,7 +348,7 @@ size_t view_selsize(View* view) { return num_selected(view->selection); } -char* view_fetchcmd(View* view, size_t row, size_t col) { +char* view_fetch(View* view, size_t row, size_t col) { char* str = NULL; size_t off = getoffset(view, row, col); if (off != SIZE_MAX) { @@ -364,12 +364,14 @@ char* view_fetchcmd(View* view, size_t row, size_t col) { return str; } -void view_findstr(View* view, int dir, char* str) { +bool view_findstr(View* view, int dir, char* str) { Sel sel = view->selection; buf_findstr(&(view->buffer), dir, str, &sel.beg, &sel.end); + bool found = (0 != memcmp(&sel, &(view->selection), sizeof(Sel))); view->selection = sel; view->sync_needed = true; view->sync_center = true; + return found; } void view_insert(View* view, bool indent, Rune rune) { diff --git a/xedit.c b/xedit.c index 53ab28e..9677ed8 100644 --- a/xedit.c +++ b/xedit.c @@ -168,7 +168,7 @@ void onmousemiddle(WinRegion id, size_t count, size_t row, size_t col) { if (win_btnpressed(MOUSE_BTN_LEFT)) { cut(); } else { - char* str = view_fetchcmd(win_view(id), row, col); + char* str = view_fetch(win_view(id), row, col); if (str) exec(str); free(str); } @@ -180,11 +180,8 @@ void onmouseright(WinRegion id, size_t count, size_t row, size_t col) { } else { SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1); free(SearchTerm); - SearchTerm = view_getstr(win_view(id), NULL); - Sel before = win_view(EDIT)->selection; - view_findstr(win_view(EDIT), SearchDir, SearchTerm); - Sel after = win_view(EDIT)->selection; - if (memcmp(&before, &after, sizeof(Sel))) { + SearchTerm = view_fetch(win_view(id), row, col); + if (view_findstr(win_view(EDIT), SearchDir, SearchTerm)) { win_setregion(EDIT); win_warpptr(EDIT); } -- 2.49.0