From 94d3d4c935bbbb04e871f0be67bda3ff0b60ae77 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 30 May 2017 21:36:42 -0400 Subject: [PATCH] tweaked logic for setting implicit marks. local cursor movements no longer set the implicit mark --- TODO.md | 1 + docs/tide.1 | 2 +- docs/tide.1.md | 5 ++++- docs/xfilepick.1 | 2 +- docs/xtagpick.1 | 2 +- lib/view.c | 39 +++++++++++++++++++++------------------ 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/TODO.md b/TODO.md index 3edd2ff..0cd149b 100644 --- a/TODO.md +++ b/TODO.md @@ -6,6 +6,7 @@ Up Next: var infoId = 'readerinfo'+reader.id; * Add a way to CD using a builtin (buffers will track original dir) * shortcut to jump to previous edit +* xrandr dpi setting does not affect tide like it should The Future: diff --git a/docs/tide.1 b/docs/tide.1 index 2f739ff..52abdcc 100644 --- a/docs/tide.1 +++ b/docs/tide.1 @@ -286,7 +286,7 @@ Lookup the selected symbol or symbol under the cursor in a ctags(1) generated in . .TP \fBCtrl+Shift+g\fR -Jump to the previous cursor location\. +Jump to the last implicitly marked location\. In general, actions that move the cursor potentially greate distances will set an implicit mark before performing the move\. These actions include, jumping to a ctag definition, jumping to a line, or clicking with the mouse\. . .TP \fBCtrl+n\fR diff --git a/docs/tide.1.md b/docs/tide.1.md index 9d178e5..6e33033 100644 --- a/docs/tide.1.md +++ b/docs/tide.1.md @@ -323,7 +323,10 @@ search operation to be applied in the opposite direction of the previous. the target file and the cursor set to the line containing the definition. * `Ctrl+Shift+g`: - Jump to the previous cursor location. + Jump to the last implicitly marked location. In general, actions that move + the cursor potentially greate distances will set an implicit mark before + performing the move. These actions include, jumping to a ctag definition, + jumping to a line, or clicking with the mouse. * `Ctrl+n`: Open a new instance of `tide` with no filename. diff --git a/docs/xfilepick.1 b/docs/xfilepick.1 index b7f22f5..39cf645 100644 --- a/docs/xfilepick.1 +++ b/docs/xfilepick.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "XFILEPICK" "1" "March 2017" "" "" +.TH "XFILEPICK" "1" "May 2017" "" "" . .SH "NAME" \fBxfilepick\fR \- fuzzy find a file from the current directory tree diff --git a/docs/xtagpick.1 b/docs/xtagpick.1 index 4aa214c..5377e2d 100644 --- a/docs/xtagpick.1 +++ b/docs/xtagpick.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "XTAGPICK" "1" "March 2017" "" "" +.TH "XTAGPICK" "1" "May 2017" "" "" . .SH "NAME" \fBxtagpick\fR \- Parses a ctags file and sends results to xpick diff --git a/lib/view.c b/lib/view.c index e682c12..727aace 100644 --- a/lib/view.c +++ b/lib/view.c @@ -298,11 +298,8 @@ void view_byline(View* view, int move, bool extsel) { void view_setcursor(View* view, size_t row, size_t col) { size_t off = getoffset(view, row, col); - if (off != SIZE_MAX) { - view->selection.beg = view->selection.end = off; - view->selection.col = buf_getcol(&(view->buffer), view->selection.end); - view->sync_needed = true; - } + if (off != SIZE_MAX) + view_jumpto(view, false, off); } void view_selext(View* view, size_t row, size_t col) { @@ -395,6 +392,15 @@ bool view_findstr(View* view, int dir, char* str) { return found; } +static void move_to(View* view, bool extsel, size_t off) { + Buf* buf = &(view->buffer); + 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_insert(View* view, bool indent, Rune rune) { /* ignore non-printable control characters */ if (!isspace(rune) && rune < 0x20) @@ -406,7 +412,7 @@ void view_insert(View* view, bool indent, Rune rune) { view->selection = sel; } unsigned newpos = buf_insert(&(view->buffer), indent, view->selection.end, rune); - view_jumpto(view, false, newpos); + move_to(view, false, newpos); } void view_delete(View* view, int dir, bool byword) { @@ -415,17 +421,12 @@ void view_delete(View* view, int dir, bool byword) { (byword ? view_byword : view_byrune)(view, dir, true); selswap(sel); unsigned newpos = buf_delete(&(view->buffer), sel->beg, sel->end); - view_jumpto(view, false, newpos); + move_to(view, false, newpos); } void view_jumpto(View* view, bool extsel, size_t 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; + move_to(view, extsel, off); } void view_jumpback(View* view) { @@ -441,11 +442,11 @@ void view_bol(View* view, bool extsel) { for (; ' ' == buf_get(buf, boi) || '\t' == buf_get(buf, boi); boi++); unsigned pos = view->selection.end; pos = (pos == bol || pos > boi ? boi : bol); - view_jumpto(view, extsel, pos); + move_to(view, extsel, pos); } void view_eol(View* view, bool extsel) { - view_jumpto(view, extsel, buf_eol(&(view->buffer), view->selection.end)); + move_to(view, extsel, buf_eol(&(view->buffer), view->selection.end)); } void view_bof(View* view, bool extsel) { @@ -572,11 +573,13 @@ void view_csrsummon(View* view) { size_t col = SIZE_MAX, row = SIZE_MAX; find_cursor(view, &col, &row); size_t off = view->rows[view->nrows/2]->off; - if (row != SIZE_MAX && col != SIZE_MAX) - if (col >= view->rows[view->nrows/2]->rlen) + if (row != SIZE_MAX && col != SIZE_MAX) { + if (col >= view->rows[view->nrows/2]->rlen) { off = view->rows[view->nrows/2]->off + view->rows[view->nrows/2]->rlen - 1; - else + } else { off += col; + } + } view_jumpto(view, false, off); view->sync_needed = false; } -- 2.52.0