Merge branch 'obsd-master' into master

This commit is contained in:
Thomas Adam 2021-03-09 10:01:19 +00:00
commit ff77658f27
2 changed files with 53 additions and 77 deletions

View File

@ -172,7 +172,7 @@ grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
/* Do not break up wrapped words. */ /* Do not break up wrapped words. */
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED) if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
xx = grid_reader_line_length(gr) - 1; xx = gr->gd->sx - 1;
else else
xx = grid_reader_line_length(gr); xx = grid_reader_line_length(gr);
yy = gr->gd->hsize + gr->gd->sy - 1; yy = gr->gd->hsize + gr->gd->sy - 1;
@ -197,7 +197,7 @@ grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
if (grid_get_line(gr->gd, gr->cy)->flags & if (grid_get_line(gr->gd, gr->cy)->flags &
GRID_LINE_WRAPPED) GRID_LINE_WRAPPED)
xx = grid_reader_line_length(gr) - 1; xx = gr->gd->sx - 1;
else else
xx = grid_reader_line_length(gr); xx = grid_reader_line_length(gr);
} else } else
@ -216,7 +216,7 @@ grid_reader_cursor_next_word_end(struct grid_reader *gr, const char *separators)
/* Do not break up wrapped words. */ /* Do not break up wrapped words. */
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED) if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
xx = grid_reader_line_length(gr) - 1; xx = gr->gd->sx - 1;
else else
xx = grid_reader_line_length(gr); xx = grid_reader_line_length(gr);
yy = gr->gd->hsize + gr->gd->sy - 1; yy = gr->gd->hsize + gr->gd->sy - 1;
@ -241,7 +241,7 @@ grid_reader_cursor_next_word_end(struct grid_reader *gr, const char *separators)
if (grid_get_line(gr->gd, gr->cy)->flags & if (grid_get_line(gr->gd, gr->cy)->flags &
GRID_LINE_WRAPPED) GRID_LINE_WRAPPED)
xx = grid_reader_line_length(gr) - 1; xx = gr->gd->sx - 1;
else else
xx = grid_reader_line_length(gr); xx = grid_reader_line_length(gr);
} else } else
@ -294,7 +294,7 @@ grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
GRID_LINE_WRAPPED) GRID_LINE_WRAPPED)
break; break;
grid_reader_cursor_up(gr); grid_reader_cursor_up(gr);
grid_reader_cursor_end_of_line(gr, 0, 0); grid_reader_cursor_end_of_line(gr, 0, 1);
} }
if (gr->cx > 0) if (gr->cx > 0)
gr->cx--; gr->cx--;

View File

@ -1759,12 +1759,15 @@ window_copy_cmd_select_line(struct window_copy_cmd_state *cs)
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);
} }
@ -1775,7 +1778,7 @@ window_copy_cmd_select_word(struct window_copy_cmd_state *cs)
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;
@ -1791,8 +1794,16 @@ window_copy_cmd_select_word(struct window_copy_cmd_state *cs)
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);
@ -1801,7 +1812,10 @@ window_copy_cmd_select_word(struct window_copy_cmd_state *cs)
} }
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;
} else if (data->dx > data->endselrx)
data->dx = data->endselrx; data->dx = data->endselrx;
return (WINDOW_COPY_CMD_REDRAW); return (WINDOW_COPY_CMD_REDRAW);
@ -3635,6 +3649,8 @@ window_copy_synchronize_cursor_end(struct window_mode_entry *wme, int begin,
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. */
@ -3929,8 +3945,12 @@ window_copy_get_selection(struct window_mode_entry *wme, size_t *len)
*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);
} }
@ -4531,6 +4551,7 @@ window_copy_cursor_next_word(struct window_mode_entry *wme,
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)
@ -4539,47 +4560,27 @@ window_copy_cursor_next_word_end_pos(struct window_mode_entry *wme,
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)
@ -4615,42 +4616,17 @@ window_copy_cursor_previous_word_pos(struct window_mode_entry *wme,
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;
} }