Fix behavior when selecting project directories
This commit is contained in:
parent
e548a6adb9
commit
8d4ba0cb34
|
@ -80,22 +80,10 @@ command.add(nil, {
|
|||
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(common.home_expand(text)))
|
||||
end, function(text)
|
||||
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_with_recents(files, core.visited_files, text)
|
||||
end)
|
||||
end,
|
||||
|
||||
|
@ -140,8 +128,9 @@ command.add(nil, {
|
|||
end,
|
||||
|
||||
["core:change-project-folder"] = function()
|
||||
core.command_view:enter("Change Project Folder", function(text)
|
||||
text = system.absolute_path(common.home_expand(text))
|
||||
core.command_view:enter("Change Project Folder", function(text, item)
|
||||
text = system.absolute_path(common.home_expand(item and item.text or text))
|
||||
if text == core.project_dir then return end
|
||||
local path_stat = system.get_file_info(text)
|
||||
if not path_stat or path_stat.type ~= 'dir' then
|
||||
core.error("Cannot open folder %q", text)
|
||||
|
@ -154,8 +143,8 @@ command.add(nil, {
|
|||
end,
|
||||
|
||||
["core:open-project-folder"] = function()
|
||||
core.command_view:enter("Open Project", function(text)
|
||||
text = common.home_expand(text)
|
||||
core.command_view:enter("Open Project", function(text, item)
|
||||
text = common.home_expand(item and item.text or text)
|
||||
local path_stat = system.get_file_info(text)
|
||||
if not path_stat or path_stat.type ~= 'dir' then
|
||||
core.error("Cannot open folder %q", text)
|
||||
|
@ -188,9 +177,10 @@ command.add(nil, {
|
|||
for i = n, 2, -1 do
|
||||
dir_list[n - i + 1] = core.project_directories[i].name
|
||||
end
|
||||
core.command_view:enter("Remove Directory", function(text)
|
||||
core.command_view:enter("Remove Directory", function(text, item)
|
||||
text = item and item.text or text
|
||||
if not core.remove_project_directory(text) then
|
||||
core.error("No added directory %q to be removed", text)
|
||||
core.error("No directory %q to be removed", text)
|
||||
end
|
||||
end, function(text)
|
||||
text = common.home_expand(text)
|
||||
|
|
|
@ -82,6 +82,24 @@ function common.fuzzy_match(haystack, needle)
|
|||
end
|
||||
|
||||
|
||||
function common.fuzzy_match_with_recents(haystack, recents, needle)
|
||||
if needle == "" then
|
||||
local recents_ext = {}
|
||||
for i = 2, #recents do
|
||||
table.insert(recents_ext, recents[i])
|
||||
end
|
||||
table.insert(recents_ext, recents[1])
|
||||
local others = common.fuzzy_match(haystack, "")
|
||||
for i = 1, #others do
|
||||
table.insert(recents_ext, others[i])
|
||||
end
|
||||
return recents_ext
|
||||
else
|
||||
return fuzzy_match_items(haystack, needle)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function common.path_suggest(text)
|
||||
local path, name = text:match("^(.-)([^/\\]*)$")
|
||||
local files = system.list_dir(path == "" and "." or path) or {}
|
||||
|
|
Loading…
Reference in New Issue