diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-03-09 10:19:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-09 10:19:00 +0800 |
commit | 89a525de9f2551e460cc91d40fd7afbb7e07622f (patch) | |
tree | 2e9bd543d89b693c7a6382fa66ec82488f8a0c61 /src/nvim/api/private/helpers.h | |
parent | eaccd0decd707ff7cec318e06914f963daa9574c (diff) | |
download | rneovim-89a525de9f2551e460cc91d40fd7afbb7e07622f.tar.gz rneovim-89a525de9f2551e460cc91d40fd7afbb7e07622f.tar.bz2 rneovim-89a525de9f2551e460cc91d40fd7afbb7e07622f.zip |
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.
Diffstat (limited to 'src/nvim/api/private/helpers.h')
-rw-r--r-- | src/nvim/api/private/helpers.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index b70452d7cb..1b82aeac34 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -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. |