Add recently visited files in the list when using find file command
This commit is contained in:
parent
16e6a6db9d
commit
82dc76dd00
|
@ -55,17 +55,30 @@ command.add(nil, {
|
|||
end,
|
||||
|
||||
["core:find-file"] = function()
|
||||
local files = {}
|
||||
for _, item in pairs(core.project_files) do
|
||||
if item.type == "file" then
|
||||
table.insert(files, item.filename)
|
||||
end
|
||||
end
|
||||
core.command_view:enter("Open File From Project", function(text, item)
|
||||
text = item and item.text or text
|
||||
core.root_view:open_doc(core.open_doc(text))
|
||||
end, function(text)
|
||||
local files = {}
|
||||
for _, item in pairs(core.project_files) do
|
||||
if item.type == "file" then
|
||||
table.insert(files, item.filename)
|
||||
if text == "" then
|
||||
local recent_files = {}
|
||||
for i = 2, #core.visited_files do
|
||||
table.insert(recent_files, core.visited_files[i])
|
||||
end
|
||||
table.insert(recent_files, core.visited_files[1])
|
||||
local other_files = common.fuzzy_match(files, "")
|
||||
for i = 1, #other_files do
|
||||
table.insert(recent_files, other_files[i])
|
||||
end
|
||||
return recent_files
|
||||
else
|
||||
return common.fuzzy_match(files, text)
|
||||
end
|
||||
return common.fuzzy_match(files, text)
|
||||
end)
|
||||
end,
|
||||
|
||||
|
|
|
@ -114,6 +114,7 @@ function core.init()
|
|||
core.threads = setmetatable({}, { __mode = "k" })
|
||||
core.project_files = {}
|
||||
core.redraw = true
|
||||
core.visited_files = {}
|
||||
|
||||
core.root_view = RootView()
|
||||
core.command_view = CommandView()
|
||||
|
@ -225,9 +226,23 @@ function core.reload_module(name)
|
|||
end
|
||||
|
||||
|
||||
function core.set_visited(filename)
|
||||
for i = 1, #core.visited_files do
|
||||
if core.visited_files[i] == filename then
|
||||
table.remove(core.visited_files, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
table.insert(core.visited_files, 1, filename)
|
||||
end
|
||||
|
||||
|
||||
function core.set_active_view(view)
|
||||
assert(view, "Tried to set active view to nil")
|
||||
if view ~= core.active_view then
|
||||
if view.doc and view.doc.filename then
|
||||
core.set_visited(view.doc.filename)
|
||||
end
|
||||
core.last_active_view = core.active_view
|
||||
core.active_view = view
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue