Skip to content

Commit

Permalink
Check if 'bufnr' is a fern buffer before replacing the buffer (#516)
Browse files Browse the repository at this point in the history
Close #514
  • Loading branch information
lambdalisue authored Dec 7, 2024
1 parent 95218a9 commit 56f7c0d
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 56f7c0d

Please sign in to comment.