vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit d1fac9be1894715cead78c301d26109a3cc92e5c
parent 650161d7405bdc989b85e2aea46b8e8f0c452844
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat, 13 Sep 2014 22:05:13 +0200

Make window_selection_get to return the correct range

This makes the operator operate on the correct file range if executed
from visual mode.

The problem is that if the cursor is visible the selection seems larger
than it actually is. The cell under the cursor is actually not part
of the selection eventhough it is visually indistinguishable from it.

The somewhat hacky way around this is to hide the cursor once selection
is active and show it again once the selection is cleared.

This will probably cause a headache if the cursor needs to be visible
while a selection is active like for example in the command prompt.

Diffstat:
Mwindow.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/window.c b/window.c @@ -87,6 +87,7 @@ void window_selection_clear(Win *win) { win->sel.start = win->sel.end = (size_t)-1; window_draw(win); window_cursor_update(win); + curs_set(1); } /* reset internal window data structures (cell matrix, line offsets etc.) */ @@ -121,6 +122,7 @@ Filerange window_selection_get(Win *win) { sel.start = sel.end; sel.end = tmp; } + sel.end = text_char_next(win->text, sel.end); return sel; } @@ -730,7 +732,9 @@ void window_scroll_to(Win *win, size_t pos) { } void window_selection_start(Win *win) { - win->sel.start = window_cursor_get(win); + win->sel.start = win->sel.end = window_cursor_get(win); + window_draw(win); + curs_set(0); } void window_selection_end(Win *win) {