Skip to content

Commit 8353204

Browse files
authored
Merge pull request #188 from lambdalisue/fix-renderer
Fix highlight issue on the default renderer
2 parents 72be136 + 125d8c3 commit 8353204

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

autoload/fern/renderer/default.vim

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,21 @@ function! s:lnum(index) abort
3838
endfunction
3939

4040
function! s:syntax() abort
41+
syntax match FernLeaf /^.*[^/].*$/ transparent contains=FernLeafSymbol
42+
syntax match FernBranch /^.*\/.*$/ transparent contains=FernBranchSymbol
43+
syntax match FernRoot /\%1l.*/ transparent contains=FernRootText
4144
execute printf(
42-
\ 'syntax match FernRootSymbol /\%%1l%s/ nextgroup=FernRootText',
45+
\ 'syntax match FernRootSymbol /%s/ contained nextgroup=FernRootText',
4346
\ escape(g:fern#renderer#default#root_symbol, s:ESCAPE_PATTERN),
4447
\)
4548
execute printf(
46-
\ 'syntax match FernLeafSymbol /^\s*%s/ nextgroup=FernLeafText',
49+
\ 'syntax match FernLeafSymbol /^\%%(%s\)*%s/ contained nextgroup=FernLeafText',
50+
\ escape(g:fern#renderer#default#leading, s:ESCAPE_PATTERN),
4751
\ escape(g:fern#renderer#default#leaf_symbol, s:ESCAPE_PATTERN),
4852
\)
4953
execute printf(
50-
\ 'syntax match FernBranchSymbol /^\s*\%%(%s\|%s\)/ nextgroup=FernBranchText',
54+
\ 'syntax match FernBranchSymbol /^\%%(%s\)*\%%(%s\|%s\)/ contained nextgroup=FernBranchText',
55+
\ escape(g:fern#renderer#default#leading, s:ESCAPE_PATTERN),
5156
\ escape(g:fern#renderer#default#collapsed_symbol, s:ESCAPE_PATTERN),
5257
\ escape(g:fern#renderer#default#expanded_symbol, s:ESCAPE_PATTERN),
5358
\)
@@ -79,7 +84,8 @@ function! s:render_node(node, base, options) abort
7984
\ : a:node.status is# s:STATUS_COLLAPSED
8085
\ ? a:options.collapsed_symbol
8186
\ : a:options.expanded_symbol
82-
return leading . symbol . a:node.label . '' . a:node.badge
87+
let suffix = a:node.status ? '/' : ''
88+
return leading . symbol . a:node.label . suffix . '' . a:node.badge
8389
endfunction
8490

8591
call s:Config.config(expand('<sfile>:p'), {

test/behavior/Fern.vimspec

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Describe Fern
2626
Assert Equals(winnr('$'), 1)
2727
Assert Equals(getline(1, '$'), [
2828
\ 'root',
29-
\ '|+ deep',
30-
\ '|+ heavy',
31-
\ '|+ shallow',
29+
\ '|+ deep/',
30+
\ '|+ heavy/',
31+
\ '|+ shallow/',
3232
\ '| leaf',
3333
\])
3434
End
@@ -37,12 +37,12 @@ Describe Fern
3737
Fern debug:/// -reveal=deep/alpha/beta -wait
3838
Assert Equals(getline(1, '$'), [
3939
\ 'root',
40-
\ '|- deep',
41-
\ ' |- alpha',
42-
\ ' |- beta',
40+
\ '|- deep/',
41+
\ ' |- alpha/',
42+
\ ' |- beta/',
4343
\ ' | gamma',
44-
\ '|+ heavy',
45-
\ '|+ shallow',
44+
\ '|+ heavy/',
45+
\ '|+ shallow/',
4646
\ '| leaf',
4747
\])
4848
End
@@ -51,11 +51,11 @@ Describe Fern
5151
Fern debug:/// -reveal=deep/alpha/zeta -wait
5252
Assert Equals(getline(1, '$'), [
5353
\ 'root',
54-
\ '|- deep',
55-
\ ' |- alpha',
56-
\ ' |+ beta',
57-
\ '|+ heavy',
58-
\ '|+ shallow',
54+
\ '|- deep/',
55+
\ ' |- alpha/',
56+
\ ' |+ beta/',
57+
\ '|+ heavy/',
58+
\ '|+ shallow/',
5959
\ '| leaf',
6060
\])
6161
End
@@ -66,8 +66,8 @@ Describe Fern
6666
execute printf('Fern %s -wait', fnameescape(workdir))
6767
Assert Equals(winnr('$'), 1)
6868
Assert Equals(getline(2, '$'), [
69-
\ '|+ deep',
70-
\ '|+ shallow',
69+
\ '|+ deep/',
70+
\ '|+ shallow/',
7171
\ '| leaf',
7272
\])
7373
End
@@ -76,11 +76,11 @@ Describe Fern
7676
execute printf('Fern %s -reveal=deep/alpha/beta -wait', fnameescape(workdir))
7777
Assert Equals(winnr('$'), 1)
7878
Assert Equals(getline(2, '$'), [
79-
\ '|- deep',
80-
\ ' |- alpha',
81-
\ ' |- beta',
79+
\ '|- deep/',
80+
\ ' |- alpha/',
81+
\ ' |- beta/',
8282
\ ' | gamma',
83-
\ '|+ shallow',
83+
\ '|+ shallow/',
8484
\ '| leaf',
8585
\])
8686
End
@@ -93,11 +93,11 @@ Describe Fern
9393
\)
9494
Assert Equals(winnr('$'), 1)
9595
Assert Equals(getline(2, '$'), [
96-
\ '|- deep',
97-
\ ' |- alpha',
98-
\ ' |- beta',
96+
\ '|- deep/',
97+
\ ' |- alpha/',
98+
\ ' |- beta/',
9999
\ ' | gamma',
100-
\ '|+ shallow',
100+
\ '|+ shallow/',
101101
\ '| leaf',
102102
\])
103103
End
@@ -110,11 +110,11 @@ Describe Fern
110110
\)
111111
Assert Equals(winnr('$'), 1)
112112
Assert Equals(getline(2, '$'), [
113-
\ '|- deep',
114-
\ ' |- alpha',
115-
\ ' |- beta',
113+
\ '|- deep/',
114+
\ ' |- alpha/',
115+
\ ' |- beta/',
116116
\ ' | gamma',
117-
\ '|+ shallow',
117+
\ '|+ shallow/',
118118
\ '| leaf',
119119
\])
120120
End

test/behavior/special-characters.vimspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,35 @@ Describe special-characters
3131
endif
3232
execute printf('Fern %s -wait', fnameescape(Join([workdir, ';'])))
3333
Assert Equals(getline(2, '$'), [
34-
\ '|+ hello',
34+
\ '|+ hello/',
3535
\])
3636
End
3737

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

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

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

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

test/fern/renderer/default.vimspec

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ Describe fern#renderer#default
4040
Assert Equals(e, v:null)
4141
Assert Equals(r, [
4242
\ 'root',
43-
\ '|- shallow',
44-
\ ' |+ alpha',
45-
\ ' |+ beta',
43+
\ '|- shallow/',
44+
\ ' |+ alpha/',
45+
\ ' |+ beta/',
4646
\ ' | gamma',
4747
\])
4848
End
@@ -59,9 +59,9 @@ Describe fern#renderer#default
5959
Assert Equals(e, v:null)
6060
Assert Equals(r, [
6161
\ 'root',
62-
\ '|- shallow',
63-
\ ' |+ alpha',
64-
\ ' |+ beta',
62+
\ '|- shallow/',
63+
\ ' |+ alpha/',
64+
\ ' |+ beta/',
6565
\ ' | gamma',
6666
\])
6767
End

0 commit comments

Comments
 (0)