]> git.mdlowis.com Git - projs/tide.git/commitdiff
changed argument handling code to fix usability issue for Ctrl+D view-rework
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 9 Jan 2019 17:40:51 +0000 (12:40 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 9 Jan 2019 17:40:51 +0000 (12:40 -0500)
TODO.md
src/tide.c

diff --git a/TODO.md b/TODO.md
index 86a780865c6681c3359b411c54ac1968dc815240..24ee76faf0b05c368f06310dd32ae5820ce284b8 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -7,7 +7,6 @@
 * registrar: doesnt match open windows when new file created and is then opened for edit or line number
 * registrar: group by hostname or group env var in registrar
 * registrar: should remove invalid windows from registry when detected
-* tide: Ctrl+D should not pass tag name as arg when executing tag commands
 * tide: gap buffer does not handle UTF-8 currently
 * pick can return null if mouse clicked on empty row
 
index c5f8c36cacb375e0107194ae5da9cf405426422c..625a2f6bd51b7b1c0f4efa43742f6a34f99454b9 100644 (file)
@@ -16,7 +16,7 @@
 #include "config.h"
 
 /* predeclare some things */
-void exec(char* cmd);
+void exec(char* cmd, char* arg);
 void cut(char* arg);
 void paste(char* arg);
 
@@ -38,6 +38,7 @@ static int FontSel;
 static bool SyncMouse = false;
 static int SearchDir = DOWN;
 static char* SearchTerm = NULL;
+static int ExecRequest = 0;
 
 #define PRESSED(btn) \
     ((KeyBtnState & (1 << (btn + 7))) == (1 << (btn + 7)))
@@ -116,7 +117,15 @@ static void mouse_left(WinRegion id, bool pressed, size_t row, size_t col) {
     if (PRESSED(MouseRight)) {
         puts("fetch tag");
     }  else if (PRESSED(MouseMiddle)) {
-        puts("exec with arg");
+        /* if we didnt get an arg, find one in the selection */
+        char* arg = NULL;
+        if (!arg || !*arg) arg = view_getstr(win_view(EDIT));
+        if (!arg || !*arg) arg = view_getstr(win_view(TAGS));
+        char* str = view_fetch(win_view(id), row, col, riscmd);
+        if (str) exec(str, arg);
+        free(str);
+        free(arg);
+        ExecRequest = 0;
     } else {
         if (count == 1)
             view_setcursor(win_view(id), row, col, win_keymodsset(ModShift));
@@ -128,12 +137,12 @@ static void mouse_left(WinRegion id, bool pressed, size_t row, size_t col) {
 }
 
 static void mouse_middle(WinRegion id, bool pressed, size_t row, size_t col) {
-    if (pressed) return;
+    if (pressed) { ExecRequest = 1; return; }
     if (PRESSED(MouseLeft)) {
         cut(NULL);
-    } else {
+    } else if (ExecRequest) {
         char* str = view_fetch(win_view(id), row, col, riscmd);
-        if (str) exec(str);
+        if (str) exec(str, NULL);
         free(str);
     }
 }
@@ -219,7 +228,7 @@ static void xbtnpress(XConf* x, XEvent* e) {
 static void xbtnrelease(XConf* x, XEvent* e) {
     (void)x;
     Now = e->xbutton.time;
-    KeyBtnState = (e->xbutton.state & ~(1 << (e->xbutton.button + 7)));
+    KeyBtnState = (KeyBtnState & ~(1 << (e->xbutton.button + 7)));
     mouse_click(e->xbutton.button, false, e->xbutton.x,  e->xbutton.y);
 }
 
@@ -401,15 +410,6 @@ static Tag* tag_lookup(char* cmd) {
     return NULL;
 }
 
-static void tag_exec(Tag* tag, char* arg) {
-    /* if we didnt get an arg, find one in the selection */
-    if (!arg || !*arg) arg = view_getstr(win_view(TAGS));
-    if (!arg || !*arg) arg = view_getstr(win_view(EDIT));
-    /* execute the tag handler */
-    tag->action(!arg || !*arg ? NULL : arg);
-    free(arg);
-}
-
 static void cmd_exec(char* cmd) {
     /* parse the command sigils */
     char op = '\0', **execcmd = NULL;
@@ -441,7 +441,7 @@ static void cmd_execwitharg(char* cmd, char* arg) {
     free(cmd);
 }
 
-void exec(char* cmd) {
+void exec(char* cmd, char* arg) {
     /* skip leading space */
     for (; *cmd && isspace(*cmd); cmd++);
     if (!*cmd) return;
@@ -450,7 +450,13 @@ void exec(char* cmd) {
     if (tag) {
         for (; *cmd && !isspace(*cmd); cmd++); /* strip off tag name */
         for (; *cmd && isspace(*cmd); cmd++);  /* strip off leading space */
-        tag_exec(tag, (*cmd ? strdup(cmd) : NULL));
+        //tag_exec(tag, (*cmd ? strdup(cmd) : arg));
+        arg = (*cmd ? strdup(cmd) : arg);
+        tag->action(!arg || !*arg ? NULL : arg);
+    } else if (arg) {
+        cmd = (arg ? strmcat(cmd, " '", arg, "'", 0) : strmcat(cmd));
+        cmd_exec(cmd);
+        free(cmd);
     } else {
         cmd_exec(cmd);
     }
@@ -685,7 +691,7 @@ static void search(char* arg) {
 static void execute(char* arg) {
     (void)arg;
     char* str = view_getcmd(win_view(FOCUSED));
-    if (str) exec(str);
+    if (str) exec(str, NULL);
     free(str);
 }
 
@@ -784,7 +790,7 @@ static void highlight(char* arg) {
 
 static void lnexec(char* cmd) {
     select_line(NULL);
-    exec(cmd);
+    exec(cmd, NULL);
 }
 
 static void tag_kill(char* cmd) {