]> git.mdlowis.com Git - projs/tide.git/commitdiff
move select line behavior to buf.c and use it when jumping to specific line number
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 1 Oct 2018 13:24:23 +0000 (09:24 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 1 Oct 2018 13:24:23 +0000 (09:24 -0400)
inc/edit.h
lib/buf.c
lib/view.c
tide.c

index 3c1f1836f84dfbc6c41f593612fcc33faeed6824..8fcca1927955e7a00534381b40fafbe3734d41e7 100644 (file)
@@ -76,6 +76,7 @@ void buf_setcol(Buf* buf);
 
 size_t buf_selbeg(Buf* buf);
 size_t buf_selsz(Buf* buf);
+void buf_selln(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);
index ae1126819738c5b2fc733432a5a275cd972fe5f3..735f63db5de71c7bec9442efdfaf464287092011 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -649,6 +649,22 @@ size_t buf_selsz(Buf* buf) {
     return sel.end - sel.beg;
 }
 
+void buf_selln(Buf* buf) {
+    /* swap the direction of the selection so beg < end */
+    if (buf->selection.beg > buf->selection.end) {
+        size_t off = buf->selection.beg;
+        buf->selection.beg = buf->selection.end;
+        buf->selection.end = off;
+    }
+
+    /* Expand the selection to completely select the lines covered */
+    buf->selection.beg = buf_bol(buf, buf->selection.beg);
+    if (!buf_iseol(buf, buf->selection.end-1) || buf->selection.end == buf->selection.beg) {
+        buf->selection.end = buf_eol(buf, buf->selection.end);
+        buf->selection.end = buf_byrune(buf, buf->selection.end, RIGHT);
+    }
+}
+
 void buf_selclr(Buf* buf, int dir) {
     if (dir > 0)
         buf->selection.beg = buf->selection.end;
index 50b0d50a2b4e9249ab4624e8798be865d12cf61f..0fc9d892ee063596189dfa20d4eefb8d141e16da 100644 (file)
@@ -315,6 +315,7 @@ void view_eof(View* view, bool extsel) {
 void view_setln(View* view, size_t line) {
     buf_setln(BUF, line);
     view->sync_flags |= CENTER;
+    buf_selln(BUF);
 }
 
 void view_undo(View* view) {
diff --git a/tide.c b/tide.c
index c79532b965cdc2569c784a8ca52153d58a8c073d..092af286bd6c8e850bec5dabc85c2e9914a31434 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -97,20 +97,7 @@ void exec(char* cmd) {
 /* Keyboard and Tag Handlers
  ******************************************************************************/
 static void select_line(char* arg) {
-    Buf* buf = win_buf(FOCUSED);
-    /* swap the direction of the selection so beg < end */
-    if (buf->selection.beg > buf->selection.end) {
-        size_t off = buf->selection.beg;
-        buf->selection.beg = buf->selection.end;
-        buf->selection.end = off;
-    }
-
-    /* Expand the selection to completely select the lines covered */
-    buf->selection.beg = buf_bol(buf, buf->selection.beg);
-    if (!buf_iseol(buf, buf->selection.end-1) || buf->selection.end == buf->selection.beg) {
-        buf->selection.end = buf_eol(buf, buf->selection.end);
-        buf->selection.end = buf_byrune(buf, buf->selection.end, RIGHT);
-    }
+    buf_selln(win_buf(FOCUSED));
 }
 
 static void join_lines(char* arg) {