@@ -1349,16 +1349,22 @@ function Previewer.buffer_or_file:set_cursor_hl(entry)
13491349 regex , reg )
13501350 end
13511351 if regex_start and regex_end then
1352- extmark = api .nvim_buf_set_extmark (buf , self .ns_previewer , lnum - 1 , regex_start + col - 1 ,
1353- { end_line = lnum - 1 , end_col = regex_end + col - 1 , hl_group = hls .search })
1352+ extmark = api .nvim_buf_set_extmark (buf , self .ns_previewer , lnum - 1 , regex_start + col - 1 , {
1353+ end_line = lnum - 1 ,
1354+ end_col = regex_end + col - 1 ,
1355+ hl_group = entry .hlgroup or hls .search
1356+ })
13541357 end
13551358 end
13561359
13571360 -- Fallback to cursor hl, only if column exists
13581361 if not extmark and hls .cursor and entry .col then
13591362 local end_lnum , end_col = entry .end_line or lnum , entry .end_col or col + 1
1360- api .nvim_buf_set_extmark (buf , self .ns_previewer , lnum - 1 , col - 1 ,
1361- { end_line = end_lnum - 1 , end_col = math.max (1 , end_col ) - 1 , hl_group = hls .cursor })
1363+ api .nvim_buf_set_extmark (buf , self .ns_previewer , lnum - 1 , col - 1 , {
1364+ end_line = end_lnum - 1 ,
1365+ end_col = math.max (1 , end_col ) - 1 ,
1366+ hl_group = entry .hlgroup or hls .cursor ,
1367+ })
13621368 end
13631369
13641370 utils .zz ()
@@ -1437,11 +1443,6 @@ end
14371443--- @field super fzf-lua.previewer.BufferOrFile
14381444Previewer .help_tags = Previewer .buffer_or_file :extend ()
14391445
1440- function Previewer .help_tags :new (o , opts )
1441- Previewer .help_tags .super .new (self , o , opts )
1442- return self
1443- end
1444-
14451446--- @diagnostic disable-next-line : unused
14461447function Previewer .help_tags :parse_entry (entry_str )
14471448 local tag = entry_str :match (" ^[^%s]+" )
@@ -1498,9 +1499,9 @@ function Previewer.help_tags:set_cursor_hl(entry)
14981499 end )
14991500end
15001501
1501- --- @class fzf-lua.previewer.ManPages : fzf-lua.previewer.Builtin , {}
1502- --- @field super fzf-lua.previewer.Builtin ,{}
1503- Previewer .man_pages = Previewer .base :extend ()
1502+ --- @class fzf-lua.previewer.ManPages : fzf-lua.previewer.BufferOrFile , {}
1503+ --- @field super fzf-lua.previewer.BufferOrFile ,{}
1504+ Previewer .man_pages = Previewer .buffer_or_file :extend ()
15041505
15051506--- @diagnostic disable-next-line : unused
15061507--- @return boolean
@@ -1520,40 +1521,24 @@ end
15201521
15211522function Previewer .man_pages :new (o , opts )
15221523 Previewer .man_pages .super .new (self , o , opts )
1523- self .filetype = " man"
15241524 self .cmd = o .cmd or " man -c %s | col -bx"
15251525 self .cmd = type (self .cmd ) == " function" and self .cmd () or self .cmd
15261526 return self
15271527end
15281528
15291529--- @diagnostic disable-next-line : unused
15301530function Previewer .man_pages :parse_entry (entry_str )
1531- return require (" fzf-lua.providers.manpages" ).manpage_sh_arg (entry_str )
1532- end
1533-
1534- function Previewer .man_pages :populate_preview_buf (entry_str )
1535- local entry = self :parse_entry (entry_str )
1536- --- @type string | string[]
1537- local cmd = self .cmd :format (entry )
1531+ local entry = require (" fzf-lua.providers.manpages" ).manpage_sh_arg (entry_str )
1532+ local cmd = self .cmd :format (entry ) --- @type string | string[]
15381533 if type (cmd ) == " string" then cmd = { " sh" , " -c" , cmd } end
15391534 local output , _ = utils .io_systemlist (cmd )
1540- local tmpbuf = self :get_tmp_buffer ()
1541- -- api.nvim_buf_set_option(tmpbuf, 'modifiable', true)
1542- api .nvim_buf_set_lines (tmpbuf , 0 , - 1 , false , output )
1543- vim .bo [tmpbuf ].filetype = self .filetype
1544- self :set_preview_buf (tmpbuf )
1545- self .win :update_preview_scrollbar ()
1535+ return { filetype = " man" , content = output }
15461536end
15471537
15481538--- @class fzf-lua.previewer.Marks : fzf-lua.previewer.BufferOrFile , {}
15491539--- @field super fzf-lua.previewer.BufferOrFile ,{}
15501540Previewer .marks = Previewer .buffer_or_file :extend ()
15511541
1552- function Previewer .marks :new (o , opts )
1553- Previewer .marks .super .new (self , o , opts )
1554- return self
1555- end
1556-
15571542function Previewer .marks :parse_entry (entry_str )
15581543 local bufnr = nil
15591544 local mark , lnum , col , filepath = entry_str :match (" ([^ ])%s+(%d+)%s+(%d+)%s+(.*)" )
@@ -1593,11 +1578,6 @@ end
15931578--- @field super fzf-lua.previewer.BufferOrFile ,{}
15941579Previewer .jumps = Previewer .buffer_or_file :extend ()
15951580
1596- function Previewer .jumps :new (o , opts )
1597- Previewer .jumps .super .new (self , o , opts )
1598- return self
1599- end
1600-
16011581function Previewer .jumps :parse_entry (entry_str )
16021582 local bufnr = nil
16031583 local _ , lnum , col0 , filepath = entry_str :match (" (%d+)%s+(%d+)%s+(%d+)%s+(.*)" )
@@ -1626,11 +1606,6 @@ end
16261606--- @field super fzf-lua.previewer.BufferOrFile ,{}
16271607Previewer .tags = Previewer .buffer_or_file :extend ()
16281608
1629- function Previewer .tags :new (o , opts )
1630- Previewer .tags .super .new (self , o , opts )
1631- return self
1632- end
1633-
16341609--- @param entry fzf-lua.buffer_or_file.Entry
16351610function Previewer .tags :set_cursor_hl (entry )
16361611 if tonumber (entry .line ) and entry .line > 0 then
@@ -1653,9 +1628,9 @@ function Previewer.tags:set_cursor_hl(entry)
16531628 end )
16541629end
16551630
1656- --- @class fzf-lua.previewer.Hightlights : fzf-lua.previewer.Builtin , {}
1631+ --- @class fzf-lua.previewer.Hightlights : fzf-lua.previewer.BufferOrFile , {}
16571632--- @field super fzf-lua.previewer.Builtin ,{}
1658- Previewer .highlights = Previewer .base :extend ()
1633+ Previewer .highlights = Previewer .buffer_or_file :extend ()
16591634
16601635--- @diagnostic disable-next-line : unused
16611636--- @return boolean
@@ -1671,24 +1646,9 @@ function Previewer.highlights:gen_winopts()
16711646 return vim .tbl_extend (" keep" , winopts , self .winopts )
16721647end
16731648
1674- function Previewer .highlights :new (o , opts )
1675- Previewer .highlights .super .new (self , o , opts )
1676- self .ns_previewer = api .nvim_create_namespace (" fzf-lua.previewer.hl" )
1677- return self
1678- end
1679-
1680- function Previewer .highlights :populate_preview_buf (entry_str )
1681- -- Preview buffer isn't set on init and after fzf's zero event
1682- if not self .preview_bufnr then
1683- local buf = self :get_tmp_buffer ()
1684- vim .bo [buf ].ft = " lua"
1685- ts_attach (buf , " lua" )
1686- self :set_preview_buf (buf )
1687- end
1688-
1649+ --- @diagnostic disable-next-line : unused
1650+ function Previewer .highlights :parse_entry (entry_str )
16891651 local serpent = require " fzf-lua.lib.serpent"
1690- local buf = self .preview_bufnr
1691- if not buf then return end
16921652 local hl = entry_str :match (" ^[^%s]+" )
16931653 local hlgroup = hl
16941654 local lines = {}
@@ -1701,21 +1661,20 @@ function Previewer.highlights:populate_preview_buf(entry_str)
17011661 until not hl
17021662 table.insert (lines , [[ ]] )
17031663 table.insert (lines , [[ "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"]] )
1704- api .nvim_buf_set_lines (buf , 0 , - 1 , false , lines )
1705- self .win :update_preview_title (hl )
1706- self .win :update_preview_scrollbar ()
1707- api .nvim_win_call (self .win .preview_winid , function ()
1708- if self .match_id then
1709- pcall (fn .matchdelete , self .match_id )
1710- self .match_id = nil
1711- end
1712- self .match_id = fn .matchaddpos (hlgroup , { { # lines } }, self .ns_previewer )
1713- end )
1664+ return {
1665+ filetype = " lua" ,
1666+ title = hl ,
1667+ content = lines ,
1668+ line = # lines ,
1669+ col = 1 ,
1670+ end_col = 1 + # lines [# lines ],
1671+ hlgroup = hlgroup
1672+ }
17141673end
17151674
1716- --- @class fzf-lua.previewer.Quickfix : fzf-lua.previewer.Builtin , {}
1675+ --- @class fzf-lua.previewer.Quickfix : fzf-lua.previewer.BufferOrFile , {}
17171676--- @field super fzf-lua.previewer.Builtin ,{}
1718- Previewer .quickfix = Previewer .base :extend ()
1677+ Previewer .quickfix = Previewer .buffer_or_file :extend ()
17191678
17201679--- @diagnostic disable-next-line : unused
17211680--- @return boolean
@@ -1732,52 +1691,31 @@ function Previewer.quickfix:gen_winopts()
17321691 return vim .tbl_extend (" keep" , winopts , self .winopts )
17331692end
17341693
1735- function Previewer .quickfix :new (o , opts )
1736- Previewer .quickfix .super .new (self , o , opts )
1737- return self
1738- end
1739-
1740- function Previewer .quickfix :close ()
1741- Previewer .quickfix .super .close (self )
1742- end
1743-
1744- function Previewer .quickfix :populate_preview_buf (entry_str )
1694+ function Previewer .quickfix :parse_entry (entry_str )
17451695 local nr = entry_str :match (" [(%d+)]" )
1746- if not nr or tonumber (nr ) <= 0 then
1747- return
1748- end
1749-
1750- local qf_list = self .opts .is_loclist
1751- and fn .getloclist (self .win .src_winid , { all = " " , nr = tonumber (nr ) })
1696+ if not nr or tonumber (nr ) <= 0 then return {} end
1697+ local qf_list = self .opts .is_loclist and
1698+ fn .getloclist (self .win .src_winid , { all = " " , nr = tonumber (nr ) })
17521699 or fn .getqflist ({ all = " " , nr = tonumber (nr ) })
1753- if utils .tbl_isempty (qf_list ) or utils .tbl_isempty (qf_list .items ) then
1754- return
1755- end
1756-
1700+ if utils .tbl_isempty (qf_list ) or utils .tbl_isempty (qf_list .items ) then return {} end
17571701 local lines = {}
17581702 for _ , e in ipairs (qf_list .items ) do
17591703 table.insert (lines , string.format (" %s|%d col %d|%s" ,
17601704 path .HOME_to_tilde (path .relative_to (
17611705 api .nvim_buf_get_name (e .bufnr ), utils .cwd ())),
17621706 e .lnum , e .col , e .text ))
17631707 end
1764- self .tmpbuf = self :get_tmp_buffer ()
1765- api .nvim_buf_set_lines (self .tmpbuf , 0 , - 1 , false , lines )
1766- vim .bo [self .tmpbuf ].filetype = " qf"
1767- self :set_preview_buf (self .tmpbuf )
1768- self .win :update_preview_title (string.format (" %s: %s " , nr , qf_list .title ))
1769- self .win :update_preview_scrollbar ()
1708+ return {
1709+ title = string.format (" %s: %s " , nr , qf_list .title ),
1710+ filetype = " qf" ,
1711+ content = lines ,
1712+ }
17701713end
17711714
17721715--- @class fzf-lua.previewer.Autocmds : fzf-lua.previewer.BufferOrFile , {}
17731716--- @field super fzf-lua.previewer.BufferOrFile ,{}
17741717Previewer .autocmds = Previewer .buffer_or_file :extend ()
17751718
1776- function Previewer .autocmds :new (o , opts )
1777- Previewer .autocmds .super .new (self , o , opts )
1778- return self
1779- end
1780-
17811719function Previewer .autocmds :gen_winopts ()
17821720 if not self ._is_vimL_command then
17831721 return self .winopts
@@ -1791,62 +1729,34 @@ function Previewer.autocmds:gen_winopts()
17911729 return vim .tbl_extend (" keep" , winopts , self .winopts )
17921730end
17931731
1794- function Previewer .autocmds :populate_preview_buf (entry_str )
1795- if not self .win or not self .win :validate_preview () then return end
1796- local entry = self :parse_entry (entry_str )
1797- if utils .tbl_isempty (entry ) then return end
1798- self ._is_vimL_command = false
1799- if entry .path == " <none>" then
1800- self ._is_vimL_command = true
1801- entry .path = entry_str :match (" [^:|]+│" )
1802- local viml = assert (entry_str :match (" [^│]+$" ))
1803- local lines = vim .split (viml , " \n " )
1804- local tmpbuf = self :get_tmp_buffer ()
1805- api .nvim_buf_set_lines (tmpbuf , 0 , - 1 , false , lines )
1806- vim .bo [tmpbuf ].filetype = " vim"
1807- self :set_preview_buf (tmpbuf )
1808- self :preview_buf_post (entry )
1809- else
1810- self .super .populate_preview_buf (self , entry_str )
1732+ function Previewer .autocmds :parse_entry (entry_str )
1733+ local entry = self .super :parse_entry (entry_str )
1734+ if not entry .path or entry .path :sub (- 6 ) ~= " <none>" then
1735+ self ._is_vimL_command = false
1736+ return entry
18111737 end
1738+ self ._is_vimL_command = true
1739+ return {
1740+ path = entry_str :match (" [^:|]+│" ),
1741+ filetype = " vim" ,
1742+ content = vim .split (assert (entry_str :match (" [^│]+$" )), " \n " )
1743+ }
18121744end
18131745
18141746--- @class fzf-lua.previewer.Keymaps : fzf-lua.previewer.BufferOrFile , {}
18151747--- @field super fzf-lua.previewer.BufferOrFile ,{}
18161748Previewer .keymaps = Previewer .buffer_or_file :extend ()
18171749
1818- function Previewer .autocmds :keymaps (o , opts )
1819- Previewer .autocmds .super .new (self , o , opts )
1820- return self
1821- end
1822-
18231750--- @param entry_str string
1824- --- @return fzf-lua.path.Entry | fzf-lua.keymap .Entry
1751+ --- @return fzf-lua.buffer_or_file .Entry
18251752function Previewer .keymaps :parse_entry (entry_str )
1826- return path .keymap_to_entry (entry_str , self .opts )
1827- end
1828-
1829- function Previewer .keymaps :populate_preview_buf (entry_str )
1830- if not self .win or not self .win :validate_preview () then return end
1831- local entry = self :parse_entry (entry_str )
1832- if entry .vmap then
1833- -- keymap is vimL, there is no source file info
1834- -- so we display the vimL code instead
1835- local vmap = assert (entry .vmap :match (" [^%s]+$" ))
1836- local lines = utils .strsplit (vmap , " \n " )
1837- local tmpbuf = self :get_tmp_buffer ()
1838- api .nvim_buf_set_lines (tmpbuf , 0 , - 1 , false , lines )
1839- vim .bo [tmpbuf ].filetype = " vim"
1840- self :set_preview_buf (tmpbuf )
1841- --- @diagnostic disable-next-line : assign-type-mismatch
1842- local title_fnamemodify = self .title_fnamemodify
1843- self .title_fnamemodify = nil
1844- -- hack entry.uri for title display
1845- self :preview_buf_post ({ uri = string.format (" %s:%s" , entry .mode , entry .key ) })
1846- self .title_fnamemodify = title_fnamemodify
1847- return
1848- end
1849- Previewer .autocmds .super .populate_preview_buf (self , entry_str )
1753+ local entry = path .keymap_to_entry (entry_str , self .opts )
1754+ if not entry .vmap then return entry end
1755+ return {
1756+ filetype = " vim" ,
1757+ title = string.format (" %s:%s" , entry .mode , entry .key ),
1758+ content = utils .strsplit (assert (entry .vmap :match (" [^%s]+$" )), " \n " ),
1759+ }
18501760end
18511761
18521762--- @class fzf-lua.previewer.NvimOptions : fzf-lua.previewer.BufferOrFile , {}
0 commit comments