Mercurial > vim
comparison src/window.c @ 16401:3b2db762a509 v8.1.1205
patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
commit https://github.com/vim/vim/commit/a68e59590905da9b4448ff1fcac929ad1a18da9e
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 25 22:22:01 2019 +0200
patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
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 #4302, closes #4294)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 25 Apr 2019 22:30:05 +0200 |
parents | b3bc3ba07bef |
children | 840fa633ad64 |
comparison
equal
deleted
inserted
replaced
16400:73200ce89e05 | 16401:3b2db762a509 |
---|---|
6194 tabpage_T *tp; | 6194 tabpage_T *tp; |
6195 | 6195 |
6196 FOR_ALL_TAB_WINDOWS(tp, wp) | 6196 FOR_ALL_TAB_WINDOWS(tp, wp) |
6197 if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) | 6197 if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) |
6198 { | 6198 { |
6199 // save the original cursor position and topline | |
6200 wp->w_save_cursor.w_cursor_save = wp->w_cursor; | |
6201 wp->w_save_cursor.w_topline_save = wp->w_topline; | |
6202 | |
6199 if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count) | 6203 if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
6200 wp->w_cursor.lnum = curbuf->b_ml.ml_line_count; | 6204 wp->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
6201 if (wp->w_topline > curbuf->b_ml.ml_line_count) | 6205 if (wp->w_topline > curbuf->b_ml.ml_line_count) |
6202 wp->w_topline = curbuf->b_ml.ml_line_count; | 6206 wp->w_topline = curbuf->b_ml.ml_line_count; |
6207 | |
6208 // save the corrected cursor position and topline | |
6209 wp->w_save_cursor.w_cursor_corr = wp->w_cursor; | |
6210 wp->w_save_cursor.w_topline_corr = wp->w_topline; | |
6211 } | |
6212 } | |
6213 | |
6214 /* | |
6215 * Reset cursor and topline to its stored values from check_lnums(). | |
6216 * check_lnums() must have been called first! | |
6217 */ | |
6218 void | |
6219 reset_lnums() | |
6220 { | |
6221 win_T *wp; | |
6222 tabpage_T *tp; | |
6223 | |
6224 FOR_ALL_TAB_WINDOWS(tp, wp) | |
6225 if (wp->w_buffer == curbuf) | |
6226 { | |
6227 // Restore the value if the autocommand didn't change it. | |
6228 if (EQUAL_POS(wp->w_save_cursor.w_cursor_corr, wp->w_cursor)) | |
6229 wp->w_cursor = wp->w_save_cursor.w_cursor_save; | |
6230 if (wp->w_save_cursor.w_topline_corr == wp->w_topline) | |
6231 wp->w_topline = wp->w_save_cursor.w_topline_save; | |
6203 } | 6232 } |
6204 } | 6233 } |
6205 | 6234 |
6206 /* | 6235 /* |
6207 * A snapshot of the window sizes, to restore them after closing the help | 6236 * A snapshot of the window sizes, to restore them after closing the help |