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

Check if 'bufnr' is a fern buffer before replacing the buffer #516

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions autoload/fern/helper/async.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ function! s:async_redraw() abort dict
let fern = helper.fern
return s:Promise.resolve()
\.then({ -> fern.renderer.render(fern.visible_nodes) })
\.then({ v -> s:reject_on_non_fern_buffer(helper.bufnr, v) })
\.then({ v -> fern#internal#buffer#replace(helper.bufnr, v) })
\.then({ -> helper.async.remark() })
\.then({ -> fern#hook#emit('viewer:redraw', helper) })
\.catch({ e -> s:is_non_fern_buffer_rejection(e) ? 0 : s:Promise.reject(e) })
\.finally({ -> Profile() })
endfunction
let s:async.redraw = funcref('s:async_redraw')
Expand Down Expand Up @@ -347,3 +349,18 @@ function! s:enter(fern, node) abort
return s:Promise.reject(v:exception)
endtry
endfunction

" Check if the 'bufnr' is a fern buffer
" This check is required because the 'bufnr' may be a buffer that is not a
" fern buffer caused by 'enew' command prior to the initial rendering.
" See https://github.com/lambdalisue/fern.vim/issues/514 for detail.
function! s:reject_on_non_fern_buffer(bufnr, value) abort
if bufname(a:bufnr) !~# 'fern://'
return s:Promise.reject('reject because the buffer is not a fern buffer')
endif
return s:Promise.resolve(a:value)
endfunction

function! s:is_non_fern_buffer_rejection(message) abort
return a:message ==# 'reject because the buffer is not a fern buffer'
endfunction
Loading