From 4621ee2e7ff8a16d521e1409f022127905463915 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 17 May 2021 23:10:15 +0200 Subject: [PATCH] Accept relative filenames in command find-file Use name within project entries to resolve filenames in command find-file. --- data/core/commands/core.lua | 15 ++++++++++++--- data/core/init.lua | 7 +++++++ data/plugins/workspace.lua | 3 ++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 956455f3..2c107607 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -71,13 +71,22 @@ command.add(nil, { end local files = {} for dir, item in core.get_project_files() do + local dirname = common.basename(dir) if item.type == "file" then - table.insert(files, common.home_encode(dir .. PATHSEP .. item.filename)) + table.insert(files, dirname .. PATHSEP .. 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(common.home_expand(text))) + local filename = common.home_expand(item and item.text or text) + local dirname, basename = filename:match("(.-)[/\\](.+)") + for i = 1, #core.project_entries do + local dir = core.project_entries[i] + if dir.item.filename == dirname then + filename = dir.name .. PATHSEP .. basename + break + end + end + core.root_view:open_doc(core.open_doc(filename)) end, function(text) return common.fuzzy_match_with_recents(files, core.visited_files, text) end) diff --git a/data/core/init.lua b/data/core/init.lua index 55060a02..c67c8d51 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -764,6 +764,13 @@ end function core.set_visited(filename) + for i = 1, #core.project_entries do + local dir = core.project_entries[i] + if common.path_belongs_to(filename, dir.name) then + local dirpath = common.dirname(dir.name) + filename = filename:sub(#dirpath + 2) + end + end filename = common.home_encode(filename) for i = 1, #core.visited_files do if core.visited_files[i] == filename then diff --git a/data/plugins/workspace.lua b/data/plugins/workspace.lua index 9123c027..ac700c66 100644 --- a/data/plugins/workspace.lua +++ b/data/plugins/workspace.lua @@ -143,11 +143,12 @@ local function load_workspace() if active_view then core.set_active_view(active_view) end + core.project_entries = {} for _, entry in ipairs(workspace.project_entries) do if entry.type == "dir" then core.add_project_directory(entry.path) elseif entry.type == "dir" then - core.add_project_dfile(entry.path) + core.add_project_file(entry.path) end end system.chdir(workspace.working_dir)