Enhance formatting by preserving view on save, update keymaps
Save cursor position and folds before formatting, restoring them afterwards to improve user experience during format-on-save.
This commit is contained in:
parent
8cf56f13e5
commit
8c9f117320
|
|
@ -87,7 +87,11 @@ return {
|
||||||
callback = function()
|
callback = function()
|
||||||
-- Only format if format-on-save is enabled (global flag)
|
-- Only format if format-on-save is enabled (global flag)
|
||||||
if vim.g.format_on_save ~= false then
|
if vim.g.format_on_save ~= false then
|
||||||
|
-- Save view (cursor position, folds, etc.) before formatting
|
||||||
|
local view = vim.fn.winsaveview()
|
||||||
vim.lsp.buf.format({ bufnr = bufnr })
|
vim.lsp.buf.format({ bufnr = bufnr })
|
||||||
|
-- Restore view after formatting to preserve folds
|
||||||
|
vim.fn.winrestview(view)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -51,10 +51,10 @@ return {
|
||||||
incremental_selection = {
|
incremental_selection = {
|
||||||
enable = true,
|
enable = true,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
init_selection = "<CR>",
|
init_selection = "+",
|
||||||
node_incremental = "<CR>",
|
node_incremental = "+",
|
||||||
scope_incremental = "<S-CR>",
|
scope_incremental = "g+",
|
||||||
node_decremental = "<BS>",
|
node_decremental = "-",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue