mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 15:58:17 +00:00
fix(buffer_updates): save and restore current window cursor (#16732)
When a buffer update callback is called, textlock is active so buffer text cannot be changed, but cursor can still be moved. This can cause problems when the buffer update is in the middle of an operator, like the one mentioned in #16729. The solution is to save cursor position and restore it afterwards, like how cursor is saved and restored when evaluating an <expr> mapping.
This commit is contained in:
@@ -155,8 +155,18 @@ typedef struct {
|
||||
msglist_T *private_msg_list; \
|
||||
msg_list = &private_msg_list; \
|
||||
private_msg_list = NULL; \
|
||||
code \
|
||||
msg_list = saved_msg_list; /* Restore the exception context. */ \
|
||||
code; \
|
||||
msg_list = saved_msg_list; /* Restore the exception context. */ \
|
||||
} while (0)
|
||||
|
||||
// Execute code with cursor position saved and restored and textlock active.
|
||||
#define TEXTLOCK_WRAP(code) \
|
||||
do { \
|
||||
const pos_T save_cursor = curwin->w_cursor; \
|
||||
textlock++; \
|
||||
code; \
|
||||
textlock--; \
|
||||
curwin->w_cursor = save_cursor; \
|
||||
} while (0)
|
||||
|
||||
// Useful macro for executing some `code` for each item in an array.
|
||||
|
Reference in New Issue
Block a user