]> git.mdlowis.com Git - projs/tide.git/commitdiff
added transaction logic to joining lines
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 27 Sep 2018 00:40:52 +0000 (20:40 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 27 Sep 2018 00:40:52 +0000 (20:40 -0400)
TODO.md
tide.c

diff --git a/TODO.md b/TODO.md
index 6a4eccd6bfded52f91947e5d897749d927d4f200..e0b1657633ffccb979afa82fe31426f27e2c7a34 100644 (file)
--- 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 d9a18985e91513885741e3a8c393b015ee2ab320..b16dd3105b40a2dd5a3a68298b773190391e9598 100644 (file)
--- 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  },