Use tilde expansion when running save-as command

This commit is contained in:
Francesco Abbate 2021-02-16 22:52:55 +01:00
parent 1decf67b64
commit 6369a7f760
3 changed files with 16 additions and 13 deletions

View File

@ -7,17 +7,9 @@ local LogView = require "core.logview"
local fullscreen = false
local function home_encode_list(paths)
local t = {}
for i = 1, #paths do
t[i] = common.home_encode(paths[i])
end
return t
end
local function suggest_directory(text)
text = common.home_expand(text)
return home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text))
return common.home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text))
end
command.add(nil, {
@ -95,7 +87,7 @@ command.add(nil, {
core.command_view:enter("Open File", function(text)
core.root_view:open_doc(core.open_doc(common.home_expand(text)))
end, function (text)
return home_encode_list(common.path_suggest(common.home_expand(text)))
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
end)
end,
@ -178,7 +170,7 @@ command.add(nil, {
end
end, function(text)
text = common.home_expand(text)
return home_encode_list(common.dir_list_suggest(text, dir_list))
return common.home_encode_list(common.dir_list_suggest(text, dir_list))
end)
end,
})

View File

@ -301,8 +301,10 @@ local commands = {
core.command_view:set_text(doc().filename)
end
core.command_view:enter("Save As", function(filename)
save(filename)
end, common.path_suggest)
save(common.home_expand(filename))
end, function (text)
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
end)
end,
["doc:save"] = function()

View File

@ -214,6 +214,15 @@ function common.home_encode(text)
end
function common.home_encode_list(paths)
local t = {}
for i = 1, #paths do
t[i] = common.home_encode(paths[i])
end
return t
end
function common.home_expand(text)
return HOME and text:gsub("^~", HOME) or text
end