From 3301acf572dc672ccd002d93dbb3d95ea01d1baa Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 25 May 2017 22:08:01 -0400 Subject: [PATCH] add shortcut to jump back to previous cursor location --- TODO.md | 2 -- docs/xedit.1.md | 3 +++ inc/edit.h | 2 ++ lib/view.c | 9 ++++++++- xedit.c | 11 ++++++++--- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index ece4464..ded4f4f 100644 --- 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 diff --git a/docs/xedit.1.md b/docs/xedit.1.md index f0569c0..71f4767 100644 --- a/docs/xedit.1.md +++ b/docs/xedit.1.md @@ -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. diff --git a/inc/edit.h b/inc/edit.h index 9e17422..8aabb01 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -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); diff --git a/lib/view.c b/lib/view.c index 50bdd2c..34c2a62 100644 --- a/lib/view.c +++ b/lib/view.c @@ -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 3cf472a..28225e4 100644 --- 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 }, -- 2.52.0