Skip to content

Commit

Permalink
feat: split up hide_cursor option (#491)
Browse files Browse the repository at this point in the history
This revision introduces changes to the 'g:fern#hide_cursor' option.

Before these changes, this option forcibly disables 'cursorline' when
focus is not on the fern window and unsets 't_ve' to hide the cursor for
the fern window.

In some configurations, it's desirable to hide the cursor but not change
the cursorline configuration. For instance, the user may want to see
what item is selected in the fern window when working in other buffers.

Although it's relatively trivial to skip 'hide_cursor' altogether and
manually update 't_ve', I believe there's value in supporting this in
Fern.

This revision introduces a new option, 'g:fern#hide_cursorline', which
enables/disables the 'cursorline' option on WinEnter/WinLeave, similar
to what 'hide_cursor' did before.

Documentation has been updated to reflect this change.
  • Loading branch information
brandon1024 committed Dec 4, 2023
1 parent e295f0d commit 56f8e4c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions autoload/fern.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ call s:Config.config(expand('<sfile>:p'), {
\ 'loglevel': g:fern#INFO,
\ 'opener': 'edit',
\ 'hide_cursor': 0,
\ 'hide_cursorline': 0,
\ 'keepalt_on_edit': 0,
\ 'keepjumps_on_edit': 0,
\ 'disable_auto_buffer_delete': 0,
Expand Down
1 change: 1 addition & 0 deletions autoload/fern/internal/viewer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function! s:init() abort
augroup END
call fern#internal#viewer#auto_duplication#init()
call fern#internal#viewer#hide_cursor#init()
call fern#internal#viewer#hide_cursorline#init()

" Add unique fragment to make each buffer uniq
let bufname = bufname('%')
Expand Down
14 changes: 2 additions & 12 deletions autoload/fern/internal/viewer/hide_cursor.vim
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
function! fern#internal#viewer#hide_cursor#init() abort
if !g:fern#hide_cursor
return
if g:fern#hide_cursor
call s:hide_cursor_init()
endif
call s:hide_cursor_init()
endfunction

function! s:hide_cursor_init() abort
augroup fern_internal_viewer_smart_cursor_init
autocmd! * <buffer>
autocmd BufEnter,WinEnter,TabLeave,CmdwinLeave,CmdlineLeave <buffer> setlocal cursorline
autocmd BufLeave,WinLeave,TabLeave,CmdwinEnter,CmdlineEnter <buffer> setlocal nocursorline
autocmd BufEnter,WinEnter,TabLeave,CmdwinLeave,CmdlineLeave <buffer> call fern#internal#cursor#hide()
autocmd BufLeave,WinLeave,TabLeave,CmdwinEnter,CmdlineEnter <buffer> call fern#internal#cursor#restore()
autocmd VimLeave <buffer> call fern#internal#cursor#restore()
augroup END

" Do NOT allow cursorlineopt=number while the cursor is hidden (Fix #182)
if exists('+cursorlineopt')
" NOTE:
" Default value is `number,line` (or `both` prior to patch-8.1.2029)
setlocal cursorlineopt&
endif
endfunction
20 changes: 20 additions & 0 deletions autoload/fern/internal/viewer/hide_cursorline.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function! fern#internal#viewer#hide_cursorline#init() abort
if g:fern#hide_cursorline
call s:hide_cursorline_init()
endif
endfunction

function! s:hide_cursorline_init() abort
augroup fern_internal_viewer_smart_cursor_line_init
autocmd! * <buffer>
autocmd BufEnter,WinEnter,TabLeave,CmdwinLeave,CmdlineLeave <buffer> setlocal cursorline
autocmd BufLeave,WinLeave,TabLeave,CmdwinEnter,CmdlineEnter <buffer> setlocal nocursorline
augroup END

" Do NOT allow cursorlineopt=number while the cursor is hidden (Fix #182)
if exists('+cursorlineopt')
" NOTE:
" Default value is `number,line` (or `both` prior to patch-8.1.2029)
setlocal cursorlineopt&
endif
endfunction
10 changes: 6 additions & 4 deletions doc/fern.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,15 @@ VARIABLE *fern-variable*
Default: 'edit'

*g:fern#hide_cursor*
Set 1 to hide cursor and forcedly enable |cursorline| to visualize the
cursor node. The |cursorline| is automatically enabled when the focus
is on the buffer and automatically disabled when the cursor is out of
the buffer.
Set 1 to forcibly hide the cursor for the fern window (see |t_ve|).

Note that Neovim prior to 0.5.0 cannot hide the cursor thus faint
vertical bar is used instead.

*g:fern#hide_cursorline*
Set 1 to forcibly disable |cursorline| for the fern window
when focus is not on the fern window.

*g:fern#keepalt_on_edit*
Set 1 to apply |keepalt| on the "open:edit" action to keep an
|alternate-file| in a split windows style like:
Expand Down

0 comments on commit 56f8e4c

Please sign in to comment.