]> git.mdlowis.com Git - projs/tide.git/commitdiff
tweaked ctrl+d behavior to select based on context
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 27 May 2017 01:44:07 +0000 (21:44 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 27 May 2017 01:44:07 +0000 (21:44 -0400)
TODO.md
lib/view.c

diff --git a/TODO.md b/TODO.md
index 9f849c91935c6845aa4507b71fe87e2fe8861d8f..eeba37123fc9c4a32545a44d1eaf29d7afc57da4 100644 (file)
--- 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)
index 34c2a62c8896a27da0165e2a88b7b7bd82571874..a47ea03213e6a9a4e88b0c9000f196f3cf3b8c2c 100644 (file)
@@ -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);