mirror of
https://github.com/neovim/neovim.git
synced 2025-10-01 23:48:32 +00:00
fix(terminal): avoid tailed cursor in focused terminal in events
Problem: in terminal mode, adjust_topline moves curwin's cursor to the last row so set_topline tails the non-scrollback area. This may result in the observed cursor position remaining tailed in events within the focused terminal, rather than reflecting the actual cursor position. Solution: use the focused terminal's actual cursor position immediately, rather than relying on the next terminal_check_cursor call in terminal_check to set it. Note: Maybe also possible for terminal mode cursor position to be stale (reporting the normal mode position) when switching buffers in events to another terminal until the next terminal_check call? (or until refresh_terminal is called for it) Maybe not worth fixing that, though.
This commit is contained in:
@@ -2185,7 +2185,7 @@ void mb_adjust_cursor(void)
|
||||
}
|
||||
|
||||
/// Checks and adjusts cursor column. Not mode-dependent.
|
||||
/// @see check_cursor_col_win
|
||||
/// @see check_cursor_col
|
||||
///
|
||||
/// @param win_ Places cursor on a valid column for this window.
|
||||
void mb_check_adjust_col(void *win_)
|
||||
|
@@ -2238,8 +2238,9 @@ static void adjust_topline(Terminal *term, buf_T *buf, int 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?
|
||||
bool focused = wp == curwin && is_focused(term);
|
||||
|
||||
if (following || (wp == curwin && is_focused(term))) {
|
||||
if (following || focused) {
|
||||
// "Follow" the terminal output
|
||||
wp->w_cursor.lnum = ml_end;
|
||||
set_topline(wp, MAX(wp->w_cursor.lnum - wp->w_view_height + 1, 1));
|
||||
@@ -2247,7 +2248,11 @@ static void adjust_topline(Terminal *term, buf_T *buf, int added)
|
||||
// Ensure valid cursor for each window displaying this terminal.
|
||||
wp->w_cursor.lnum = MIN(wp->w_cursor.lnum, ml_end);
|
||||
}
|
||||
mb_check_adjust_col(wp);
|
||||
if (focused) {
|
||||
terminal_check_cursor();
|
||||
} else {
|
||||
mb_check_adjust_col(wp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user