summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2009-08-21 07:33:58 +0000
committernicm <nicm@openbsd.org>2009-08-21 07:33:58 +0000
commit364f9de4db4a26f47f187da9d7bc2dc411d84ff9 (patch)
treea3ead9e60aa69d563f5308df582cf58ff4785d05
parentFix grid_expand_line so it actually works when the required size is bigger than (diff)
downloadwireguard-openbsd-364f9de4db4a26f47f187da9d7bc2dc411d84ff9.tar.xz
wireguard-openbsd-364f9de4db4a26f47f187da9d7bc2dc411d84ff9.zip
When moving up or down in copy mode, save the cursor position and size of the
last line with content (width != 0) and use it to determine if the cursor should be at the end of the line. Fixes problem of the cursor always jumping to the end of the line when scrolling past a blank line.
-rw-r--r--usr.bin/tmux/window-copy.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index d9ec0af6a70..241731fa890 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.24 2009/08/19 14:46:56 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.25 2009/08/21 07:33:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -97,6 +97,9 @@ struct window_copy_mode_data {
u_int cx;
u_int cy;
+ u_int lastcx; /* position in last line with content */
+ u_int lastsx; /* size of last line with content */
+
enum window_copy_input_type inputtype;
const char *inputprompt;
char *inputstr;
@@ -119,6 +122,9 @@ window_copy_init(struct window_pane *wp)
data->cx = wp->base.cx;
data->cy = wp->base.cy;
+ data->lastcx = 0;
+ data->lastsx = 0;
+
data->inputtype = WINDOW_COPY_OFF;
data->inputprompt = NULL;
data->inputstr = xstrdup("");
@@ -1045,7 +1051,12 @@ window_copy_cursor_up(struct window_pane *wp)
oy = screen_hsize(&wp->base) + data->cy - data->oy;
ox = window_copy_find_length(wp, oy);
+ if (ox != 0) {
+ data->lastcx = data->cx;
+ data->lastsx = ox;
+ }
+ data->cx = data->lastcx;
if (data->cy == 0)
window_copy_scroll_down(wp, 1);
else {
@@ -1056,8 +1067,7 @@ window_copy_cursor_up(struct window_pane *wp)
py = screen_hsize(&wp->base) + data->cy - data->oy;
px = window_copy_find_length(wp, py);
-
- if (data->cx >= px || data->cx >= ox)
+ if (data->cx >= data->lastsx || data->cx > px)
window_copy_cursor_end_of_line(wp);
}
@@ -1070,7 +1080,12 @@ window_copy_cursor_down(struct window_pane *wp)
oy = screen_hsize(&wp->base) + data->cy - data->oy;
ox = window_copy_find_length(wp, oy);
+ if (ox != 0) {
+ data->lastcx = data->cx;
+ data->lastsx = ox;
+ }
+ data->cx = data->lastcx;
if (data->cy == screen_size_y(s) - 1)
window_copy_scroll_up(wp, 1);
else {
@@ -1081,8 +1096,7 @@ window_copy_cursor_down(struct window_pane *wp)
py = screen_hsize(&wp->base) + data->cy - data->oy;
px = window_copy_find_length(wp, py);
-
- if (data->cx >= px || data->cx >= ox)
+ if (data->cx >= data->lastsx || data->cx > px)
window_copy_cursor_end_of_line(wp);
}