Add HOME directory expansion also for open file command
This commit is contained in:
parent
4401f33c19
commit
9a12d47afd
|
@ -8,20 +8,15 @@ local LogView = require "core.logview"
|
||||||
local fullscreen = false
|
local fullscreen = false
|
||||||
|
|
||||||
local function home_encode_list(paths)
|
local function home_encode_list(paths)
|
||||||
if HOME then
|
local t = {}
|
||||||
local t = {}
|
for i = 1, #paths do
|
||||||
for i = 1, #paths do
|
t[i] = common.home_encode(paths[i])
|
||||||
t[i] = common.home_encode(paths[i])
|
|
||||||
end
|
|
||||||
return t
|
|
||||||
end
|
end
|
||||||
return paths
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
local function suggest_directory(text)
|
local function suggest_directory(text)
|
||||||
if HOME then
|
text = common.home_expand(text)
|
||||||
text = common.home_expand(text)
|
|
||||||
end
|
|
||||||
return home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text))
|
return home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -110,8 +105,10 @@ command.add(nil, {
|
||||||
|
|
||||||
["core:open-file"] = function()
|
["core:open-file"] = function()
|
||||||
core.command_view:enter("Open File", function(text)
|
core.command_view:enter("Open File", function(text)
|
||||||
core.root_view:open_doc(core.open_doc(text))
|
core.root_view:open_doc(core.open_doc(common.home_expand(text)))
|
||||||
end, common.path_suggest)
|
end, function (text)
|
||||||
|
return home_encode_list(common.path_suggest(common.home_expand(text)))
|
||||||
|
end)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-log"] = function()
|
["core:open-log"] = function()
|
||||||
|
|
|
@ -153,16 +153,18 @@ end
|
||||||
|
|
||||||
|
|
||||||
function common.home_encode(text)
|
function common.home_encode(text)
|
||||||
local n = #HOME
|
if HOME then
|
||||||
if text:sub(1, n) == HOME and text:sub(n + 1, n + 1):match("[/\\\\]") then
|
local n = #HOME
|
||||||
return "~" .. text:sub(n + 1)
|
if text:sub(1, n) == HOME and text:sub(n + 1, n + 1):match("[/\\\\]") then
|
||||||
|
return "~" .. text:sub(n + 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function common.home_expand(text)
|
function common.home_expand(text)
|
||||||
return text:gsub("^~", HOME)
|
return HOME and text:gsub("^~", HOME) or text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue