From 6807a8e29a3923f80b0296d787a9ed9efb344ac3 Mon Sep 17 00:00:00 2001 From: George Sokianos Date: Mon, 19 Feb 2024 22:51:41 +0000 Subject: [PATCH] s when opening projects or changing paths. --- README_Amiga.md | 2 ++ data/core/commands/core.lua | 2 +- data/core/common.lua | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README_Amiga.md b/README_Amiga.md index 19db0113..0da124bc 100644 --- a/README_Amiga.md +++ b/README_Amiga.md @@ -245,6 +245,8 @@ https://git.walkero.gr/walkero/lite-xl/issues the root of a partition or an assign path - Fixed an error with the codesets plugin, where an empty file could not be opened +- Improved the folder suggestions when opening projects or changing paths. + Now even the root folders of a partition are presented ## [2.1.2r1] - 2023-12-19 ### Added diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index cdf8d421..5113e9f4 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -185,7 +185,7 @@ command.add(nil, { local dirname = common.dirname(core.project_dir) local text if dirname then - text = common.home_encode(dirname) .. PATHSEP + text = common.basepath(common.home_encode(dirname)) end core.command_view:enter("Change Project Folder", { text = text, diff --git a/data/core/common.lua b/data/core/common.lua index 092f7960..7763ddcb 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -226,7 +226,13 @@ function common.path_suggest(text, root) if root and root:sub(-1) ~= PATHSEP then root = root .. PATHSEP end - local path, name = text:match("^(.-)([^"..PATHSEP.."]*)$") + local path, name + if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") then + path, name = text:match("^(.-)([^:"..PATHSEP.."]*)$") + else + path, name = text:match("^(.-)([^"..PATHSEP.."]*)$") + end + local clean_dotslash = false -- ignore root if path is absolute local is_absolute = common.is_absolute_path(text) @@ -279,7 +285,12 @@ end ---@param text string The input path. ---@return string[] function common.dir_path_suggest(text) - local path, name = text:match("^(.-)([^"..PATHSEP.."]*)$") + local path, name + if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") then + path, name = text:match("^(.-)([^:"..PATHSEP.."]*)$") + else + path, name = text:match("^(.-)([^"..PATHSEP.."]*)$") + end local files = system.list_dir(path == "" and "." or path) or {} local res = {} for _, file in ipairs(files) do @@ -298,7 +309,13 @@ end ---@param dir_list string[] A list of paths to filter. ---@return string[] function common.dir_list_suggest(text, dir_list) - local path, name = text:match("^(.-)([^"..PATHSEP.."]*)$") + local path, name + if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") then + path, name = text:match("^(.-)([^:"..PATHSEP.."]*)$") + else + path, name = text:match("^(.-)([^"..PATHSEP.."]*)$") + end + local res = {} for _, dir_path in ipairs(dir_list) do if dir_path:lower():find(text:lower(), nil, true) == 1 then @@ -484,6 +501,16 @@ end ---@param path string ---@return string|nil function common.dirname(path) + if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") then + local drive, relpath = path:match('^([%w%s]*:)(.+)') + if drive and relpath then + local dir = relpath:match("(.+)["..PATHSEP.."][^"..PATHSEP.."]+$") + if dir then + return drive .. dir + end + end + return path + end return path:match("(.+)["..PATHSEP.."][^"..PATHSEP.."]+$") end