mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 15:58:17 +00:00
api/window_set_cursor: make sure cursor line is visible.
Previously, the cursor could be left outside the visible range if window is not the current window
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include "nvim/cursor.h"
|
#include "nvim/cursor.h"
|
||||||
#include "nvim/window.h"
|
#include "nvim/window.h"
|
||||||
#include "nvim/screen.h"
|
#include "nvim/screen.h"
|
||||||
|
#include "nvim/move.h"
|
||||||
#include "nvim/misc2.h"
|
#include "nvim/misc2.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -86,6 +87,10 @@ void window_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
|
|||||||
win->w_cursor.coladd = 0;
|
win->w_cursor.coladd = 0;
|
||||||
// When column is out of range silently correct it.
|
// When column is out of range silently correct it.
|
||||||
check_cursor_col_win(win);
|
check_cursor_col_win(win);
|
||||||
|
|
||||||
|
// make sure cursor is in visible range even if win != curwin
|
||||||
|
update_topline_win(win);
|
||||||
|
|
||||||
update_screen(VALID);
|
update_screen(VALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include "nvim/popupmnu.h"
|
#include "nvim/popupmnu.h"
|
||||||
#include "nvim/screen.h"
|
#include "nvim/screen.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
#include "nvim/window.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
linenr_T lnum; /* line number */
|
linenr_T lnum; /* line number */
|
||||||
@@ -314,6 +315,17 @@ void update_topline(void)
|
|||||||
p_so = save_so;
|
p_so = save_so;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Update win->w_topline to move the cursor onto the screen.
|
||||||
|
*/
|
||||||
|
void update_topline_win(win_T* win)
|
||||||
|
{
|
||||||
|
win_T *save_curwin;
|
||||||
|
switch_win(&save_curwin, NULL, win, NULL, true);
|
||||||
|
update_topline();
|
||||||
|
restore_win(save_curwin, NULL, true);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the scrolljump value to use for the current window.
|
* Return the scrolljump value to use for the current window.
|
||||||
* When 'scrolljump' is positive use it as-is.
|
* When 'scrolljump' is positive use it as-is.
|
||||||
|
Reference in New Issue
Block a user