From e886bf7de642bee35af1646f9df1e0e1d3fedd22 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 4 Apr 2017 10:12:44 -0400 Subject: [PATCH] Tweaked right click behavior to always search the content region --- TODO.md | 2 -- inc/edit.h | 1 - lib/view.c | 22 +--------------------- xedit.c | 10 +++++++--- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/TODO.md b/TODO.md index 3bd142a..39cdd71 100644 --- a/TODO.md +++ b/TODO.md @@ -9,13 +9,11 @@ Up Next: * check for file changes on save * check for file changes when window regains focus -* Right click in tags region should search edit region * 100% coverage with unit and unit-integration tests * Add a SaveAs tag that takes an argument for the filename to save as * 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 -* selecting text should set PRIMARY x11 selection Straight-up Bugs: diff --git a/inc/edit.h b/inc/edit.h index 445b46f..735c92f 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -143,7 +143,6 @@ 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_find(View* view, int dir, size_t row, size_t col); void 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); diff --git a/lib/view.c b/lib/view.c index ff04d6a..2a4de67 100644 --- a/lib/view.c +++ b/lib/view.c @@ -340,8 +340,7 @@ void view_select(View* view, size_t row, size_t col) { view_setcursor(view, row, col); Sel sel = view->selection; selcontext(view, &sel); - if (sel.end+1 < buf_end(&(view->buffer))) - sel.end++; + sel.end = buf_byrune(&(view->buffer), sel.end, RIGHT); view->selection = sel; } @@ -365,25 +364,6 @@ char* view_fetchcmd(View* view, size_t row, size_t col) { return str; } -void view_find(View* view, int dir, size_t row, size_t col) { - size_t off = getoffset(view, row, col); - if (off != SIZE_MAX) { - Sel sel = view->selection; - if (!num_selected(sel) || !in_selection(sel, off)) { - view_setcursor(view, row, col); - sel = view->selection; - selcontext(view, &sel); - buf_find(&(view->buffer), dir, &sel.beg, &sel.end); - sel.end++; - } else { - buf_find(&(view->buffer), dir, &sel.beg, &sel.end); - } - view->selection = sel; - view->sync_needed = true; - view->sync_center = true; - } -} - void view_findstr(View* view, int dir, char* str) { Sel sel = view->selection; buf_findstr(&(view->buffer), dir, str, &sel.beg, &sel.end); diff --git a/xedit.c b/xedit.c index c471b02..fa4951e 100644 --- a/xedit.c +++ b/xedit.c @@ -180,9 +180,14 @@ void onmouseright(WinRegion id, size_t count, size_t row, size_t col) { } else { SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1); free(SearchTerm); - view_find(win_view(id), SearchDir, row, col); SearchTerm = view_getstr(win_view(id), NULL); - win_warpptr(id); + 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))) { + win_setregion(EDIT); + win_warpptr(EDIT); + } } } @@ -555,4 +560,3 @@ int main(int argc, char** argv) { return 0; } #endif - -- 2.49.0