-/* $OpenBSD: window-copy.c,v 1.311 2021/01/18 11:14:24 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.312 2021/01/22 10:21:24 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
struct window_copy_mode_data *data = wme->data;
struct screen *back_s = data->backing;
struct grid_reader gr;
- u_int px, py, cy, yy, ny, hsize;
+ u_int px, py, cy, oldy, yy, ny, nd, hsize;
px = data->cx;
hsize = screen_hsize(back_s);
py = hsize + data->cy - data->oy;
+ oldy = data->cy;
grid_reader_start(&gr, back_s->grid, px, py);
grid_reader_cursor_start_of_line(&gr, 1);
if (py < yy) {
ny = yy - py;
cy = 0;
+ nd = 1;
} else {
ny = 0;
cy = py - yy;
+ nd = oldy - cy + 1;
}
while (ny > 0) {
window_copy_cursor_up(wme, 1);
}
window_copy_update_cursor(wme, px, cy);
if (window_copy_update_selection(wme, 1, 0))
- window_copy_redraw_lines(wme, data->cy, 1);
+ window_copy_redraw_lines(wme, data->cy, nd);
}
static void
struct window_copy_mode_data *data = wme->data;
struct screen *back_s = data->backing;
struct grid_reader gr;
- u_int px, py, cy, yy, ny, hsize;
+ u_int px, py, cy, oldy, yy, ny, nd, hsize;
px = data->cx;
hsize = screen_hsize(back_s);
py = hsize + data->cy - data->oy;
+ oldy = data->cy;
grid_reader_start(&gr, back_s->grid, px, py);
if (data->screen.sel != NULL && data->rectflag)
/* Scroll down if we went off the visible screen. */
cy = py - hsize + data->oy;
yy = screen_size_y(back_s) - 1;
- if (cy > yy)
+ if (cy > yy) {
ny = cy - yy;
- else
+ oldy = yy;
+ nd = 1;
+ } else {
ny = 0;
+ nd = cy - oldy + 1;
+ }
while (ny > 0) {
window_copy_cursor_down(wme, 1);
ny--;
else
window_copy_update_cursor(wme, px, cy);
if (window_copy_update_selection(wme, 1, 0))
- window_copy_redraw_lines(wme, data->cy, 1);
+ window_copy_redraw_lines(wme, oldy, nd);
}
static void
{
struct window_copy_mode_data *data = wme->data;
struct screen *back_s = data->backing;
- u_int px, py, xx, yy;
- int expected = 0;
+ struct grid_reader gr;
+ u_int px, py, cy, oldy, yy, ny, nd, hsize;
px = data->cx;
- py = screen_hsize(back_s) + data->cy - data->oy;
- xx = window_copy_find_length(wme, py);
- yy = screen_hsize(back_s) + screen_size_y(back_s) - 1;
-
- /*
- * First skip past any nonword characters and then any word characters.
- *
- * expected is initially set to 0 for the former and then 1 for the
- * latter.
- */
- do {
- while (px > xx ||
- window_copy_in_set(wme, px, py, separators) == expected) {
- /* Move down if we're past the end of the line. */
- if (px > xx) {
- if (py == yy)
- return;
- window_copy_cursor_down(wme, 0);
- px = 0;
+ hsize = screen_hsize(back_s);
+ py = hsize + data->cy - data->oy;
+ oldy = data->cy;
- py = screen_hsize(back_s) + data->cy - data->oy;
- xx = window_copy_find_length(wme, py);
- } else
- px++;
- }
- expected = !expected;
- } while (expected == 1);
+ grid_reader_start(&gr, back_s->grid, px, py);
+ grid_reader_cursor_next_word(&gr, separators);
+ grid_reader_get_cursor(&gr, &px, &py);
- window_copy_update_cursor(wme, px, data->cy);
+ /* Scroll down if we went off the visible screen. */
+ cy = py - hsize + data->oy;
+ yy = screen_size_y(back_s) - 1;
+ if (cy > yy) {
+ ny = cy - yy;
+ oldy = yy;
+ nd = 1;
+ } else {
+ ny = 0;
+ nd = cy - oldy + 1;
+ }
+ while (ny > 0) {
+ window_copy_cursor_down(wme, 1);
+ ny--;
+ }
+ if (cy > yy)
+ window_copy_update_cursor(wme, px, yy);
+ else
+ window_copy_update_cursor(wme, px, cy);
if (window_copy_update_selection(wme, 1, 0))
- window_copy_redraw_lines(wme, data->cy, 1);
+ window_copy_redraw_lines(wme, oldy, nd);
}
static void
struct options *oo = wp->window->options;
struct screen *back_s = data->backing;
struct grid_reader gr;
- u_int px, py, cy, yy, ny, hsize;
+ u_int px, py, cy, oldy, yy, ny, nd, hsize;
int keys;
px = data->cx;
hsize = screen_hsize(back_s);
py = hsize + data->cy - data->oy;
+ oldy = data->cy;
grid_reader_start(&gr, back_s->grid, px, py);
keys = options_get_number(oo, "mode-keys");
/* Scroll down if we went off the visible screen. */
cy = py - hsize + data->oy;
yy = screen_size_y(back_s) - 1;
- if (cy > yy)
+ if (cy > yy) {
ny = cy - yy;
- else
+ oldy = yy;
+ nd = 1;
+ } else {
ny = 0;
+ nd = cy - oldy + 1;
+ }
while (ny > 0) {
window_copy_cursor_down(wme, 1);
ny--;
else
window_copy_update_cursor(wme, px, cy);
if (window_copy_update_selection(wme, 1, no_reset))
- window_copy_redraw_lines(wme, data->cy, 1);
+ window_copy_redraw_lines(wme, oldy, nd);
}
/* Compute the previous place where a word begins. */
struct window_copy_mode_data *data = wme->data;
struct screen *back_s = data->backing;
struct grid_reader gr;
- u_int px, py, cy, yy, ny, hsize;
+ u_int px, py, cy, oldy, yy, ny, nd, hsize;
px = data->cx;
hsize = screen_hsize(back_s);
py = hsize + data->cy - data->oy;
+ oldy = data->cy;
grid_reader_start(&gr, back_s->grid, px, py);
grid_reader_cursor_previous_word(&gr, separators, already);
if (py < yy) {
ny = yy - py;
cy = 0;
+ nd = 1;
} else {
ny = 0;
cy = py - yy;
+ nd = oldy - cy + 1;
}
while (ny > 0) {
window_copy_cursor_up(wme, 1);
}
window_copy_update_cursor(wme, px, cy);
if (window_copy_update_selection(wme, 1, 0))
- window_copy_redraw_lines(wme, data->cy, 1);
+ window_copy_redraw_lines(wme, data->cy, nd);
}
static void