From 5b30e4cfdeb9ffcaad11b4b15b32f7241c807695 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 9 Jan 2019 12:40:51 -0500 Subject: [PATCH] changed argument handling code to fix usability issue for Ctrl+D --- TODO.md | 1 - src/tide.c | 44 +++++++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/TODO.md b/TODO.md index 86a7808..24ee76f 100644 --- 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 diff --git a/src/tide.c b/src/tide.c index c5f8c36..625a2f6 100644 --- a/src/tide.c +++ b/src/tide.c @@ -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) { -- 2.51.0