From: Michael D. Lowis Date: Fri, 22 Nov 2019 03:49:06 +0000 (-0500) Subject: refactored command handling while pty active X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=175bb65595729221c547b6c374efc305c6e03d91;p=projs%2Ftide.git refactored command handling while pty active --- diff --git a/src/lib/buf.c b/src/lib/buf.c index b2aafaf..c5350c1 100644 --- a/src/lib/buf.c +++ b/src/lib/buf.c @@ -367,8 +367,9 @@ void buf_del(Buf* buf) if (nbytes > 0) { /* adjust the point according to the characters deleted */ - size_t bpoint = ((sel.beg <= buf->point.beg) ? (buf->point.beg - sel.beg) : 0u); - size_t inpoint = (min(buf->point.end, sel.end) - max(buf->point.beg, sel.beg)); + size_t bpoint = ((sel.beg <= buf->point.beg) ? min(nbytes, buf->point.beg - sel.beg) : 0u); + size_t inpoint = (buf->point.beg < sel.end && sel.end <= buf->point.end) + ? (sel.end - buf->point.beg) : 0u ; buf->point.beg -= bpoint; buf->point.end -= (bpoint + inpoint); diff --git a/src/lib/xpty.c b/src/lib/xpty.c index d551149..6d38db4 100644 --- a/src/lib/xpty.c +++ b/src/lib/xpty.c @@ -18,7 +18,7 @@ static void putb(int byte) { char* str = buf_getsat(&(EditView->buffer), EditView->buffer.point.beg, EditView->buffer.point.end); EditView->buffer.point.beg = EditView->buffer.point.end; - printf("write '%s'\n", str); +// printf("write '%s'\n", str); writefd(Pty_Fd, str, strlen(str)); free(str); } diff --git a/src/tide.c b/src/tide.c index b13302c..d915970 100644 --- a/src/tide.c +++ b/src/tide.c @@ -14,6 +14,7 @@ #include "config.h" /* predeclare some things */ +static void exec_or_send(char* str); static void exec(char* cmd, char* arg); void cut(char* arg); void paste(char* arg); @@ -177,7 +178,7 @@ static void xmousebtn(XConf* x, XEvent* e) case MouseActExec: { char* str = view_fetch(win_view(Focused), row, col, riscmd); - if (str) exec(str, NULL); + exec_or_send(str); free(str); break; } @@ -508,6 +509,21 @@ static void exec(char* cmd, char* arg) } } +static void exec_or_send(char* str) +{ + if (str) + { + if (xpty_active()) + { + xpty_send(str); + } + else + { + exec(str, NULL); + } + } +} + /* Keyboard and Tag Handlers ******************************************************************************/ static void change_focus(char* arg) @@ -575,17 +591,7 @@ static void execute(char* arg) { (void)arg; char* str = view_getcmd(win_view(FOCUSED)); - if (str) - { - if (xpty_active()) - { - xpty_send(str); - } - else - { - exec(str, NULL); - } - } + exec_or_send(str); free(str); }