Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadee7f6

Browse files
committed
fix(api): do not switch win/buf if getting option in current win/buf
1 parent1c9f487 commitadee7f6

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

‎src/nvim/api/options.c‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -504,31 +504,40 @@ static int access_option_value(char *key, long *numval, char **stringval, int op
504504
staticintaccess_option_value_for(char*key,long*numval,char**stringval,intopt_flags,
505505
intopt_type,void*from,boolget,Error*err)
506506
{
507+
boolneed_switch= false;
507508
switchwin_Tswitchwin;
508509
aco_save_Taco;
509510
intresult=0;
510511

511512
try_start();
512513
switch (opt_type) {
513514
caseSREQ_WIN:
514-
if (switch_win_noblock(&switchwin, (win_T*)from,win_find_tabpage((win_T*)from), true)
515-
==FAIL) {
516-
restore_win_noblock(&switchwin, true);
517-
if (try_end(err)) {
515+
need_switch= (win_T*)from!=curwin;
516+
if (need_switch) {
517+
if (switch_win_noblock(&switchwin, (win_T*)from,win_find_tabpage((win_T*)from), true)
518+
==FAIL) {
519+
restore_win_noblock(&switchwin, true);
520+
if (try_end(err)) {
521+
returnresult;
522+
}
523+
api_set_error(err,kErrorTypeException,"Problem while switching windows");
518524
returnresult;
519525
}
520-
api_set_error(err,
521-
kErrorTypeException,
522-
"Problem while switching windows");
523-
returnresult;
524526
}
525527
result=access_option_value(key,numval,stringval,opt_flags,get,err);
526-
restore_win_noblock(&switchwin, true);
528+
if (need_switch) {
529+
restore_win_noblock(&switchwin, true);
530+
}
527531
break;
528532
caseSREQ_BUF:
529-
aucmd_prepbuf(&aco, (buf_T*)from);
533+
need_switch= (buf_T*)from!=curbuf;
534+
if (need_switch) {
535+
aucmd_prepbuf(&aco, (buf_T*)from);
536+
}
530537
result=access_option_value(key,numval,stringval,opt_flags,get,err);
531-
aucmd_restbuf(&aco);
538+
if (need_switch) {
539+
aucmd_restbuf(&aco);
540+
}
532541
break;
533542
caseSREQ_GLOBAL:
534543
result=access_option_value(key,numval,stringval,opt_flags,get,err);

‎test/functional/api/vim_spec.lua‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,17 @@ describe('API', function()
14691469
nvim('win_set_option',win,'number',true)
14701470
eq(true,nvim('get_option_value','number', {win=win}))
14711471
end)
1472+
1473+
it('getting current buffer option does not adjust cursor #19381',function()
1474+
nvim('command','new')
1475+
localbuf=nvim('get_current_buf').id
1476+
localwin=nvim('get_current_win').id
1477+
insert('some text')
1478+
feed('0v$')
1479+
eq({1,9},nvim('win_get_cursor',win))
1480+
nvim('get_option_value','filetype', {buf=buf})
1481+
eq({1,9},nvim('win_get_cursor',win))
1482+
end)
14721483
end)
14731484

14741485
describe('nvim_{get,set}_current_buf, nvim_list_bufs',function()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp