From d7ec94e70be31475afb7f5552e13d5d4e269ccbc Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 17 May 2017 22:16:17 -0400 Subject: [PATCH] tweaked copy command to select current line if nothing selected --- inc/shortcuts.h | 18 ++++++++++++------ lib/buf.c | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/inc/shortcuts.h b/inc/shortcuts.h index 91e1e42..0756d73 100644 --- a/inc/shortcuts.h +++ b/inc/shortcuts.h @@ -1,3 +1,9 @@ +static void select_line(void) { + View* view = win_view(FOCUSED); + view_eol(view, false); + view_selctx(view); +} + static void delete(void) { bool byword = x11_keymodsset(ModCtrl); view_delete(win_view(FOCUSED), RIGHT, byword); @@ -8,14 +14,11 @@ static void onpaste(char* text) { } static void cut(void) { - View* view = win_view(FOCUSED); /* select the current line if no selection */ - if (!view_selsize(view)) { - view_eol(view, false); - view_selctx(view); - } + if (!view_selsize(win_view(FOCUSED))) + select_line(); /* now perform the cut */ - char* str = view_getstr(view, NULL); + char* str = view_getstr(win_view(FOCUSED), NULL); x11_sel_set(CLIPBOARD, str); if (str && *str) delete(); } @@ -25,6 +28,9 @@ static void paste(void) { } static void copy(void) { + /* select the current line if no selection */ + if (!view_selsize(win_view(FOCUSED))) + select_line(); char* str = view_getstr(win_view(FOCUSED), NULL); x11_sel_set(CLIPBOARD, str); } diff --git a/lib/buf.c b/lib/buf.c index e5afc32..00655f1 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -198,6 +198,7 @@ static size_t next_size(size_t curr) { int size = 1; while(size < curr) size = (size << 1); + return size; } unsigned buf_load(Buf* buf, char* path) { -- 2.51.0