aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-05-08 18:01:21 +0200
committerGitHub <noreply@github.com>2019-05-08 18:01:21 +0200
commit8330cc22afec67d9dbc2ad8b4a39eaf62fdf16d1 (patch)
treee22baa51856201ff97e2167a82a37a625ab6d20d /src/nvim/window.c
parentd36ef9339f398988d4ccefd4780b2f289b0c7f83 (diff)
downloadrneovim-8330cc22afec67d9dbc2ad8b4a39eaf62fdf16d1.tar.gz
rneovim-8330cc22afec67d9dbc2ad8b4a39eaf62fdf16d1.tar.bz2
rneovim-8330cc22afec67d9dbc2ad8b4a39eaf62fdf16d1.zip
vim-patch:8.1.1205: BufReadPre may move the cursor #9980
Problem: A BufReadPre autocommand may cause the cursor to move. Solution: Restore the cursor position after executing the autocommand, unless the autocommand moved it. (Christian Brabandt, closes vim/vim#4302, closes vim/vim#4294) https://github.com/vim/vim/commit/a68e59590905da9b4448ff1fcac929ad1a18da9e
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index e737bfbd05..200c651d1e 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -5963,16 +5963,40 @@ void check_lnums(int do_curwin)
{
FOR_ALL_TAB_WINDOWS(tp, wp) {
if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) {
+ // save the original cursor position and topline
+ wp->w_save_cursor.w_cursor_save = wp->w_cursor;
+ wp->w_save_cursor.w_topline_save = wp->w_topline;
+
if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
}
if (wp->w_topline > curbuf->b_ml.ml_line_count) {
wp->w_topline = curbuf->b_ml.ml_line_count;
}
+
+ // save the corrected cursor position and topline
+ wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
+ wp->w_save_cursor.w_topline_corr = wp->w_topline;
}
}
}
+/// Reset cursor and topline to its stored values from check_lnums().
+/// check_lnums() must have been called first!
+void reset_lnums(void)
+{
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if (wp->w_buffer == curbuf) {
+ // Restore the value if the autocommand didn't change it.
+ if (equalpos(wp->w_save_cursor.w_cursor_corr, wp->w_cursor)) {
+ wp->w_cursor = wp->w_save_cursor.w_cursor_save;
+ }
+ if (wp->w_save_cursor.w_topline_corr == wp->w_topline) {
+ wp->w_topline = wp->w_save_cursor.w_topline_save;
+ }
+ }
+ }
+}
/*
* A snapshot of the window sizes, to restore them after closing the help