@@ -314,46 +314,48 @@ function Preview:setBuffer(bufnr)
314314 local eventignore = vim .opt .eventignore
315315 vim .opt .eventignore :append (" BufEnter,BufWinEnter" )
316316
317- if self .config .use_image_nvim and try_load_image_nvim_buf (self .winid , bufnr ) then
318- -- calling the try method twice should be okay here, image.nvim should cache the image and displaying the image takes
319- -- really long anyways
320- vim .api .nvim_win_set_buf (self .winid , bufnr )
321- try_load_image_nvim_buf (self .winid , bufnr )
322- goto finally
323- end
324-
325- if self .config .use_float then
326- -- Workaround until https://github.com/neovim/neovim/issues/24973 is resolved or maybe 'previewpopup' comes in?
327- vim .fn .bufload (bufnr )
328- local lines = vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false )
329- vim .api .nvim_buf_set_lines (self .bufnr , 0 , - 1 , false , lines )
330- vim .api .nvim_win_set_buf (self .winid , self .bufnr )
331- -- I'm not sure why float windows won't show numbers without this
332- vim .wo [self .winid ].number = true
333-
334- -- code below is from mini.pick
335- -- only starts treesitter parser if the filetype is matching
336- local ft = vim .bo [bufnr ].filetype
337- local bufsize = get_bufsize (bufnr )
338- if bufsize > 1024 * 1024 or bufsize > 1000 * # lines then
339- goto finally
340- end
341- local has_lang , lang = pcall (vim .treesitter .language .get_lang , ft )
342- lang = has_lang and lang or ft
343- local has_parser , parser = pcall (vim .treesitter .get_parser , self .bufnr , lang , { error = false })
344- has_parser = has_parser and parser ~= nil
345- if has_parser then
346- has_parser = pcall (vim .treesitter .start , self .bufnr , lang )
317+ repeat
318+ if self .config .use_image_nvim and try_load_image_nvim_buf (self .winid , bufnr ) then
319+ -- calling the try method twice should be okay here, image.nvim should cache the image and displaying the image takes
320+ -- really long anyways
321+ vim .api .nvim_win_set_buf (self .winid , bufnr )
322+ try_load_image_nvim_buf (self .winid , bufnr )
323+ break -- goto end
347324 end
348- if not has_parser then
349- vim .bo [self .bufnr ].syntax = ft
325+
326+ if self .config .use_float then
327+ -- Workaround until https://github.com/neovim/neovim/issues/24973 is resolved or maybe 'previewpopup' comes in?
328+ vim .fn .bufload (bufnr )
329+ local lines = vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false )
330+ vim .api .nvim_buf_set_lines (self .bufnr , 0 , - 1 , false , lines )
331+ vim .api .nvim_win_set_buf (self .winid , self .bufnr )
332+ -- I'm not sure why float windows won't show numbers without this
333+ vim .wo [self .winid ].number = true
334+
335+ -- code below is from mini.pick
336+ -- only starts treesitter parser if the filetype is matching
337+ local ft = vim .bo [bufnr ].filetype
338+ local bufsize = get_bufsize (bufnr )
339+ if bufsize > 1024 * 1024 or bufsize > 1000 * # lines then
340+ break -- goto end
341+ end
342+ local has_lang , lang = pcall (vim .treesitter .language .get_lang , ft )
343+ lang = has_lang and lang or ft
344+ local has_parser , parser =
345+ pcall (vim .treesitter .get_parser , self .bufnr , lang , { error = false })
346+ has_parser = has_parser and parser ~= nil
347+ if has_parser then
348+ has_parser = pcall (vim .treesitter .start , self .bufnr , lang )
349+ end
350+ if not has_parser then
351+ vim .bo [self .bufnr ].syntax = ft
352+ end
353+ else
354+ vim .api .nvim_win_set_buf (self .winid , bufnr )
355+ self .bufnr = bufnr
350356 end
351- else
352- vim .api .nvim_win_set_buf (self .winid , bufnr )
353- self .bufnr = bufnr
354- end
355357
356- :: finally ::
358+ until true
357359 vim .opt .eventignore = eventignore
358360end
359361
@@ -387,28 +389,15 @@ function Preview:highlight_preview_range()
387389 end_pos = start_pos
388390 end
389391
390- local highlight = function (line , col_start , col_end )
391- vim .api .nvim_buf_add_highlight (
392- self .bufnr ,
393- neo_tree_preview_namespace ,
394- highlights .PREVIEW ,
395- line ,
396- col_start ,
397- col_end
398- )
399- end
400-
401392 local start_line , end_line = start_pos [1 ], end_pos [1 ]
402393 local start_col , end_col = start_pos [2 ], end_pos [2 ]
403- if start_line == end_line then
404- highlight (start_line , start_col , end_col )
405- else
406- highlight (start_line , start_col , - 1 )
407- for line = start_line + 1 , end_line - 1 do
408- highlight (line , 0 , - 1 )
409- end
410- highlight (end_line , 0 , end_col )
411- end
394+ vim .api .nvim_buf_set_extmark (self .bufnr , neo_tree_preview_namespace , start_line , start_col , {
395+ hl_group = highlights .PREVIEW ,
396+ end_row = end_line ,
397+ end_col = end_col ,
398+ -- priority = priority,
399+ strict = false ,
400+ })
412401end
413402
414403--- Clear the preview highlight in the buffer currently in the preview window.
0 commit comments