@@ -5,14 +5,40 @@ function! fern#internal#buffer#replace(bufnr, content) abort
55 let modifiable_saved = getbufvar (a: bufnr , ' &modifiable' )
66 try
77 call setbufvar (a: bufnr , ' &modifiable' , 1 )
8- call setbufline (a: bufnr , 1 , a: content )
9- call deletebufline (a: bufnr , len (a: content ) + 1 , ' $' )
8+
9+ if g: fern #enable_textprop_support
10+ call s: replace_buffer_content (a: bufnr , a: content )
11+ else
12+ call setbufline (a: bufnr , 1 , a: content )
13+ call deletebufline (a: bufnr , len (a: content ) + 1 , ' $' )
14+ endif
1015 finally
1116 call setbufvar (a: bufnr , ' &modifiable' , modifiable_saved)
1217 call setbufvar (a: bufnr , ' &modified' , modified_saved)
1318 endtry
1419endfunction
1520
21+ " Replace buffer content with lines of text with (optional) text properties.
22+ function ! s: replace_buffer_content (bufnr , content) abort
23+ for lnum in range (len (a: content ))
24+ let line = a: content [lnum]
25+ let [text, props] = type (line ) is # v: t_dict
26+ \ ? [line .text, get (line , ' props' , [])]
27+ \ : [line , []]
28+
29+ call setbufline (a: bufnr , lnum + 1 , text)
30+
31+ if exists (' *prop_add' )
32+ for prop in props
33+ let prop.bufnr = a: bufnr
34+ call prop_add (lnum + 1 , prop.col , prop)
35+ endfor
36+ endif
37+ endfor
38+
39+ call deletebufline (a: bufnr , len (a: content ) + 1 , ' $' )
40+ endfunction
41+
1642function ! fern#internal#buffer#open (bufname , ... ) abort
1743 let options = extend ({
1844 \ ' opener' : ' edit' ,
0 commit comments