]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added escape shortcut to select the last inserted text
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 23 Nov 2016 16:12:38 +0000 (11:12 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 23 Nov 2016 16:12:38 +0000 (11:12 -0500)
inc/edit.h
libedit/buf.c
libedit/view.c
xedit [deleted file]
xedit.c

index 848c8ebe1b19bb7eb4f775c7a22624030ee7f629..bf7b8a9762f35adb4912b80b2f0b7d5a47d2fe0d 100644 (file)
@@ -75,8 +75,8 @@ unsigned buf_byrune(Buf* buf, unsigned pos, int count);
 unsigned buf_byline(Buf* buf, unsigned pos, int count);
 unsigned buf_getcol(Buf* buf, unsigned pos);
 unsigned buf_setcol(Buf* buf, unsigned pos, unsigned col);
-char* buf_getstr(Buf* buf, unsigned beg, unsigned end);
-unsigned buf_putstr(Buf* buf, unsigned beg, unsigned end, char* str);
+void buf_lastins(Buf* buf, size_t* beg, size_t* end);
+void buf_loglock(Buf* buf);
 
 /*
 void buf_load(Buf* buf, char* path);
@@ -156,6 +156,7 @@ void view_byline(View* view, int move);
 void view_setcursor(View* view, size_t row, size_t col);
 void view_selext(View* view, size_t row, size_t col);
 void view_selword(View* view, size_t row, size_t col);
+void view_selprev(View* view);
 void view_select(View* view, size_t row, size_t col);
 char* view_fetch(View* view, size_t row, size_t col);
 void view_find(View* view, size_t row, size_t col);
index c87b4675d0ec40802cfff7aab5b28f0cf4a2eaa5..52e240a0f09d748e7ae36e5b42ef62787ef5e862 100644 (file)
@@ -404,3 +404,21 @@ unsigned buf_setcol(Buf* buf, unsigned pos, unsigned col) {
     }
     return curr;
 }
+
+void buf_lastins(Buf* buf, size_t* beg, size_t* end) {
+    Log* log = buf->undo;
+    while (log) {
+        if (log->insert)
+            break;
+        log = log->next;
+    }
+    if (log) {
+        *beg = log->data.ins.beg;
+        *end = log->data.ins.end;
+    }
+}
+
+void buf_loglock(Buf* buf) {
+    if (buf->undo)
+        buf->undo->locked = true;
+}
index 1fcf318c638ecdabd59d06a584d6af83af385870..f35634c4da87434dbd3c51ade5eb14a350e5cd48 100644 (file)
@@ -297,6 +297,12 @@ void view_selword(View* view, size_t row, size_t col) {
     view->selection = sel;
 }
 
+void view_selprev(View* view) {
+    Sel sel = view->selection;
+    buf_lastins(&(view->buffer), &sel.beg, &sel.end);
+    view->selection = sel;
+}
+
 void view_select(View* view, size_t row, size_t col) {
     view_setcursor(view, row, col);
     Sel sel = view->selection;
@@ -406,12 +412,14 @@ void view_redo(View* view) {
 }
 
 void view_putstr(View* view, char* str) {
+    buf_loglock(&(view->buffer));
     while (*str) {
         Rune rune = 0;
         size_t length = 0;
         while (!utf8decode(&rune, &length, *str++));
         view_insert(view, rune);
     }
+    buf_loglock(&(view->buffer));
 }
 
 char* view_getstr(View* view, Sel* range) {
diff --git a/xedit b/xedit
deleted file mode 100755 (executable)
index 41b247d..0000000
Binary files a/xedit and /dev/null differ
diff --git a/xedit.c b/xedit.c
index d18dbd22831ba4c773d66b803f4b911e6c493170..f06d9061099c13b1af2f1243370d669738883687 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -34,6 +34,7 @@ static void cursor_bol(void);
 static void cursor_eol(void);
 static void page_up(void);
 static void page_dn(void);
+static void select_prev(void);
 static void change_focus(void);
 static void quit(void);
 static void save(void);
@@ -101,6 +102,7 @@ static KeyBinding Insert[] = {
     { KEY_END,       cursor_eol   },
     { KEY_PGUP,      page_up      },
     { KEY_PGDN,      page_dn      },
+    { KEY_ESCAPE,    select_prev  },
     { KEY_CTRL_T,    change_focus },
     { KEY_CTRL_Q,    quit         },
     { KEY_CTRL_S,    save         },
@@ -359,6 +361,10 @@ static void page_dn(void) {
     view_scrollpage(currview(), +1);
 }
 
+static void select_prev(void) {
+    view_selprev(currview());
+}
+
 static void change_focus(void) {
     Focused = (Focused == TAGS ? EDIT : TAGS);
 }