Skip to content

vim: Fix visual block Shift-I jumping to original cursor after Ctrl-D scroll#50822

Merged
dinocosta merged 3 commits intozed-industries:mainfrom
cppcoffee:vim_block_insert
Mar 18, 2026
Merged

vim: Fix visual block Shift-I jumping to original cursor after Ctrl-D scroll#50822
dinocosta merged 3 commits intozed-industries:mainfrom
cppcoffee:vim_block_insert

Conversation

@cppcoffee
Copy link
Copy Markdown
Contributor

@cppcoffee cppcoffee commented Mar 5, 2026

Release Notes:

  • Fixed visual block shift-i jumping to the initial cursor position after scrolling with ctrl-d/ctrl-u

In Vim mode, press Ctrl+V to enter line selection, press Ctrl+D to start scrolling, then press Shift+I to insert into the newly selected multiple lines.

Current: Jump to the beginning
Expected: Enter multi-line insert mode

before:

2026-03-05.20.47.18.mov

after:

2026-03-05.20.46.41.mov

vim behaviour:

2026-03-05.20.52.53.mov

… scroll

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 5, 2026
@MrSubidubi MrSubidubi requested review from cole-miller and removed request for cole-miller March 5, 2026 14:34
Copy link
Copy Markdown
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cppcoffee 👋

Thank you so much for finding this issue and attempting to fix it! Although the changes do fix the outlined issue, it seems to accidentally introduce a different issue, so I've left some feedback 🙂

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
@cppcoffee
Copy link
Copy Markdown
Contributor Author

The JSON test data file added.

* Update `vim::normal::scroll::scroll_editor` to be a method in `Vim`,
  removing the need to pass it a `&mut Vim`, `&mut Editor` and `Mode`
  arguments, as those can all be obtained from having access to `&mut
  Vim`.
* Simplify the `vim::visual::test:;test_visual_block_wrapping_selection`
  test and use `assert_eq` so it's a little bit easier to understand
  what the final result should be without having to dig into the JSON
  file for the test.
Copy link
Copy Markdown
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @cppcoffee 🙂

I've pushed a commit with some minor refactoring but everything looks good!

@dinocosta dinocosta enabled auto-merge (squash) March 18, 2026 10:58
@dinocosta dinocosta merged commit 3af7b64 into zed-industries:main Mar 18, 2026
30 checks passed
@cppcoffee cppcoffee deleted the vim_block_insert branch March 18, 2026 12:19
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 18, 2026
… scroll (zed-industries#50822)

Ensure that the `vim::visual::Vim::visual_block_motion` method is called
when `scroll_editor` is called while in Visual Block mode. This fixes an
issue where, after getting into `Visual Block` mode, if the user used
`ctrl-d` or `ctrl-u` to scroll half of the page, the wrong selection
would be made and, if `shift-i` was used to start inserting at the start
of the line, a single cursor would be placed at the cursor position
where the selection was started, instead of one cursor per each of the
selected lines.

These changes ensure that we now match Neovim's behavior for the same
flow.

---------

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
… scroll (zed-industries#50822)

Ensure that the `vim::visual::Vim::visual_block_motion` method is called
when `scroll_editor` is called while in Visual Block mode. This fixes an
issue where, after getting into `Visual Block` mode, if the user used
`ctrl-d` or `ctrl-u` to scroll half of the page, the wrong selection
would be made and, if `shift-i` was used to start inserting at the start
of the line, a single cursor would be placed at the cursor position
where the selection was started, instead of one cursor per each of the
selected lines.

These changes ensure that we now match Neovim's behavior for the same
flow.

---------

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
… scroll (zed-industries#50822)

Ensure that the `vim::visual::Vim::visual_block_motion` method is called
when `scroll_editor` is called while in Visual Block mode. This fixes an
issue where, after getting into `Visual Block` mode, if the user used
`ctrl-d` or `ctrl-u` to scroll half of the page, the wrong selection
would be made and, if `shift-i` was used to start inserting at the start
of the line, a single cursor would be placed at the cursor position
where the selection was started, instead of one cursor per each of the
selected lines.

These changes ensure that we now match Neovim's behavior for the same
flow.

---------

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
… scroll (zed-industries#50822)

Ensure that the `vim::visual::Vim::visual_block_motion` method is called
when `scroll_editor` is called while in Visual Block mode. This fixes an
issue where, after getting into `Visual Block` mode, if the user used
`ctrl-d` or `ctrl-u` to scroll half of the page, the wrong selection
would be made and, if `shift-i` was used to start inserting at the start
of the line, a single cursor would be placed at the cursor position
where the selection was started, instead of one cursor per each of the
selected lines.

These changes ensure that we now match Neovim's behavior for the same
flow.

---------

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants