@@ -1271,7 +1271,7 @@ function Previewer.buffer_or_file:do_syntax(entry)
12711271 end
12721272
12731273 -- filetype detect
1274- local did_filetype_detect
1274+ local did_filetype_detect = entry . filetype and true or false
12751275 local ft = entry .filetype or vim .filetype .match ({
12761276 buf = bufnr ,
12771277 filename = filepath ,
@@ -1303,20 +1303,14 @@ function Previewer.buffer_or_file:do_syntax(entry)
13031303 end )()
13041304
13051305 while true do
1306- local ts_success = ts_enabled and ts_attach (bufnr , ft )
1307- if ts_success then
1308- self :update_render_markdown ()
1309- break
1310- end
1311- if did_filetype_detect then
1312- vim .bo [bufnr ].syntax = ft
1313- break
1314- end
1306+ if ts_enabled and ts_attach (bufnr , ft ) then return end
1307+ if did_filetype_detect then break end
13151308 -- sometimes vim.filetype.match get a poor filetype (e.g. ft=text)
13161309 -- this should be a fallback we should detect it again from ftdetect/modeline
13171310 ft = filetype_detect (bufnr , filepath ) or ft
13181311 did_filetype_detect = true
13191312 end
1313+ vim .bo [bufnr ].syntax = ft
13201314end
13211315
13221316function Previewer .base :maybe_set_cursorline (win , pos )
@@ -1455,6 +1449,7 @@ function Previewer.buffer_or_file:preview_buf_post(entry, min_winopts)
14551449 local syntax = function ()
14561450 if self .syntax then
14571451 self :do_syntax (entry )
1452+ self :update_render_markdown ()
14581453 self :update_ts_context ()
14591454 self :attach_snacks_image_inline ()
14601455 end
0 commit comments