From: Michael D. Lowis Date: Thu, 27 Sep 2018 00:40:52 +0000 (-0400) Subject: added transaction logic to joining lines X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=5d54aee065017b863e83180262cf13e9742e67d7;p=projs%2Ftide.git added transaction logic to joining lines --- diff --git a/TODO.md b/TODO.md index 6a4eccd..e0b1657 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,6 @@ BUGS: * no magic right click -* use transaction processing for joining lines * implement mouse warping on search, jump to line, and focus change * gap buffer does not handle UTF-8 currently * mouse selection handling when mouse moves outside region diff --git a/tide.c b/tide.c index d9a1898..b16dd31 100644 --- a/tide.c +++ b/tide.c @@ -114,6 +114,7 @@ static void select_line(char* arg) { static void join_lines(char* arg) { View* view = win_view(FOCUSED); + buf_logstart(win_buf(FOCUSED)); view_eol(view, false); view_delete(view, RIGHT, false); Rune r = view_getrune(view); @@ -121,6 +122,7 @@ static void join_lines(char* arg) { view_byrune(view, RIGHT, true); if (r != '\n') buf_putc(win_buf(FOCUSED), ' '); + buf_logstop(win_buf(FOCUSED)); } static void delete(char* arg) { @@ -388,6 +390,12 @@ static void highlight(char* arg) { view_selctx(win_view(FOCUSED)); } +static void lnexec(char* cmd) { + if (!view_selsize(win_view(FOCUSED))) + select_line(NULL); + exec(cmd); +} + /* Main Routine ******************************************************************************/ static Tag Builtins[] = { @@ -442,8 +450,8 @@ static KeyBinding Bindings[] = { { .mods = ModAny, .key = KEY_BACKSPACE, .fn = backspace }, /* External command shortcuts */ - { .mods = ModCtrl, .key = '[', .fn = exec, .arg = "|i-" }, - { .mods = ModCtrl, .key = ']', .fn = exec, .arg = "|i+" }, + { .mods = ModCtrl, .key = '[', .fn = lnexec, .arg = "|i-" }, + { .mods = ModCtrl, .key = ']', .fn = lnexec, .arg = "|i+" }, /* Implementation Specific */ { .mods = ModNone, .key = KEY_ESCAPE, .fn = select_prev },