]> git.mdlowis.com Git - projs/tide.git/commitdiff
add shortcut to jump back to previous cursor location
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 26 May 2017 02:08:01 +0000 (22:08 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 26 May 2017 02:08:01 +0000 (22:08 -0400)
TODO.md
docs/xedit.1.md
inc/edit.h
lib/view.c
xedit.c

diff --git a/TODO.md b/TODO.md
index ece4464a2d18da50025207e038b711d415cb4c32..ded4f4ff789df7f49ae0c7dfdef9302e05d2e144 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -3,7 +3,6 @@
 Up Next:
 
 * ctrl+d with no selection does word selection instead of context
-* add config option to change default tab style
 * get rid of edit wrapper script
 * move by words is inconsistent. Example:
     var infoId = 'readerinfo'+reader.id;
@@ -13,7 +12,6 @@ Up Next:
 * Make Fn keys execute nth command in the tags buffers
 * Add a way to CD using a builtin
 * Ctrl+PageUp/Dn to move cursor by screenfuls
-* Ctrl+Shift+g to jump to undo a goto line action
 * Ctrl+\ Shortcut to warp cursor to middle of current screen.
 * Find shortcut should select previous word if current char is newline
 * diagnostic messages can stack up if deselected and not resolved
index f0569c08284da0cc826555a94907a44f4686262e..71f4767eba9f30b4a5416f3d6ee93c70bd34b71c 100644 (file)
@@ -308,6 +308,9 @@ search operation to be applied in the opposite direction of the previous.
     the current file. Otherwise, a new instance of `xedit` will be launched with
     the target file and the cursor set to the line containing the definition.
 
+* `Ctrl+Shift+g`:
+    Jump to the previous cursor location.
+
 * `Ctrl+n`:
     Open a new instance of `xedit` with no filename.
 
index 9e17422edc9d4368952fbfc4bb4e9db97773768f..8aabb01c0d7faba88ea534f09231c1f8f2623b70 100644 (file)
@@ -135,6 +135,7 @@ typedef struct {
     Row** rows;       /* array of row data structures */
     Buf buffer;       /* the buffer used to populate the view */
     Sel selection;    /* range of currently selected text */
+    size_t prev_csr;  /* previous cursor location */
 } View;
 
 enum {
@@ -181,6 +182,7 @@ void view_selextend(View* view, size_t row, size_t col);
 void view_selword(View* view, size_t row, size_t col);
 void view_select(View* view, size_t row, size_t col);
 void view_jumpto(View* view, bool extsel, size_t off);
+void view_jumpback(View* view);
 void view_scrollto(View* view, size_t csr);
 Rune view_getrune(View* view);
 
index 50bdd2cf4657461087be4b34e74df41de02edb4f..34c2a62c8896a27da0165e2a88b7b7bd82571874 100644 (file)
@@ -414,13 +414,20 @@ void view_delete(View* view, int dir, bool byword) {
 }
 
 void view_jumpto(View* view, bool extsel, size_t off) {
-    view->selection.end = off;
+    Buf* buf = &(view->buffer);
+    view->prev_csr = view->selection.end;
+    view->selection.end = (off > buf_end(buf) ? buf_end(buf) : off);
     if (!extsel)
         view->selection.beg = view->selection.end;
     view->selection.col = buf_getcol(&(view->buffer), view->selection.end);
     view->sync_needed = true;
 }
 
+void view_jumpback(View* view) {
+    view_jumpto(view, false, view->prev_csr);
+    view->sync_center = true;
+}
+
 void view_bol(View* view, bool extsel) {
     /* determine whether we are jumping to start of content or line */
     Buf* buf = &(view->buffer);
diff --git a/xedit.c b/xedit.c
index 3cf472ae30c0e06eefc35cb2f0cc09d0d178b7aa..28225e4e6c491206563c0197910e177e9d8abfac 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -324,9 +324,13 @@ static void jump_to(char* arg) {
 }
 
 static void goto_ctag(void) {
-    char* str = view_getctx(win_view(FOCUSED));
-    jump_to(str);
-    free(str);
+    if (x11_keymodsset(ModShift)) {
+        view_jumpback(win_view(FOCUSED));
+    } else {
+        char* str = view_getctx(win_view(FOCUSED));
+        jump_to(str);
+        free(str);
+    }
 }
 
 static void tabs(void) {
@@ -449,6 +453,7 @@ static KeyBinding Bindings[] = {
     { ModCtrl,                 'o',        open_file    },
     { ModCtrl,                 'p',        pick_ctag    },
     { ModCtrl,                 'g',        goto_ctag    },
+    { ModCtrl|ModShift,        'g',        goto_ctag    },
     { ModCtrl,                 'n',        new_win      },
     { ModCtrl,                 '\n',       newline      },
     { ModCtrl|ModShift,        '\n',       newline      },