mirror of
https://github.com/neovim/neovim.git
synced 2026-08-20 14:21:06 +00:00
fix(editorconfig): avoid trim_trailing_whitespace in insert-mode #41175
Problem: During insert-mode / replace-mode, `autowrite` may trigger. If it does, the cursor position can shift due to the automatic removal of trailing spaces on the current line. When I resume typing, the space between the last word and the new word is suddenly gone. Solution: Disable the "remove trailing spaces" handler during Insert (or a similar) mode. Autosave logic is not affected.
This commit is contained in:
@@ -166,6 +166,10 @@ function properties.trim_trailing_whitespace(bufnr, val)
|
||||
)
|
||||
if val == 'true' then
|
||||
nvim_on('BufWritePre', 'nvim.editorconfig', { buf = bufnr }, function()
|
||||
local mode = vim.api.nvim_get_mode().mode
|
||||
if mode:sub(1, 1) == 'i' or mode:sub(1, 1) == 'R' or mode:sub(1, 2) == 'ni' then
|
||||
return
|
||||
end
|
||||
local view = vim.fn.winsaveview()
|
||||
vim.api.nvim_command('silent! undojoin')
|
||||
vim.api.nvim_command('silent keepjumps keeppatterns %s/\\s\\+$//e')
|
||||
|
||||
Reference in New Issue
Block a user