mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
fix(api): do not switch win/buf if getting option in current win/buf (#19383)
This commit is contained in:
@@ -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:
|
||||
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");
|
||||
api_set_error(err, kErrorTypeException, "Problem while switching windows");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
result = access_option_value(key, numval, stringval, opt_flags, get, err);
|
||||
if (need_switch) {
|
||||
restore_win_noblock(&switchwin, true);
|
||||
}
|
||||
break;
|
||||
case SREQ_BUF:
|
||||
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);
|
||||
if (need_switch) {
|
||||
aucmd_restbuf(&aco);
|
||||
}
|
||||
break;
|
||||
case SREQ_GLOBAL:
|
||||
result = access_option_value(key, numval, stringval, opt_flags, get, err);
|
||||
|
@@ -1469,6 +1469,17 @@ describe('API', function()
|
||||
nvim('win_set_option', win, 'number', true)
|
||||
eq(true, nvim('get_option_value', 'number', {win = win}))
|
||||
end)
|
||||
|
||||
it('getting current buffer option does not adjust cursor #19381', function()
|
||||
nvim('command', 'new')
|
||||
local buf = nvim('get_current_buf').id
|
||||
local win = nvim('get_current_win').id
|
||||
insert('some text')
|
||||
feed('0v$')
|
||||
eq({1, 9}, nvim('win_get_cursor', win))
|
||||
nvim('get_option_value', 'filetype', {buf = buf})
|
||||
eq({1, 9}, nvim('win_get_cursor', win))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_{get,set}_current_buf, nvim_list_bufs', function()
|
||||
|
Reference in New Issue
Block a user