@@ -82,24 +82,20 @@ local function format_repository_info(repo, compact)
8282 return table.concat (parts , ' ' )
8383end
8484
85- local State = {}
86- State .state = {
87- all = function ()
88- State .encode = function (p ) return format_repository_info (p ) end
89- end ,
90- compat = function ()
91- State .encode = function (p ) return format_repository_info (p , true ) end
92- end ,
93- }
94- State .cycle = function ()
95- State .key = next (State .state , State .key )
96- if not State .key then State .key = next (State .state , State .key ) end
97- State .state [State .key ]()
85+ -- format_repository_info
86+ local state = require (' fzf-lua-extra.state' ).new ()
87+ state :put (' fmt' , ' detail' , function (p ) return format_repository_info (p ) end )
88+ state :put (' fmt' , ' compat' , function (p ) return format_repository_info (p , true ) end )
89+ local sort_by_stars = function (a , b )
90+ return a .stars > b .stars or (a .stars == b .stars and a .issues > b .issues )
91+ end
92+ local sort_by_issues = function (a , b )
93+ return a .issues > b .issues or (a .issues == b .issues and a .stars > b .stars )
9894end
9995
100- --- @return function , function
101- State . get = function () return State . filter , State . encode end
102- State . cycle ( )
96+ state : put ( ' sort ' , ' no_sort ' , false )
97+ state : put ( ' sort ' , ' stars ' , sort_by_stars )
98+ state : put ( ' sort ' , ' issues ' , sort_by_issues )
10399
104100--- @class fle.config.Store : fzf-lua.config.Base
105101local __DEFAULT__ = {
@@ -120,6 +116,7 @@ local __DEFAULT__ = {
120116 items = {},
121117 },
122118 fzf_opts = {
119+ [' --no-sort' ] = true ,
123120 [' --delimiter' ] = ' \t ' ,
124121 [' --with-nth' ] = ' 2..' ,
125122 [' --no-hscroll' ] = true ,
@@ -153,7 +150,8 @@ local __DEFAULT__ = {
153150 [' ctrl-r' ] = p_do (
154151 function (p ) require (' lazy.core.loader' )[p ._ and p ._ .loaded and ' reload' or ' load' ](p ) end
155152 ),
156- [' ctrl-g' ] = { fn = State .cycle , reload = true },
153+ [' ctrl-g' ] = { fn = function () state :cycle (' fmt' ) end , reload = true },
154+ [' ctrl-s' ] = { fn = function () state :cycle (' sort' ) end , reload = true },
157155 },
158156}
159157
@@ -217,12 +215,15 @@ return function(opts)
217215 { cache_path = utils .path (' store.json' ), cache_invalid = opts .cache_invalid }
218216 ).stdout or ' '
219217 )
218+ local fmt = state :get (' fmt' )
219+ local sort = state :get (' sort' )
220220 local items = db .items
221+ -- TODO: maybe we also need "toggle-sort"
222+ if sort then table.sort (items , sort ) end
221223 opts .previewer .items = opts .previewer .items or {}
222224 for _ , item in ipairs (items ) do
223225 opts .previewer .items [item .full_name ] = item
224- local filter , encode = State .get ()
225- if not filter or filter (item ) then cb (encode (item )) end
226+ cb (fmt (item ))
226227 end
227228 cb (nil )
228229 end )
0 commit comments