Skip to content

Commit

Permalink
feat: sort Leet tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
kawre committed Feb 27, 2024
1 parent dde441f commit 72a0446
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
15 changes: 0 additions & 15 deletions lua/leetcode/command/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -540,55 +540,40 @@ cmd.commands = {
last_submit = { cmd.last_submit },
restore = { cmd.restore },
inject = { cmd.inject },

session = {
change = {
cmd.change_session,

_args = arguments.session_change,
},

create = {
cmd.create_session,

_args = arguments.session_create,
},

update = { cmd.update_sessions },
},

list = {
cmd.problems,

_args = arguments.list,
},

random = {
cmd.random_question,

_args = arguments.random,
},

desc = {
cmd.desc_toggle,

stats = { cmd.desc_toggle_stats },

toggle = { cmd.desc_toggle },
},

cookie = {
update = { cmd.cookie_prompt },
delete = { cmd.sign_out },
},

cache = {
update = { cmd.cache_update },
},

fix = {
cmd.fix,

_private = true,
},
}
Expand Down
3 changes: 3 additions & 0 deletions lua/leetcode/config/icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ local icons = {
notac = "󱎖",
todo = "",
},
caret = {
right = "",
},
}

icons.hl = {
Expand Down
15 changes: 13 additions & 2 deletions lua/leetcode/pickers/question-tabs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local t = require("leetcode.translator")
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local config = require("leetcode.config")
local icons = config.icons

local entry_display = require("telescope.pickers.entry_display")
local actions = require("telescope.actions")
Expand All @@ -22,7 +24,7 @@ local function display_current(entry)
local tabp = vim.api.nvim_get_current_tabpage()
if tabp ~= entry.tabpage then return unpack({ "", "" }) end

return { "", "" }
return { icons.caret.right, "leetcode_ref" }
end

local function display_difficulty(q)
Expand Down Expand Up @@ -75,7 +77,16 @@ local opts = require("telescope.themes").get_dropdown()
return {
pick = function()
local tabs = utils.question_tabs()
if vim.tbl_isempty(tabs) then return log.warn("No questions opened") end

if vim.tbl_isempty(tabs) then --
return log.warn("No questions opened")
end

table.sort(tabs, function(q1, q2)
local fid1, fid2 =
tonumber(q1.question.q.frontend_id), tonumber(q2.question.q.frontend_id)
return (fid1 and fid2) and fid1 < fid2 or fid1 ~= nil
end)

pickers
.new(opts, {
Expand Down

0 comments on commit 72a0446

Please sign in to comment.