aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/terminal.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-02-27 03:10:55 +0100
committerJustin M. Keyes <justinkz@gmail.com>2017-03-01 14:47:49 +0100
commit937e54f86599ab448e6497955e2b4dddf6347e88 (patch)
treee3ba431fb1480d4dde8362604139a36fb0d576bb /src/nvim/terminal.c
parent504693ce66e61e2976b0af2930177a07bafbe6f3 (diff)
downloadrneovim-937e54f86599ab448e6497955e2b4dddf6347e88.tar.gz
rneovim-937e54f86599ab448e6497955e2b4dddf6347e88.tar.bz2
rneovim-937e54f86599ab448e6497955e2b4dddf6347e88.zip
terminal: Keep cursor position.
Let the terminal dictate the normal-mode cursor position. This will be disorienting sometimes, but it is closer to what users expect vs always going to the last line.
Diffstat (limited to 'src/nvim/terminal.c')
-rw-r--r--src/nvim/terminal.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index e23c2e5748..b37aff6aea 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -1126,18 +1126,17 @@ static void redraw(bool restore_cursor)
update_screen(0);
}
- if (term && is_focused(term)) {
- curwin->w_wrow = term->cursor.row;
- curwin->w_wcol = term->cursor.col + win_col_off(curwin);
- setcursor();
- } else if (restore_cursor) {
+ if (restore_cursor) {
ui_cursor_goto(save_row, save_col);
} else if (term) {
- // exiting terminal focus, put the window cursor in a valid position
- int height, width;
- vterm_get_size(term->vt, &height, &width);
- curwin->w_wrow = height - 1;
- curwin->w_wcol = 0;
+ curwin->w_wrow = term->cursor.row;
+ curwin->w_wcol = term->cursor.col + win_col_off(curwin);
+ curwin->w_cursor.lnum = MIN(curbuf->b_ml.ml_line_count,
+ row_to_linenr(term, term->cursor.row));
+ // Nudge cursor when returning to normal-mode.
+ int off = is_focused(term) ? 0 : (curwin->w_p_rl ? 1 : -1);
+ curwin->w_cursor.col = MAX(0, term->cursor.col + win_col_off(curwin) + off);
+ curwin->w_cursor.coladd = 0;
setcursor();
}
@@ -1153,6 +1152,7 @@ static void adjust_topline(Terminal *term, buf_T *buf, long added)
if (wp->w_buffer == buf) {
linenr_T ml_end = buf->b_ml.ml_line_count;
bool following = ml_end == wp->w_cursor.lnum + added; // cursor at end?
+
if (following || (wp == curwin && is_focused(term))) {
// "Follow" the terminal output
wp->w_cursor.lnum = ml_end;