aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-16 09:31:05 +0800
committerGitHub <noreply@github.com>2022-07-16 09:31:05 +0800
commit73526abbbdf08e68e572b8e54c583de5a0323484 (patch)
tree7887fa868cdefc49c1ed501581a2767a3e55d30d /src
parent33da7d83e879e47cc84544507785d4e189b4200e (diff)
downloadrneovim-73526abbbdf08e68e572b8e54c583de5a0323484.tar.gz
rneovim-73526abbbdf08e68e572b8e54c583de5a0323484.tar.bz2
rneovim-73526abbbdf08e68e572b8e54c583de5a0323484.zip
fix(api): do not switch win/buf if getting option in current win/buf (#19383)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/options.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index 8c174fc129..4ed676e613 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -504,6 +504,7 @@ static int access_option_value(char *key, long *numval, char **stringval, int op
static int access_option_value_for(char *key, long *numval, char **stringval, int opt_flags,
int opt_type, void *from, bool get, Error *err)
{
+ bool need_switch = false;
switchwin_T switchwin;
aco_save_T aco;
int result = 0;
@@ -511,24 +512,32 @@ static int access_option_value_for(char *key, long *numval, char **stringval, in
try_start();
switch (opt_type) {
case SREQ_WIN:
- if (switch_win_noblock(&switchwin, (win_T *)from, win_find_tabpage((win_T *)from), true)
- == FAIL) {
- restore_win_noblock(&switchwin, true);
- if (try_end(err)) {
+ need_switch = (win_T *)from != curwin;
+ if (need_switch) {
+ if (switch_win_noblock(&switchwin, (win_T *)from, win_find_tabpage((win_T *)from), true)
+ == FAIL) {
+ restore_win_noblock(&switchwin, true);
+ if (try_end(err)) {
+ return result;
+ }
+ api_set_error(err, kErrorTypeException, "Problem while switching windows");
return result;
}
- api_set_error(err,
- kErrorTypeException,
- "Problem while switching windows");
- return result;
}
result = access_option_value(key, numval, stringval, opt_flags, get, err);
- restore_win_noblock(&switchwin, true);
+ if (need_switch) {
+ restore_win_noblock(&switchwin, true);
+ }
break;
case SREQ_BUF:
- aucmd_prepbuf(&aco, (buf_T *)from);
+ need_switch = (buf_T *)from != curbuf;
+ if (need_switch) {
+ aucmd_prepbuf(&aco, (buf_T *)from);
+ }
result = access_option_value(key, numval, stringval, opt_flags, get, err);
- aucmd_restbuf(&aco);
+ if (need_switch) {
+ aucmd_restbuf(&aco);
+ }
break;
case SREQ_GLOBAL:
result = access_option_value(key, numval, stringval, opt_flags, get, err);