version 1.318, 2021/03/02 10:56:45 |
version 1.319, 2021/03/09 08:24:09 |
|
|
window_copy_cursor_start_of_line(wme); |
window_copy_cursor_start_of_line(wme); |
data->selrx = data->cx; |
data->selrx = data->cx; |
data->selry = screen_hsize(data->backing) + data->cy - data->oy; |
data->selry = screen_hsize(data->backing) + data->cy - data->oy; |
data->endselrx = window_copy_find_length(wme, data->selry); |
|
data->endselry = data->selry; |
data->endselry = data->selry; |
window_copy_start_selection(wme); |
window_copy_start_selection(wme); |
for (; np > 1; np--) |
|
window_copy_cursor_down(wme, 0); |
|
window_copy_cursor_end_of_line(wme); |
window_copy_cursor_end_of_line(wme); |
|
data->endselry = screen_hsize(data->backing) + data->cy - data->oy; |
|
data->endselrx = window_copy_find_length(wme, data->endselry); |
|
for (; np > 1; np--) { |
|
window_copy_cursor_down(wme, 0); |
|
window_copy_cursor_end_of_line(wme); |
|
} |
|
|
return (WINDOW_COPY_CMD_REDRAW); |
return (WINDOW_COPY_CMD_REDRAW); |
} |
} |
|
|
struct window_mode_entry *wme = cs->wme; |
struct window_mode_entry *wme = cs->wme; |
struct session *s = cs->s; |
struct session *s = cs->s; |
struct window_copy_mode_data *data = wme->data; |
struct window_copy_mode_data *data = wme->data; |
u_int px, py; |
u_int px, py, nextx, nexty; |
|
|
data->lineflag = LINE_SEL_LEFT_RIGHT; |
data->lineflag = LINE_SEL_LEFT_RIGHT; |
data->rectflag = 0; |
data->rectflag = 0; |
|
|
data->selry = py; |
data->selry = py; |
window_copy_start_selection(wme); |
window_copy_start_selection(wme); |
|
|
|
/* Handle single character words. */ |
|
nextx = px + 1; |
|
nexty = py; |
|
if (grid_get_line(data->backing->grid, nexty)->flags & |
|
GRID_LINE_WRAPPED && nextx > screen_size_x(data->backing) - 1) { |
|
nextx = 0; |
|
nexty++; |
|
} |
if (px >= window_copy_find_length(wme, py) || |
if (px >= window_copy_find_length(wme, py) || |
!window_copy_in_set(wme, px + 1, py, data->ws)) |
!window_copy_in_set(wme, nextx, nexty, data->ws)) |
window_copy_cursor_next_word_end(wme, data->ws, 1); |
window_copy_cursor_next_word_end(wme, data->ws, 1); |
else { |
else { |
window_copy_update_cursor(wme, px, data->cy); |
window_copy_update_cursor(wme, px, data->cy); |
|
|
} |
} |
data->endselrx = data->cx; |
data->endselrx = data->cx; |
data->endselry = screen_hsize(data->backing) + data->cy - data->oy; |
data->endselry = screen_hsize(data->backing) + data->cy - data->oy; |
if (data->dx > data->endselrx) |
if (data->dy > data->endselry) { |
|
data->dy = data->endselry; |
data->dx = data->endselrx; |
data->dx = data->endselrx; |
|
} else if (data->dx > data->endselrx) |
|
data->dx = data->endselrx; |
|
|
return (WINDOW_COPY_CMD_REDRAW); |
return (WINDOW_COPY_CMD_REDRAW); |
} |
} |
|
|
data->endsely = data->endselry; |
data->endsely = data->endselry; |
} else { |
} else { |
/* Left to right selection. */ |
/* Left to right selection. */ |
|
if (yy < data->endselry) |
|
yy = data->endselry; |
xx = window_copy_find_length(wme, yy); |
xx = window_copy_find_length(wme, yy); |
|
|
/* Reset the start. */ |
/* Reset the start. */ |
|
|
*len = 0; |
*len = 0; |
return (NULL); |
return (NULL); |
} |
} |
if (keys == MODEKEY_EMACS || lastex <= ey_last) |
/* Remove final \n (unless at end in vi mode). */ |
off -= 1; /* remove final \n (unless at end in vi mode) */ |
if (keys == MODEKEY_EMACS || lastex <= ey_last) { |
|
if (~grid_get_line(data->backing->grid, ey)->flags & |
|
GRID_LINE_WRAPPED || lastex != ey_last) |
|
off -= 1; |
|
} |
*len = off; |
*len = off; |
return (buf); |
return (buf); |
} |
} |
|
|
data->oy, oldy, px, py, 0); |
data->oy, oldy, px, py, 0); |
} |
} |
|
|
|
/* Compute the next place where a word ends. */ |
static void |
static void |
window_copy_cursor_next_word_end_pos(struct window_mode_entry *wme, |
window_copy_cursor_next_word_end_pos(struct window_mode_entry *wme, |
const char *separators, u_int *ppx, u_int *ppy) |
const char *separators, u_int *ppx, u_int *ppy) |
|
|
struct window_copy_mode_data *data = wme->data; |
struct window_copy_mode_data *data = wme->data; |
struct options *oo = wp->window->options; |
struct options *oo = wp->window->options; |
struct screen *back_s = data->backing; |
struct screen *back_s = data->backing; |
u_int px, py, xx, yy; |
struct grid_reader gr; |
int keys, expected = 1; |
u_int px, py, hsize; |
|
int keys; |
|
|
px = data->cx; |
px = data->cx; |
py = screen_hsize(back_s) + data->cy - data->oy; |
hsize = screen_hsize(back_s); |
xx = window_copy_find_length(wme, py); |
py = hsize + data->cy - data->oy; |
yy = screen_hsize(back_s) + screen_size_y(back_s) - 1; |
|
|
|
|
grid_reader_start(&gr, back_s->grid, px, py); |
keys = options_get_number(oo, "mode-keys"); |
keys = options_get_number(oo, "mode-keys"); |
if (keys == MODEKEY_VI && !window_copy_in_set(wme, px, py, separators)) |
if (keys == MODEKEY_VI && !grid_reader_in_set(&gr, separators)) |
px++; |
grid_reader_cursor_right(&gr, 0, 0); |
|
grid_reader_cursor_next_word_end(&gr, separators); |
/* |
if (keys == MODEKEY_VI) |
* First skip past any word characters, then any non-word characters. |
grid_reader_cursor_left(&gr); |
* |
grid_reader_get_cursor(&gr, &px, &py); |
* expected is initially set to 1 for the former and then 0 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; |
|
py++; |
|
px = 0; |
|
xx = window_copy_find_length(wme, py); |
|
} else |
|
px++; |
|
} |
|
expected = !expected; |
|
} while (expected == 0); |
|
|
|
if (keys == MODEKEY_VI && px != 0) |
|
px--; |
|
|
|
*ppx = px; |
*ppx = px; |
*ppy = py; |
*ppy = py; |
} |
} |
|
|
|
/* Move to the next place where a word ends. */ |
static void |
static void |
window_copy_cursor_next_word_end(struct window_mode_entry *wme, |
window_copy_cursor_next_word_end(struct window_mode_entry *wme, |
const char *separators, int no_reset) |
const char *separators, int no_reset) |
|
|
const char *separators, int already, u_int *ppx, u_int *ppy) |
const char *separators, int already, u_int *ppx, u_int *ppy) |
{ |
{ |
struct window_copy_mode_data *data = wme->data; |
struct window_copy_mode_data *data = wme->data; |
|
struct screen *back_s = data->backing; |
|
struct grid_reader gr; |
u_int px, py, hsize; |
u_int px, py, hsize; |
|
|
hsize = screen_hsize(data->backing); |
|
px = data->cx; |
px = data->cx; |
|
hsize = screen_hsize(back_s); |
py = hsize + data->cy - data->oy; |
py = hsize + data->cy - data->oy; |
|
|
/* Move back to the previous word character. */ |
grid_reader_start(&gr, back_s->grid, px, py); |
if (already || window_copy_in_set(wme, px, py, separators)) { |
grid_reader_cursor_previous_word(&gr, separators, already); |
for (;;) { |
grid_reader_get_cursor(&gr, &px, &py); |
if (px > 0) { |
|
px--; |
|
if (!window_copy_in_set(wme, px, py, |
|
separators)) |
|
break; |
|
} else { |
|
if (py == 0 || |
|
(data->cy == 0 && |
|
(hsize == 0 || data->oy > hsize - 1))) |
|
goto out; |
|
|
|
py--; |
|
px = window_copy_find_length(wme, py); |
|
|
|
/* Stop if separator at EOL. */ |
|
if (px > 0 && window_copy_in_set(wme, px - 1, |
|
py, separators)) |
|
break; |
|
} |
|
} |
|
} |
|
|
|
/* Move back to the beginning of this word. */ |
|
while (px > 0 && !window_copy_in_set(wme, px - 1, py, separators)) |
|
px--; |
|
|
|
out: |
|
*ppx = px; |
*ppx = px; |
*ppy = py; |
*ppy = py; |
} |
} |