From 82231dbc98617ba364dd29f7ec3eafc9362b18e8 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 13 May 2021 14:57:55 +0200 Subject: [PATCH] Fix a few more things about filenames --- data/core/commands/core.lua | 3 +-- data/core/commands/doc.lua | 5 +---- data/core/init.lua | 8 ++++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 3c2bdb12..1a2c3413 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -72,8 +72,7 @@ command.add(nil, { local files = {} for dir, item in core.get_project_files() do if item.type == "file" then - local path = (dir == core.project_dir and "" or dir .. PATHSEP) - table.insert(files, common.home_encode(path .. item.filename)) + table.insert(files, common.home_encode(dir .. PATHSEP .. item.filename)) end end core.command_view:enter("Open File From Project", function(text, item) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 592fc9fe..bb3c9dab 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -41,10 +41,7 @@ end local function save(filename) - if filename then - filename = core.normalize_to_working_dir(filename) - end - doc():save(filename) + doc():save(filename and core.normalize_to_working_dir(filename)) local saved_filename = doc().filename core.on_doc_save(saved_filename) core.log("Saved \"%s\"", saved_filename) diff --git a/data/core/init.lua b/data/core/init.lua index b0155fc3..be4bdffc 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -745,6 +745,7 @@ end function core.set_visited(filename) + filename = common.home_encode(filename) for i = 1, #core.visited_files do if core.visited_files[i] == filename then table.remove(core.visited_files, i) @@ -798,16 +799,15 @@ function core.pop_clip_rect() renderer.set_clip_rect(x, y, w, h) end --- FIXME: update comment -- The function below works like system.absolute_path except it -- doesn't fail if the file does not exist. We consider that the --- current dir is core.project_dir so relative filename are considered --- to be in core.project_dir. +-- current dir is core.working_dir so relative filename are considered +-- to be in core.working_dir. -- Please note that .. or . in the filename are not taken into account. -- This function should get only filenames normalized using -- common.normalize_path function. function core.working_dir_absolute_path(filename) - if filename:match('^%a:\\') or filename:find('/', 1, true) then + if filename:match('^%a:\\') or filename:find('/', 1, true) == 1 then return filename else return core.working_dir .. PATHSEP .. filename