Skip to content

Commit

Permalink
Merge pull request #188 from lambdalisue/fix-renderer
Browse files Browse the repository at this point in the history
Fix highlight issue on the default renderer
  • Loading branch information
lambdalisue authored Aug 31, 2020
2 parents 72be136 + 125d8c3 commit 8353204
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
14 changes: 10 additions & 4 deletions autoload/fern/renderer/default.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ function! s:lnum(index) abort
endfunction

function! s:syntax() abort
syntax match FernLeaf /^.*[^/].*$/ transparent contains=FernLeafSymbol
syntax match FernBranch /^.*\/.*$/ transparent contains=FernBranchSymbol
syntax match FernRoot /\%1l.*/ transparent contains=FernRootText
execute printf(
\ 'syntax match FernRootSymbol /\%%1l%s/ nextgroup=FernRootText',
\ 'syntax match FernRootSymbol /%s/ contained nextgroup=FernRootText',
\ escape(g:fern#renderer#default#root_symbol, s:ESCAPE_PATTERN),
\)
execute printf(
\ 'syntax match FernLeafSymbol /^\s*%s/ nextgroup=FernLeafText',
\ 'syntax match FernLeafSymbol /^\%%(%s\)*%s/ contained nextgroup=FernLeafText',
\ escape(g:fern#renderer#default#leading, s:ESCAPE_PATTERN),
\ escape(g:fern#renderer#default#leaf_symbol, s:ESCAPE_PATTERN),
\)
execute printf(
\ 'syntax match FernBranchSymbol /^\s*\%%(%s\|%s\)/ nextgroup=FernBranchText',
\ 'syntax match FernBranchSymbol /^\%%(%s\)*\%%(%s\|%s\)/ contained nextgroup=FernBranchText',
\ escape(g:fern#renderer#default#leading, s:ESCAPE_PATTERN),
\ escape(g:fern#renderer#default#collapsed_symbol, s:ESCAPE_PATTERN),
\ escape(g:fern#renderer#default#expanded_symbol, s:ESCAPE_PATTERN),
\)
Expand Down Expand Up @@ -79,7 +84,8 @@ function! s:render_node(node, base, options) abort
\ : a:node.status is# s:STATUS_COLLAPSED
\ ? a:options.collapsed_symbol
\ : a:options.expanded_symbol
return leading . symbol . a:node.label . '' . a:node.badge
let suffix = a:node.status ? '/' : ''
return leading . symbol . a:node.label . suffix . '' . a:node.badge
endfunction

call s:Config.config(expand('<sfile>:p'), {
Expand Down
54 changes: 27 additions & 27 deletions test/behavior/Fern.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Describe Fern
Assert Equals(winnr('$'), 1)
Assert Equals(getline(1, '$'), [
\ 'root',
\ '|+ deep',
\ '|+ heavy',
\ '|+ shallow',
\ '|+ deep/',
\ '|+ heavy/',
\ '|+ shallow/',
\ '| leaf',
\])
End
Expand All @@ -37,12 +37,12 @@ Describe Fern
Fern debug:/// -reveal=deep/alpha/beta -wait
Assert Equals(getline(1, '$'), [
\ 'root',
\ '|- deep',
\ ' |- alpha',
\ ' |- beta',
\ '|- deep/',
\ ' |- alpha/',
\ ' |- beta/',
\ ' | gamma',
\ '|+ heavy',
\ '|+ shallow',
\ '|+ heavy/',
\ '|+ shallow/',
\ '| leaf',
\])
End
Expand All @@ -51,11 +51,11 @@ Describe Fern
Fern debug:/// -reveal=deep/alpha/zeta -wait
Assert Equals(getline(1, '$'), [
\ 'root',
\ '|- deep',
\ ' |- alpha',
\ ' |+ beta',
\ '|+ heavy',
\ '|+ shallow',
\ '|- deep/',
\ ' |- alpha/',
\ ' |+ beta/',
\ '|+ heavy/',
\ '|+ shallow/',
\ '| leaf',
\])
End
Expand All @@ -66,8 +66,8 @@ Describe Fern
execute printf('Fern %s -wait', fnameescape(workdir))
Assert Equals(winnr('$'), 1)
Assert Equals(getline(2, '$'), [
\ '|+ deep',
\ '|+ shallow',
\ '|+ deep/',
\ '|+ shallow/',
\ '| leaf',
\])
End
Expand All @@ -76,11 +76,11 @@ Describe Fern
execute printf('Fern %s -reveal=deep/alpha/beta -wait', fnameescape(workdir))
Assert Equals(winnr('$'), 1)
Assert Equals(getline(2, '$'), [
\ '|- deep',
\ ' |- alpha',
\ ' |- beta',
\ '|- deep/',
\ ' |- alpha/',
\ ' |- beta/',
\ ' | gamma',
\ '|+ shallow',
\ '|+ shallow/',
\ '| leaf',
\])
End
Expand All @@ -93,11 +93,11 @@ Describe Fern
\)
Assert Equals(winnr('$'), 1)
Assert Equals(getline(2, '$'), [
\ '|- deep',
\ ' |- alpha',
\ ' |- beta',
\ '|- deep/',
\ ' |- alpha/',
\ ' |- beta/',
\ ' | gamma',
\ '|+ shallow',
\ '|+ shallow/',
\ '| leaf',
\])
End
Expand All @@ -110,11 +110,11 @@ Describe Fern
\)
Assert Equals(winnr('$'), 1)
Assert Equals(getline(2, '$'), [
\ '|- deep',
\ ' |- alpha',
\ ' |- beta',
\ '|- deep/',
\ ' |- alpha/',
\ ' |- beta/',
\ ' | gamma',
\ '|+ shallow',
\ '|+ shallow/',
\ '| leaf',
\])
End
Expand Down
10 changes: 5 additions & 5 deletions test/behavior/special-characters.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,35 @@ Describe special-characters
endif
execute printf('Fern %s -wait', fnameescape(Join([workdir, ';'])))
Assert Equals(getline(2, '$'), [
\ '|+ hello',
\ '|+ hello/',
\])
End

It Fern {workdir}/# opens the directory
execute printf('Fern %s -wait', fnameescape(Join([workdir, '#'])))
Assert Equals(getline(2, '$'), [
\ '|+ hello',
\ '|+ hello/',
\])
End

It Fern {workdir}/$ opens the directory
execute printf('Fern %s -wait', fnameescape(Join([workdir, '$'])))
Assert Equals(getline(2, '$'), [
\ '|+ hello',
\ '|+ hello/',
\])
End

It Fern {workdir}/% opens the directory
execute printf('Fern %s -wait', fnameescape(Join([workdir, '%'])))
Assert Equals(getline(2, '$'), [
\ '|+ hello',
\ '|+ hello/',
\])
End

It Fern {workdir}/%20 opens the directory
execute printf('Fern %s -wait', fnameescape(Join([workdir, '%20'])))
Assert Equals(getline(2, '$'), [
\ '|+ hello',
\ '|+ hello/',
\])
End
End
12 changes: 6 additions & 6 deletions test/fern/renderer/default.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Describe fern#renderer#default
Assert Equals(e, v:null)
Assert Equals(r, [
\ 'root',
\ '|- shallow',
\ ' |+ alpha',
\ ' |+ beta',
\ '|- shallow/',
\ ' |+ alpha/',
\ ' |+ beta/',
\ ' | gamma',
\])
End
Expand All @@ -59,9 +59,9 @@ Describe fern#renderer#default
Assert Equals(e, v:null)
Assert Equals(r, [
\ 'root',
\ '|- shallow',
\ ' |+ alpha',
\ ' |+ beta',
\ '|- shallow/',
\ ' |+ alpha/',
\ ' |+ beta/',
\ ' | gamma',
\])
End
Expand Down

0 comments on commit 8353204

Please sign in to comment.