]> git.mdlowis.com Git - projs/tide.git/commitdiff
refactored command handling while pty active
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 22 Nov 2019 03:49:06 +0000 (22:49 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 22 Nov 2019 03:49:06 +0000 (22:49 -0500)
src/lib/buf.c
src/lib/xpty.c
src/tide.c

index b2aafafc4ff75bb4645b89dc9ef2d0a9cad32627..c5350c13827d7cce032a29d09e97fc105fc883ed 100644 (file)
@@ -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);
 
index d551149d1f2c214d6139cd88c890a03f9d301030..6d38db41f635cf0a1947846c9704b9b702b5044e 100644 (file)
@@ -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);
     }
index b13302c21cdd752bf8902122403945e66e226b33..d915970a2934a1fb47026025c5a97fbaf0b029a7 100644 (file)
@@ -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);
 }