Accept relative filenames in command find-file
Use name within project entries to resolve filenames in command find-file.
This commit is contained in:
parent
6dd5743be8
commit
4621ee2e7f
|
@ -71,13 +71,22 @@ command.add(nil, {
|
||||||
end
|
end
|
||||||
local files = {}
|
local files = {}
|
||||||
for dir, item in core.get_project_files() do
|
for dir, item in core.get_project_files() do
|
||||||
|
local dirname = common.basename(dir)
|
||||||
if item.type == "file" then
|
if item.type == "file" then
|
||||||
table.insert(files, common.home_encode(dir .. PATHSEP .. item.filename))
|
table.insert(files, dirname .. PATHSEP .. item.filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
core.command_view:enter("Open File From Project", function(text, item)
|
core.command_view:enter("Open File From Project", function(text, item)
|
||||||
text = item and item.text or text
|
local filename = common.home_expand(item and item.text or text)
|
||||||
core.root_view:open_doc(core.open_doc(common.home_expand(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)
|
end, function(text)
|
||||||
return common.fuzzy_match_with_recents(files, core.visited_files, text)
|
return common.fuzzy_match_with_recents(files, core.visited_files, text)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -764,6 +764,13 @@ end
|
||||||
|
|
||||||
|
|
||||||
function core.set_visited(filename)
|
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)
|
filename = common.home_encode(filename)
|
||||||
for i = 1, #core.visited_files do
|
for i = 1, #core.visited_files do
|
||||||
if core.visited_files[i] == filename then
|
if core.visited_files[i] == filename then
|
||||||
|
|
|
@ -143,11 +143,12 @@ local function load_workspace()
|
||||||
if active_view then
|
if active_view then
|
||||||
core.set_active_view(active_view)
|
core.set_active_view(active_view)
|
||||||
end
|
end
|
||||||
|
core.project_entries = {}
|
||||||
for _, entry in ipairs(workspace.project_entries) do
|
for _, entry in ipairs(workspace.project_entries) do
|
||||||
if entry.type == "dir" then
|
if entry.type == "dir" then
|
||||||
core.add_project_directory(entry.path)
|
core.add_project_directory(entry.path)
|
||||||
elseif entry.type == "dir" then
|
elseif entry.type == "dir" then
|
||||||
core.add_project_dfile(entry.path)
|
core.add_project_file(entry.path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
system.chdir(workspace.working_dir)
|
system.chdir(workspace.working_dir)
|
||||||
|
|
Loading…
Reference in New Issue