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

nvim_buf_set_text in insert mode should update dot repeat #19806

Open
theol0403 opened this issue Aug 16, 2022 · 2 comments
Open

nvim_buf_set_text in insert mode should update dot repeat #19806

theol0403 opened this issue Aug 16, 2022 · 2 comments
Labels
api libnvim, Nvim RPC API bug issues reporting wrong behavior insert-mode needs:discussion For PRs that propose significant changes to some part of the architecture or API

Comments

@theol0403
Copy link

theol0403 commented Aug 16, 2022

Neovim version (nvim -v)

NVIM v0.8.0-dev+141-g55187de11

Vim (not Nvim) behaves the same?

N/A

Operating system/version

N/A

Terminal name/version

N/A

$TERM environment variable

N/A

Installation

N/A

How to reproduce the issue

Given the following steps in lua:

vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, {'one'})
vim.api.nvim_input('ciw')
vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, {'two'})
vim.api.nvim_input('<Esc>u')
vim.api.nvim_input('.')

Expected behavior

The buffer contains "two".

Actual behavior

The buffer is empty (the ciw was repeated, but not the insertion).

nvim_buf_set_text should only update dot repeat if the change is in one continuous region (someone typing or deleting). The changes should be accumulated until there is a discontunity.

Essentially, if start == end (insertion), or replacement == [""] (deletion), dot-repeat should accumulate just like nvim_input in insert mode.

Background

This is very important for vscode-neovim to improve reliablility and remove significant workarounds and bloat.
vscode-neovim/vscode-neovim#992

Vscode handles typing in insert mode, and then sends document changes to nvim via nvim_buf_set_text or nvim_buf_set_lines. However, because neovim does not properly record dot repeat, a workaround is currently needed that opens a scratch buffer, replays the changes by typing, and then returns to the original buffer.

@theol0403 theol0403 added the bug issues reporting wrong behavior label Aug 16, 2022
@theol0403 theol0403 changed the title nvim_buf_set_text should update dot repeat nvim_buf_set_text in insert mode should update dot repeat Aug 16, 2022
@zeertzjq zeertzjq added api libnvim, Nvim RPC API needs:discussion For PRs that propose significant changes to some part of the architecture or API labels Aug 16, 2022
@hrsh7th
Copy link
Sponsor Contributor

hrsh7th commented Aug 19, 2022

I try to share my knowledges.

  1. nvim-cmp uses feedkeys function to modify current line with updating dot-repeat register.
  2. coc.nvim uses complete function to modify current line with updating dot-repeat register.

In vim, I don't know of any function that modifies the dot-repeat register in a function intended to modify the text of the buffer.

But as one of the plugin author, I think this feature is very useful.

@theol0403
Copy link
Author

theol0403 commented Feb 3, 2024

This feature could also be partially resolved by manually writing to the dot repeat register. Technically, this is possible by using operatorfunc to trigger a nvim_input, but the problem is there is no way to recover the way insert mode was entered.

For example, if you type ciwtest, getreg(".") will return "test", not "ciwtest". Thus, it is impossible to fully reconstruct the dotrepeat sequence in order to overwrite the register.

Any other suggestions on how to do this, or can progress be made on the issue? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api libnvim, Nvim RPC API bug issues reporting wrong behavior insert-mode needs:discussion For PRs that propose significant changes to some part of the architecture or API
Projects
None yet
Development

No branches or pull requests

3 participants