mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 04:01:13 +01:00
Fix: saving an edited or unedited empty buffer with a filename of a already existing file worked, but then stopped further saving with <leader>w.
This commit is contained in:
@@ -182,9 +182,18 @@ local function smart_save(force_save_as)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- For no-name buffers or Save As, write and set buffer name
|
-- For no-name buffers or Save As, write and set buffer name
|
||||||
|
if current_path == '' then
|
||||||
|
-- No-name buffer: set name first
|
||||||
|
vim.api.nvim_buf_set_name(0, filename)
|
||||||
|
-- Force overwrite if file exists
|
||||||
|
local write_cmd = 'write!'
|
||||||
|
vim.cmd(write_cmd)
|
||||||
|
-- Clear modified flag so future saves work correctly
|
||||||
|
vim.api.nvim_buf_set_option(0, 'modified', false)
|
||||||
|
else
|
||||||
|
-- Named buffer: normal Save As logic
|
||||||
local write_cmd = overwrite and 'write!' or 'write'
|
local write_cmd = overwrite and 'write!' or 'write'
|
||||||
vim.cmd(write_cmd .. ' ' .. vim.fn.fnameescape(filename))
|
vim.cmd(write_cmd .. ' ' .. vim.fn.fnameescape(filename))
|
||||||
if current_path ~= '' then
|
|
||||||
-- Preserve cursor position and undo history
|
-- Preserve cursor position and undo history
|
||||||
local old_buf = vim.api.nvim_get_current_buf()
|
local old_buf = vim.api.nvim_get_current_buf()
|
||||||
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||||||
@@ -197,9 +206,6 @@ local function smart_save(force_save_as)
|
|||||||
vim.cmd 'undojoin'
|
vim.cmd 'undojoin'
|
||||||
-- Delete the old buffer without saving
|
-- Delete the old buffer without saving
|
||||||
vim.api.nvim_buf_delete(old_buf, { force = true })
|
vim.api.nvim_buf_delete(old_buf, { force = true })
|
||||||
else
|
|
||||||
-- No-name buffer, just set its name
|
|
||||||
vim.api.nvim_buf_set_name(0, filename)
|
|
||||||
end
|
end
|
||||||
print('Saved as ' .. filename)
|
print('Saved as ' .. filename)
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user