From 2d7111778c78aeea212ceff907aa4149872564f9 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 26 May 2017 21:44:07 -0400 Subject: [PATCH] tweaked ctrl+d behavior to select based on context --- TODO.md | 1 - lib/view.c | 14 ++++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/TODO.md b/TODO.md index 9f849c9..eeba371 100644 --- a/TODO.md +++ b/TODO.md @@ -4,7 +4,6 @@ Up Next: * Change PageUp/Dn to move cursor by screenfuls * Add Ctrl+Shift+A shortcut to select all -* ctrl+d with no selection does word selection instead of context * move by words is inconsistent. Example: var infoId = 'readerinfo'+reader.id; * Add a way to CD using a builtin (buffers will track original dir) diff --git a/lib/view.c b/lib/view.c index 34c2a62..a47ea03 100644 --- a/lib/view.c +++ b/lib/view.c @@ -309,7 +309,7 @@ void view_selext(View* view, size_t row, size_t col) { } } -static void selcontext(View* view, Sel* sel) { +static void selcontext(View* view, bool (*isword)(Rune), Sel* sel) { Buf* buf = &(view->buffer); size_t bol = buf_bol(buf, sel->end); Rune r = buf_get(buf, sel->end); @@ -323,7 +323,7 @@ static void selcontext(View* view, Sel* sel) { sel->beg = bol; sel->end = buf_eol(buf, sel->end); } else if (risword(r)) { - buf_getword(buf, risword, sel); + buf_getword(buf, isword, sel); } else { buf_getword(buf, risbigword, sel); } @@ -354,7 +354,7 @@ void view_select(View* view, size_t row, size_t col) { buf_loglock(&(view->buffer)); view_setcursor(view, row, col); Sel sel = view->selection; - selcontext(view, &sel); + selcontext(view, risword, &sel); sel.end = buf_byrune(&(view->buffer), sel.end, RIGHT); sel.col = buf_getcol(&(view->buffer), sel.end); view->selection = sel; @@ -533,16 +533,14 @@ char* view_getstr(View* view, Sel* range) { char* view_getcmd(View* view) { Sel sel = view->selection; - if (!num_selected(sel)) { - buf_getword(&(view->buffer), riscmd, &sel); - sel.end++; - } + if (!num_selected(sel)) + selcontext(view, riscmd, &sel); return view_getstr(view, &sel); } void view_selctx(View* view) { if (!num_selected(view->selection)) { - selcontext(view, &(view->selection)); + selcontext(view, risword, &(view->selection)); view->selection.end = buf_byrune( &(view->buffer), view->selection.end, RIGHT); view->selection.col = buf_getcol(&(view->buffer), view->selection.end); -- 2.54.0