Tweak copy behaviour slightly in vi mode to be closer to real vi. From

Tiago Resende.
This commit is contained in:
Nicholas Marriott 2011-04-24 21:06:12 +00:00
parent 8738141913
commit dc8fb9fb23

View File

@ -1225,6 +1225,7 @@ window_copy_copy_selection(struct window_pane *wp)
size_t off; size_t off;
u_int i, xx, yy, sx, sy, ex, ey, limit; u_int i, xx, yy, sx, sy, ex, ey, limit;
u_int firstsx, lastex, restex, restsx; u_int firstsx, lastex, restex, restsx;
int keys;
if (!s->sel.flag) if (!s->sel.flag)
return; return;
@ -1261,6 +1262,14 @@ window_copy_copy_selection(struct window_pane *wp)
* end (restex) of all other lines. * end (restex) of all other lines.
*/ */
xx = screen_size_x(s); xx = screen_size_x(s);
/*
* Behave according to mode-keys. If it is emacs, copy like emacs,
* keeping the top-left-most character, and dropping the
* bottom-right-most, regardless of copy direction. If it is vi, also
* keep bottom-right-most character.
*/
keys = options_get_number(&wp->window->options, "mode-keys");
if (data->rectflag) { if (data->rectflag) {
/* /*
* Need to ignore the column with the cursor in it, which for * Need to ignore the column with the cursor in it, which for
@ -1268,8 +1277,14 @@ window_copy_copy_selection(struct window_pane *wp)
*/ */
if (data->selx < data->cx) { if (data->selx < data->cx) {
/* Selection start is on the left. */ /* Selection start is on the left. */
lastex = data->cx; if (keys == MODEKEY_EMACS) {
restex = data->cx; lastex = data->cx;
restex = data->cx;
}
else {
lastex = data->cx + 1;
restex = data->cx + 1;
}
firstsx = data->selx; firstsx = data->selx;
restsx = data->selx; restsx = data->selx;
} else { } else {
@ -1280,11 +1295,10 @@ window_copy_copy_selection(struct window_pane *wp)
restsx = data->cx; restsx = data->cx;
} }
} else { } else {
/* if (keys == MODEKEY_EMACS)
* Like emacs, keep the top-left-most character, and drop the lastex = ex;
* bottom-right-most, regardless of copy direction. else
*/ lastex = ex + 1;
lastex = ex;
restex = xx; restex = xx;
firstsx = sx; firstsx = sx;
restsx = 0; restsx = 0;