Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:bnext cursor positioning is different for a hidden buffer vs a buffer shown in another window #11558

Open
zeertzjq opened this issue Nov 16, 2022 · 6 comments
Labels

Comments

@zeertzjq
Copy link
Member

Steps to reproduce

  1. Run vim --clean
  2. Source the following file:
set hidden
call setline(1, range(&lines + 10))
normal! G
vsplit
enew
bnext
  1. Cursor in the left window is at the top of the file

Expected behaviour

Cursor in the left window is at the bottom of the file. The is the behavior if I removed the :vsplit, and if I revert patch 8.1.0425 I also get this behavior.

Version of Vim

9.0.813

Environment

Operating system: Arch Linux
Terminal: kitty
Value of $TERM: xterm-kitty
Shell: fish

Logs and stack traces

No response

@zeertzjq zeertzjq added the bug label Nov 16, 2022
@brammool
Copy link
Contributor

brammool commented Nov 16, 2022 via email

@zeertzjq
Copy link
Member Author

I don't think this has anything to do with autocommands. :bnext still moves the cursor to last position when the buffer is not loaded even if I remove the autocommand:

augroup vimStartup | au! | augroup END
set hidden
call setline(1, range(&lines + 10))
normal! G
enew
bnext

And if revert patch 8.1.0425:

diff --git a/src/buffer.c b/src/buffer.c
index de4c40b58..78b41cd26 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1906,9 +1906,6 @@ enter_buffer(buf_T *buf)
     // mark cursor position as being invalid
     curwin->w_valid = 0;
 
-    buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.lnum,
-					      curbuf->b_last_cursor.col, TRUE);
-
     // Make sure the buffer is loaded.
     if (curbuf->b_ml.ml_mfp == NULL)	// need to load the file
     {

The cursor is then also moved when the buffer is shown in another window even if I remove the autocommand:

augroup vimStartup | au! | augroup END
set hidden
call setline(1, range(&lines + 10))
normal! G
vsplit
enew
bnext

@zeertzjq
Copy link
Member Author

Taking another look at patch 8.1.0425, it seems that fix doesn't always work. If the buffer isn't visible in any window, then curwin still cannot be set to a window that contains the buffer.

@brammool
Copy link
Contributor

brammool commented Nov 17, 2022 via email

brammool added a commit that referenced this issue Nov 19, 2022
Problem:    Setting lines in another buffer may not work well.
Solution:   Make sure the buffer being changed has a window. (issue #11558)
@brammool
Copy link
Contributor

I added the patch to make sure the buffer is changed in the context of a window. Please check that either this has fixed the problem or it can still be reproduced.
If this did fix the problem, can you write a regression test?
If did this not fix the problem, what is the simplest way to reproduce? Ideally in the form of a failing test.

@brammool
Copy link
Contributor

Perhaps patch 9.0.0961 also matters for this issue.
Otherwise the questions from 8 days ago still matter.

zeertzjq added a commit to zeertzjq/neovim that referenced this issue Nov 29, 2022
Problem:    Setting lines in another buffer may not work well.
Solution:   Make sure the buffer being changed has a window. (issue vim/vim#11558)

vim/vim@c934bfa

Co-authored-by: Bram Moolenaar <Bram@vim.org>
Nero-F pushed a commit to Nero-F/neovim that referenced this issue Dec 16, 2022
Problem:    Setting lines in another buffer may not work well.
Solution:   Make sure the buffer being changed has a window. (issue vim/vim#11558)

vim/vim@c934bfa

Co-authored-by: Bram Moolenaar <Bram@vim.org>
yesean pushed a commit to yesean/neovim that referenced this issue Mar 25, 2023
Problem:    Setting lines in another buffer may not work well.
Solution:   Make sure the buffer being changed has a window. (issue vim/vim#11558)

vim/vim@c934bfa

Co-authored-by: Bram Moolenaar <Bram@vim.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants