From 9a12d47afd031fdb328a6eccb44b5ce79b6c5388 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 20 Dec 2020 00:31:49 +0100 Subject: [PATCH] Add HOME directory expansion also for open file command --- data/core/commands/core.lua | 21 +++++++++------------ data/core/common.lua | 10 ++++++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 6457601e..3ce3cdfc 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -8,20 +8,15 @@ local LogView = require "core.logview" local fullscreen = false local function home_encode_list(paths) - if HOME then - local t = {} - for i = 1, #paths do - t[i] = common.home_encode(paths[i]) - end - return t + local t = {} + for i = 1, #paths do + t[i] = common.home_encode(paths[i]) end - return paths + return t end local function suggest_directory(text) - if HOME then - text = common.home_expand(text) - end + text = common.home_expand(text) return home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text)) end @@ -110,8 +105,10 @@ command.add(nil, { ["core:open-file"] = function() core.command_view:enter("Open File", function(text) - core.root_view:open_doc(core.open_doc(text)) - end, common.path_suggest) + 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))) + end) end, ["core:open-log"] = function() diff --git a/data/core/common.lua b/data/core/common.lua index eabfeedd..61ab355d 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -153,16 +153,18 @@ end function common.home_encode(text) - local n = #HOME - if text:sub(1, n) == HOME and text:sub(n + 1, n + 1):match("[/\\\\]") then - return "~" .. text:sub(n + 1) + if HOME then + local n = #HOME + if text:sub(1, n) == HOME and text:sub(n + 1, n + 1):match("[/\\\\]") then + return "~" .. text:sub(n + 1) + end end return text end function common.home_expand(text) - return text:gsub("^~", HOME) + return HOME and text:gsub("^~", HOME) or text end