@@ -56,12 +56,18 @@ enddef
5656
5757def GetFileSize (filename: string ): number
5858 var filesize = ' '
59+ # TODO : Using system () slow down significantly the opening and the file preview
5960 if filereadable (filename)
6061 if has (' win32' )
6162 filesize = system (' powershell -NoProfile -ExecutionPolicy Bypass -Command '
6263 .. $ ' "(Get-Item \"{filename}\").length"' )
64+ elseif has (' unix' ) && system (' uname' ) = ~ ' Darwin'
65+ filesize = system ($ ' stat -f %z {escape(filename, " ")}' )
66+ elseif has (' unix' )
67+ filesize = system ($ ' stat --format=%s {escape(filename, " ")}' )
6368 else
64- filesize = system ($ ' stat --format=%s {filename}' )
69+ utils.Echowarn ($ " Cannot determine the size of {filename}" )
70+ filesize = " -1"
6571 endif
6672 else
6773 utils.Echoerr ($ " File {filename} is not readable" )
@@ -614,13 +620,38 @@ export def PreviewPopup()
614620 if ! empty (IsLink ())
615621 # Search from the current cursor position to the end of line
616622 var saved_curpos = getcurpos ()
617- norm! f [l
618- var link_id = utils.GetTextObject (' i[' ).text
619- var link_name = b: markdown_extras_links [link_id]
623+
624+ # Find the closest between [ and (
625+ var symbol = ' '
626+ if searchpos (' [' , ' nW' ) == [0 , 0 ]
627+ symbol = ' ('
628+ elseif searchpos (' (' , ' nW' ) == [0 , 0 ]
629+ symbol = ' ['
630+ else
631+ symbol = utils.IsLess (searchpos (' [' , ' nW' ), searchpos (' (' , ' nW' ))
632+ ? ' ['
633+ : ' ('
634+ endif
635+
636+ exe $ " norm! f{symbol}l"
637+
638+ var link_name = ' '
639+ var link_id = ' '
640+ if symbol == ' ['
641+ b: markdown_extras_links = RefreshLinksDict ()
642+ link_id = utils.GetTextObject (' i[' ).text
643+ link_name = b: markdown_extras_links [link_id]
644+ else
645+ link_name = utils.GetTextObject (' i(' ).text
646+ endif
647+
648+ #
649+ #
620650 # TODO At the moment only .md files have syntax highlight .
621651 var refFiletype = $ ' {fnamemodify(link_name, ":e")}' == ' md'
622652 ? ' markdown'
623653 : ' text'
654+ # echom GetFileSize (link_name)
624655 if IsURL (link_name)
625656 || (filereadable (link_name) && GetFileSize (link_name) > 1000000 )
626657 previewText = [link_name]
0 commit comments