From 79f27b4f92279ecc5e6312fb3b0596c8734d54e2 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 1 Oct 2018 09:24:23 -0400 Subject: [PATCH] move select line behavior to buf.c and use it when jumping to specific line number --- inc/edit.h | 1 + lib/buf.c | 16 ++++++++++++++++ lib/view.c | 1 + tide.c | 15 +-------------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index 3c1f183..8fcca19 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -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); diff --git a/lib/buf.c b/lib/buf.c index ae11268..735f63d 100644 --- 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; diff --git a/lib/view.c b/lib/view.c index 50b0d50..0fc9d89 100644 --- a/lib/view.c +++ b/lib/view.c @@ -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 c79532b..092af28 100644 --- 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) { -- 2.52.0