From 12f38fc7a4326efaf15ff6a93ddfa948b809743d Mon Sep 17 00:00:00 2001 From: Milly Date: Sun, 19 Oct 2025 17:56:48 +0900 Subject: [PATCH] fix: prevent closing adjacent window when writing rename buffer with :wq The rename buffer's write command handler now uses a timer to defer window closing, ensuring only the rename buffer window is closed and not any adjacent windows when using :wq command. --- autoload/fern/internal/replacer.vim | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/autoload/fern/internal/replacer.vim b/autoload/fern/internal/replacer.vim index f462369a..fcce4543 100644 --- a/autoload/fern/internal/replacer.vim +++ b/autoload/fern/internal/replacer.vim @@ -97,16 +97,26 @@ function! s:BufWriteCmd() abort for Modifier in b:fern_replacer_modifiers let result = Modifier(result) endfor - let l:Resolve = b:fern_replacer_resolve - set nomodified - close - call Resolve(result) catch echohl ErrorMsg echo '[fern] Please fix the following error first to continue or cancel with ":q!"' echo printf('[fern] %s', substitute(v:exception, '^Vim(.*):', '', '')) echohl None + return endtry + set nomodified + let l:Resolve = b:fern_replacer_resolve + let winid = win_getid() + let bufnr = bufnr() + call timer_start(0, { -> s:post_write(l:Resolve, result, winid, bufnr) }) +endfunction + +function! s:post_write(resolve, result, winid, bufnr) abort + if winbufnr(a:winid) == a:bufnr + call win_execute(a:winid, 'close') + endif + let l:Resolve = a:resolve + call Resolve(a:result) endfunction function! s:syntax() abort