From 3cc4cd1adab62411f5666f71c1df13d45c4c1557 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 05:09:26 -0700 Subject: [PATCH 01/62] Fix error when opening root directory --- data/core/common.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/core/common.lua b/data/core/common.lua index 3093a36d..9f3102bb 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -276,6 +276,7 @@ end function common.normalize_path(filename) + if not filename then return end if PATHSEP == '\\' then filename = filename:gsub('[/\\]', '\\') local drive, rem = filename:match('^([a-zA-Z])(:.*)') @@ -290,7 +291,8 @@ function common.normalize_path(filename) table.insert(accu, part) end end - return table.concat(accu, PATHSEP) + local npath = table.concat(accu, PATHSEP) + return npath == "" and PATHSEP or npath end From 368ffca40ab2746f7eb4896bbfa63a428e8cce1f Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 05:10:00 -0700 Subject: [PATCH 02/62] Fix macOS minimum system version in info.plist --- resources/macos/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/macos/Info.plist b/resources/macos/Info.plist index 70d49a02..d465479c 100644 --- a/resources/macos/Info.plist +++ b/resources/macos/Info.plist @@ -14,7 +14,7 @@ APPL NSHighResolutionCapable - MinimumOSVersion10.13 + LSMinimumSystemVersion10.11 NSDocumentsFolderUsageDescriptionTo access, edit and index your projects. NSDesktopFolderUsageDescriptionTo access, edit and index your projects. NSDownloadsFolderUsageDescriptionTo access, edit and index your projects. From 28e8a98ffc27d0f0c7342e5250ea19ba02d575ee Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 05:21:45 -0700 Subject: [PATCH 03/62] Fix error in change-project-folder command --- data/core/commands/core.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 7ac36976..215ff654 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -148,7 +148,9 @@ command.add(nil, { ["core:change-project-folder"] = function() local dirname = common.dirname(core.project_dir) - core.command_view:set_text(common.home_encode(dirname) .. PATHSEP) + if dirname then + core.command_view:set_text(common.home_encode(dirname) .. PATHSEP) + end core.command_view:enter("Change Project Folder", function(text, item) text = system.absolute_path(common.home_expand(item and item.text or text)) if text == core.project_dir then return end From afaf0a718d634fb786285370fa4b2f005f17c9f6 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Sun, 22 Aug 2021 19:29:21 +0800 Subject: [PATCH 04/62] improve logview The logview is now less cluttered. The filename and stack trace (if any) is hidden by default. The user can click on the log entry to expand it. --- data/core/logview.lua | 146 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 131 insertions(+), 15 deletions(-) diff --git a/data/core/logview.lua b/data/core/logview.lua index b731df3c..b81e8efe 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -1,8 +1,37 @@ local core = require "core" +local common = require "core.common" local style = require "core.style" local View = require "core.view" +local function lines(text) + if text == "" then return 0 end + local l = 1 + for _ in string.gmatch(text, "\n") do + l = l + 1 + end + return l +end + + +local item_height_result = {} + + +local function get_item_height(item) + local h = item_height_result[item] + if not h then + h = {} + local l = 1 + lines(item.text) + lines(item.info or "") + h.normal = style.font:get_height() + style.padding.y + h.expanded = l * style.font:get_height() + style.padding.y + h.current = h.normal + h.target = h.current + item_height_result[item] = h + end + return h +end + + local LogView = View:extend() LogView.context = "session" @@ -10,6 +39,7 @@ LogView.context = "session" function LogView:new() LogView.super.new(self) self.last_item = core.log_items[#core.log_items] + self.expanding = {} self.scrollable = true self.yoffset = 0 end @@ -20,6 +50,55 @@ function LogView:get_name() end +local function is_expanded(item) + local item_height = get_item_height(item) + return item_height.target == item_height.expanded +end + + +function LogView:expand_item(item) + item = get_item_height(item) + item.target = item.target == item.expanded and item.normal or item.expanded + table.insert(self.expanding, item) +end + + +function LogView:each_item() + local x, y = self:get_content_offset() + y = y + style.padding.y + self.yoffset + return coroutine.wrap(function() + for i = #core.log_items, 1, -1 do + local item = core.log_items[i] + local h = get_item_height(item).current + coroutine.yield(i, item, x, y, self.size.x, h) + y = y + h + end + end) +end + + +function LogView:on_mouse_moved(px, py, ...) + LogView.super.on_mouse_moved(self, px, py, ...) + local hovered = false + for _, item, x, y, w, h in self:each_item() do + if px >= x and py >= y and px < x + w and py < y + h then + hovered = true + self.hovered_item = item + break + end + end + if not hovered then self.hovered_item = nil end +end + + +function LogView:on_mouse_pressed(button, mx, my, clicks) + if LogView.super.on_mouse_pressed(self, button, mx, my, clicks) then return end + if self.hovered_item then + self:expand_item(self.hovered_item) + end +end + + function LogView:update() local item = core.log_items[#core.log_items] if self.last_item ~= item then @@ -28,6 +107,14 @@ function LogView:update() self.yoffset = -(style.font:get_height() + style.padding.y) end + local expanding = self.expanding[1] + if expanding then + self:move_towards(expanding, "current", expanding.target) + if expanding.current == expanding.target then + table.remove(self.expanding, 1) + end + end + self:move_towards("yoffset", 0) LogView.super.update(self) @@ -46,28 +133,57 @@ local function draw_text_multiline(font, text, x, y, color) end +local function draw_text_elipsis(font, color, text, x, y, w, h, elipsis_style) + elipsis_style = elipsis_style or "end" + local c = font:get_width("_") + local approxc = math.floor(w / c) + if #text > approxc then + if elipsis_style == "end" then + text = string.sub(text, 1, approxc - 3) .. "..." + elseif elipsis_style == "middle" then + local mid = math.floor(#text / 2) + text = string.sub(text, 1, mid - 3) .. "..." .. string.sub(text, mid) + end + end + return common.draw_text(font, color, text, "left", x, y, w, h) +end + + function LogView:draw() self:draw_background(style.background) - local ox, oy = self:get_content_offset() local th = style.font:get_height() - local y = oy + style.padding.y + self.yoffset - - for i = #core.log_items, 1, -1 do - local x = ox + style.padding.x - local item = core.log_items[i] - local time = os.date(nil, item.time) - x = renderer.draw_text(style.font, time, x, y, style.dim) + local lh = th + style.padding.y -- for one line + for _, item, x, y, w, h in self:each_item() do + core.push_clip_rect(x, y, w, h) x = x + style.padding.x - local subx = x - x, y = draw_text_multiline(style.font, item.text, x, y, style.text) - renderer.draw_text(style.font, " at " .. item.at, x, y, style.dim) - y = y + th - if item.info then - subx, y = draw_text_multiline(style.font, item.info, subx, y, style.dim) + + local time = os.date(nil, item.time) + x = common.draw_text(style.font, style.dim, time, "left", x, y, w, lh) + x = x + style.padding.x + + x = common.draw_text(style.code_font, style.dim, is_expanded(item) and "-" or "+", "left", x, y, w, lh) + x = x + style.padding.x + w = w - (x - self:get_content_offset()) + + if is_expanded(item) then + y = y + common.round(style.padding.y / 2) + draw_text_multiline(style.font, item.text, x, y, style.text) + y = y + th + + local at = "at " .. common.home_encode(item.at) + draw_text_elipsis(style.font, style.dim, at, x, y, w, lh, "middle") + y = y + th + + if item.info then + draw_text_multiline(style.font, item.info, x, y, style.dim) + end + else + draw_text_elipsis(style.font, style.text, item.text, x, y, w, lh) y = y + th end - y = y + style.padding.y + + core.pop_clip_rect() end end From 622b162225689424740a92c6390fff494eabd08c Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Sun, 22 Aug 2021 19:32:45 +0800 Subject: [PATCH 05/62] add core.get_log() --- data/core/init.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/data/core/init.lua b/data/core/init.lua index f6034a06..702e31fd 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -881,6 +881,23 @@ function core.error(...) end +function core.get_log(i) + if i == nil then + local r = {} + for _, item in ipairs(core.log_items) do + table.insert(r, core.get_log(item)) + end + return table.concat(r, "\n") + end + local item = type(i) == "number" and core.log_items[i] or i + local text = string.format("[%s] %s at %s", os.date(nil, item.time), item.text, item.at) + if item.info then + text = string.format("%s\n%s\n", text, item.info) + end + return text +end + + function core.try(fn, ...) local err local ok, res = xpcall(fn, function(msg) From e25ea1196a539f56b88b84bc3fd442001251bb65 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Sun, 22 Aug 2021 19:33:28 +0800 Subject: [PATCH 06/62] add context menu options for logview --- data/plugins/contextmenu.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/data/plugins/contextmenu.lua b/data/plugins/contextmenu.lua index b84d114d..dc95567f 100644 --- a/data/plugins/contextmenu.lua +++ b/data/plugins/contextmenu.lua @@ -42,6 +42,24 @@ keymap.add { ["menu"] = "context:show" } +local function copy_log() + local item = core.active_view.hovered_item + if item then + system.set_clipboard(core.get_log(item)) + end +end + +local function open_as_doc() + local doc = core.open_doc("logs.txt") + core.root_view:open_doc(doc) + doc:insert(1, 1, core.get_log()) +end + +menu:register("core.logview", { + { text = "Copy entry", command = copy_log }, + { text = "Open as file", command = open_as_doc } +}) + if require("plugins.scale") then menu:register("core.docview", { { text = "Font +", command = "scale:increase" }, From 14565b5226523614719f5a6e77fbf0c1e6ad7e23 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Tue, 24 Aug 2021 11:32:20 +0800 Subject: [PATCH 07/62] more changes to logview - remove draw_text_elipsis - remove clip rect operations - fix text drawing when expanded - simplify code --- data/core/logview.lua | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/data/core/logview.lua b/data/core/logview.lua index b81e8efe..f79ff3e3 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -123,29 +123,12 @@ end local function draw_text_multiline(font, text, x, y, color) local th = font:get_height() - local resx, resy = x, y + local resx = x for line in text:gmatch("[^\n]+") do - resy = y resx = renderer.draw_text(style.font, line, x, y, color) y = y + th end - return resx, resy -end - - -local function draw_text_elipsis(font, color, text, x, y, w, h, elipsis_style) - elipsis_style = elipsis_style or "end" - local c = font:get_width("_") - local approxc = math.floor(w / c) - if #text > approxc then - if elipsis_style == "end" then - text = string.sub(text, 1, approxc - 3) .. "..." - elseif elipsis_style == "middle" then - local mid = math.floor(#text / 2) - text = string.sub(text, 1, mid - 3) .. "..." .. string.sub(text, mid) - end - end - return common.draw_text(font, color, text, "left", x, y, w, h) + return resx, y end @@ -155,7 +138,6 @@ function LogView:draw() local th = style.font:get_height() local lh = th + style.padding.y -- for one line for _, item, x, y, w, h in self:each_item() do - core.push_clip_rect(x, y, w, h) x = x + style.padding.x local time = os.date(nil, item.time) @@ -168,22 +150,21 @@ function LogView:draw() if is_expanded(item) then y = y + common.round(style.padding.y / 2) - draw_text_multiline(style.font, item.text, x, y, style.text) - y = y + th + _, y = draw_text_multiline(style.font, item.text, x, y, style.text) local at = "at " .. common.home_encode(item.at) - draw_text_elipsis(style.font, style.dim, at, x, y, w, lh, "middle") - y = y + th + _, y = common.draw_text(style.font, style.dim, at, "left", x, y, w, lh) if item.info then - draw_text_multiline(style.font, item.info, x, y, style.dim) + _, y = draw_text_multiline(style.font, item.info, x, y, style.dim) end else - draw_text_elipsis(style.font, style.text, item.text, x, y, w, lh) - y = y + th + local line, has_newline = string.match(item.text, "([^\n]+)(\n?)") + if has_newline ~= "" then + line = line .. " ..." + end + _, y = common.draw_text(style.font, style.text, line, "left", x, y, w, lh) end - - core.pop_clip_rect() end end From 30d3751632cfa237e81d5f7b4c1ddffe2d630f84 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Tue, 24 Aug 2021 12:02:22 +0800 Subject: [PATCH 08/62] remove unused variable --- data/core/logview.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/logview.lua b/data/core/logview.lua index f79ff3e3..1ea0e43e 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -137,7 +137,7 @@ function LogView:draw() local th = style.font:get_height() local lh = th + style.padding.y -- for one line - for _, item, x, y, w, h in self:each_item() do + for _, item, x, y, w in self:each_item() do x = x + style.padding.x local time = os.date(nil, item.time) From 97493a1a4eca756e81404bc053de90a4591fb4d9 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Mon, 2 Aug 2021 11:37:00 +0800 Subject: [PATCH 09/62] add doc:get_selection_text() --- data/core/doc/init.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index d05d9d45..ae948479 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -124,9 +124,21 @@ function Doc:get_selection(sort) return line1, col1, line2, col2, sort end +function Doc:get_selection_text(limit) + limit = limit or math.huge + local result = {} + for idx, line1, col1, line2, col2 in self:get_selections() do + if idx > limit then break end + if line1 ~= line2 or col1 ~= col2 then + local text = self:get_text(line1, col1, line2, col2) + if text ~= "" then result[#result + 1] = text end + end + end + return table.concat(result, "\n") +end + function Doc:has_selection() - local line1, col1, line2, col2 = self:get_selection(false) - return line1 ~= line2 or col1 ~= col2 + local line1, col1, line2, col2 = self:get_selection(false) return line1 ~= line2 or col1 ~= col2 end function Doc:sanitize_selection() From fb907c9bf4ffbcb84f9b7b1b1e010cf66ac88fd8 Mon Sep 17 00:00:00 2001 From: Takase <20792268+takase1121@users.noreply.github.com> Date: Tue, 17 Aug 2021 20:16:56 +0800 Subject: [PATCH 10/62] increase code readibility --- data/core/doc/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index ae948479..4a231295 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -138,7 +138,8 @@ function Doc:get_selection_text(limit) end function Doc:has_selection() - local line1, col1, line2, col2 = self:get_selection(false) return line1 ~= line2 or col1 ~= col2 + local line1, col1, line2, col2 = self:get_selection(false) + return line1 ~= line2 or col1 ~= col2 end function Doc:sanitize_selection() From fc4c7a29eee4cb0c775454ce700f32f49fd936f4 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Mon, 23 Aug 2021 19:10:13 +0200 Subject: [PATCH 11/62] use dependency fallbacks, use system reproc if available --- lib/font_renderer/meson.build | 6 +----- meson.build | 13 ++----------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/font_renderer/meson.build b/lib/font_renderer/meson.build index 7724d584..d596e152 100644 --- a/lib/font_renderer/meson.build +++ b/lib/font_renderer/meson.build @@ -1,10 +1,6 @@ freetype_dep = dependency('freetype2') -libagg_dep = dependency('libagg', required: false) -if not libagg_dep.found() - libagg_subproject = subproject('libagg') - libagg_dep = libagg_subproject.get_variable('libagg_dep') -endif +libagg_dep = dependency('libagg', fallback: ['libagg', 'libagg_dep']) font_renderer_sources = [ 'agg_font_freetype.cpp', diff --git a/meson.build b/meson.build index 5dee12ec..20067d43 100644 --- a/meson.build +++ b/meson.build @@ -51,24 +51,15 @@ endif #=============================================================================== libm = cc.find_library('m', required : false) libdl = cc.find_library('dl', required : false) -lua_dep = dependency('lua5.2', required : false) +lua_dep = dependency('lua5.2', fallback: ['lua', 'lua_dep']) pcre2_dep = dependency('libpcre2-8') sdl_dep = dependency('sdl2', method: 'config-tool') - -if not lua_dep.found() - lua_subproject = subproject('lua', - default_options: ['shared=false', 'use_readline=false', 'app=false'] - ) - lua_dep = lua_subproject.get_variable('lua_dep') -endif - -reproc_subproject = subproject('reproc', +reproc_dep = dependency('reproc', fallback: ['reproc', 'reproc_dep'], default_options: [ 'default_library=static', 'multithreaded=false', 'reproc-cpp=false', 'examples=false' ] ) -reproc_dep = reproc_subproject.get_variable('reproc_dep') lite_deps = [lua_dep, sdl_dep, reproc_dep, pcre2_dep, libm, libdl] From e23b6176f4921a9f086cb94ee81b79a73ed414f2 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 24 Aug 2021 19:04:48 +0200 Subject: [PATCH 12/62] Fix lua subproject options removed by error --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 20067d43..0c5bc865 100644 --- a/meson.build +++ b/meson.build @@ -51,7 +51,9 @@ endif #=============================================================================== libm = cc.find_library('m', required : false) libdl = cc.find_library('dl', required : false) -lua_dep = dependency('lua5.2', fallback: ['lua', 'lua_dep']) +lua_dep = dependency('lua5.2', fallback: ['lua', 'lua_dep'], + default_options: ['shared=false', 'use_readline=false', 'app=false'] +) pcre2_dep = dependency('libpcre2-8') sdl_dep = dependency('sdl2', method: 'config-tool') reproc_dep = dependency('reproc', fallback: ['reproc', 'reproc_dep'], From 7f338fc993b2edc940268e884e638e5d2072ace8 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Fri, 27 Aug 2021 19:03:41 +0200 Subject: [PATCH 13/62] Allow tabs to always be visible --- data/core/config.lua | 1 + data/core/rootview.lua | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/data/core/config.lua b/data/core/config.lua index 401ac0af..caecdfcd 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -12,6 +12,7 @@ config.non_word_chars = " \t\n/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-" config.undo_merge_timeout = 0.3 config.max_undos = 10000 config.max_tabs = 10 +config.always_show_tabs = false config.highlight_current_line = true config.line_height = 1.2 config.indent_size = 2 diff --git a/data/core/rootview.lua b/data/core/rootview.lua index f2499e68..9d017268 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -261,7 +261,7 @@ end function Node:get_tab_overlapping_point(px, py) - if #self.views == 1 then return nil end + if not self:should_show_tabs() then return nil end local tabs_number = self:get_visible_tabs_number() local x1, y1, w, h = self:get_tab_rect(self.tab_offset) local x2, y2 = self:get_tab_rect(self.tab_offset + tabs_number) @@ -271,6 +271,16 @@ function Node:get_tab_overlapping_point(px, py) end +function Node:should_show_tabs() + if self.locked then return false end + if #self.views > 1 then return true + elseif config.always_show_tabs then + return not self.views[1]:is(EmptyView) + end + return false +end + + local function close_button_location(x, w) local cw = style.icon_font:get_width("C") local pad = style.padding.y @@ -414,7 +424,7 @@ end function Node:update_layout() if self.type == "leaf" then local av = self.active_view - if #self.views > 1 then + if self:should_show_tabs() then local _, _, _, th = self:get_tab_rect(1) av.position.x, av.position.y = self.position.x, self.position.y + th av.size.x, av.size.y = self.size.x, self.size.y - th @@ -569,7 +579,7 @@ end function Node:draw() if self.type == "leaf" then - if #self.views > 1 then + if self:should_show_tabs() then self:draw_tabs() end local pos, size = self.active_view.position, self.active_view.size From d3bd35b577b3d65f5a0704566219e4cecf1c9cc3 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sun, 29 Aug 2021 02:23:47 +0200 Subject: [PATCH 14/62] Use plain `string:find` when matching plugin directories --- data/core/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index 702e31fd..5b1cca26 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -692,7 +692,7 @@ function core.load_plugins() if is_lua_file then if not version_match then core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir) - local list = refused_list[plugin_dir:find(USERDIR) == 1 and 'userdir' or 'datadir'].plugins + local list = refused_list[plugin_dir:find(USERDIR, 1, true) == 1 and 'userdir' or 'datadir'].plugins table.insert(list, filename) end if version_match and config.plugins[basename] ~= false then From e93bbc559c5dda25a2aab870a49b76f64124e681 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sun, 29 Aug 2021 04:02:53 +0200 Subject: [PATCH 15/62] Fix crash in project search when project has no files --- data/plugins/projectsearch.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index 45967697..dda3a2d0 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -171,7 +171,7 @@ function ResultsView:draw() local ox, oy = self:get_content_offset() local x, y = ox + style.padding.x, oy + style.padding.y local files_number = core.project_files_number() - local per = files_number and self.last_file_idx / files_number or 1 + local per = common.clamp(files_number and self.last_file_idx / files_number or 1, 0, 1) local text if self.searching then if files_number then From ea795aa411ef814c5db3fb0d70619184f0e520cc Mon Sep 17 00:00:00 2001 From: boppyt <71049646+boppyt@users.noreply.github.com> Date: Sat, 28 Aug 2021 22:37:02 -0700 Subject: [PATCH 16/62] build script: add .git fallback --- build-packages.sh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/build-packages.sh b/build-packages.sh index f30b1112..039e56f8 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -10,7 +10,16 @@ copy_directory_from_repo () { fi local dirname="$1" local destdir="$2" - git archive "$use_branch" "$dirname" --format=tar | tar xf - -C "$destdir" "${tar_options[@]}" + _archive "$use_branch" "$dirname" "$destdir" "${tar_options[@]}" +} + +_archive () { + if [[ -d ".git" ]]; then + git archive "$1" "$2" --format=tar | tar xf - -C "$3" "$4" + else + echo ".git not found, falling back to UNIX operation" + cp -r "$2" "$3" + fi } # Check if build directory is ok to be used to build. @@ -20,10 +29,14 @@ build_dir_is_usable () { echo "invalid build directory, no path allowed: \"$build\"" return 1 fi - git ls-files --error-unmatch "$build" &> /dev/null - if [ $? == 0 ]; then - echo "invalid path, \"$build\" is under revision control" - return 1 + if [[ -d ".git" ]]; then + git ls-files --error-unmatch "$build" &> /dev/null + if [ $? == 0 ]; then + echo "invalid path, \"$build\" is under revision control" + return 1 + fi + else + echo ".git not found, skipping check for revision control" fi } @@ -214,7 +227,12 @@ if [ -z ${arch+set} ]; then fi if [ -z ${use_branch+set} ]; then - use_branch="$(git rev-parse --abbrev-ref HEAD)" + if [[ -d ".git" ]]; then + use_branch="$(git rev-parse --abbrev-ref HEAD)" + else + # it really doesn't matter if git isn't present + use_branch="master" + fi fi build_dir=".build-$arch" From e34ec195b42960a1e7ab49285bc46d1ee55cc74a Mon Sep 17 00:00:00 2001 From: boppyt <71049646+boppyt@users.noreply.github.com> Date: Sat, 28 Aug 2021 23:31:49 -0700 Subject: [PATCH 17/62] build script: check for BUILD_PROHIBIT_GIT --- build-packages.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build-packages.sh b/build-packages.sh index 039e56f8..366882e6 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -14,7 +14,7 @@ copy_directory_from_repo () { } _archive () { - if [[ -d ".git" ]]; then + if [[ -d ".git" || $BUILD_PROHIBIT_GIT -eq 1 ]]; then git archive "$1" "$2" --format=tar | tar xf - -C "$3" "$4" else echo ".git not found, falling back to UNIX operation" @@ -29,7 +29,7 @@ build_dir_is_usable () { echo "invalid build directory, no path allowed: \"$build\"" return 1 fi - if [[ -d ".git" ]]; then + if [[ -d ".git" || $BUILD_PROHIBIT_GIT -eq 1 ]]; then git ls-files --error-unmatch "$build" &> /dev/null if [ $? == 0 ]; then echo "invalid path, \"$build\" is under revision control" @@ -227,7 +227,7 @@ if [ -z ${arch+set} ]; then fi if [ -z ${use_branch+set} ]; then - if [[ -d ".git" ]]; then + if [[ -d ".git" || $BUILD_PROHIBIT_GIT -eq 1 ]]; then use_branch="$(git rev-parse --abbrev-ref HEAD)" else # it really doesn't matter if git isn't present From 97ca19c73fa062600293c994c2488b413bc38957 Mon Sep 17 00:00:00 2001 From: Zack A Date: Sun, 29 Aug 2021 16:16:14 -0700 Subject: [PATCH 18/62] build script: check if .git is present --- build-packages.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/build-packages.sh b/build-packages.sh index 366882e6..ed85e175 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -14,10 +14,9 @@ copy_directory_from_repo () { } _archive () { - if [[ -d ".git" || $BUILD_PROHIBIT_GIT -eq 1 ]]; then + if [[ $git_available -eq 1 ]]; then git archive "$1" "$2" --format=tar | tar xf - -C "$3" "$4" else - echo ".git not found, falling back to UNIX operation" cp -r "$2" "$3" fi } @@ -29,14 +28,12 @@ build_dir_is_usable () { echo "invalid build directory, no path allowed: \"$build\"" return 1 fi - if [[ -d ".git" || $BUILD_PROHIBIT_GIT -eq 1 ]]; then + if [[ $git_available -eq 1 ]]; then git ls-files --error-unmatch "$build" &> /dev/null if [ $? == 0 ]; then echo "invalid path, \"$build\" is under revision control" return 1 fi - else - echo ".git not found, skipping check for revision control" fi } @@ -203,7 +200,6 @@ lite_copy_third_party_modules () { mv "$build/lite-colors-master/colors" "$build/third/data" rm -fr "$build/lite-colors-master" } - unset arch while [ ! -z {$1+x} ]; do case $1 in @@ -226,8 +222,15 @@ if [ -z ${arch+set} ]; then exit 1 fi + if [[ -d ".git" || $BUILD_PROHIBIT_GIT -ne 0 ]]; then + git_available=1; + else + echo "Use of git prohibited. Either '.git' wasn't found or BUILD_PROHIBIT_GIT was set." + git_available=0; + fi + if [ -z ${use_branch+set} ]; then - if [[ -d ".git" || $BUILD_PROHIBIT_GIT -eq 1 ]]; then + if [[ $git_available -eq 1 ]]; then use_branch="$(git rev-parse --abbrev-ref HEAD)" else # it really doesn't matter if git isn't present From 8dde1dbb8649f33e08e5d44e4931c3ede0ce0407 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 30 Aug 2021 14:27:31 +0200 Subject: [PATCH 19/62] Add renderer build options in build-packages.sh --- build-packages.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/build-packages.sh b/build-packages.sh index ed85e175..ffe3537b 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -42,7 +42,7 @@ lite_build () { local build="$1" build_dir_is_usable "$build" || exit 1 rm -fr "$build" - setup_options=() + setup_options=("${@:2}") if [[ "$OSTYPE" == "darwin"* ]]; then setup_options+=(-Dbundle=true) fi @@ -55,7 +55,8 @@ lite_build_pgo () { local build="$1" build_dir_is_usable "$build" || exit 1 rm -fr "$build" - meson setup --buildtype=release -Db_pgo=generate "$build" || exit 1 + echo meson setup --buildtype=release "${@:2}" -Db_pgo=generate "$build" + meson setup --buildtype=release "${@:2}" -Db_pgo=generate "$build" || exit 1 ninja -C "$build" || exit 1 copy_directory_from_repo data "$build/src" "$build/src/lite-xl" @@ -200,9 +201,15 @@ lite_copy_third_party_modules () { mv "$build/lite-colors-master/colors" "$build/third/data" rm -fr "$build/lite-colors-master" } + +build_opts=() unset arch while [ ! -z {$1+x} ]; do case $1 in + -renderer) + build_opts+=("-Drenderer=true") + shift + ;; -pgo) pgo=true shift @@ -241,9 +248,9 @@ fi build_dir=".build-$arch" if [ -z ${pgo+set} ]; then - lite_build "$build_dir" + lite_build "$build_dir" "${build_opts[@]}" else - lite_build_pgo "$build_dir" + lite_build_pgo "$build_dir" "${build_opts[@]}" fi lite_copy_third_party_modules "$build_dir" lite_build_package "$build_dir" "$arch" From 68c1cc606fda70769db200d79421db2311d4313f Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 30 Aug 2021 14:35:42 +0200 Subject: [PATCH 20/62] Bring back min len autocomplete default to 3 --- data/plugins/autocomplete.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/plugins/autocomplete.lua b/data/plugins/autocomplete.lua index c41f233d..484199a9 100644 --- a/data/plugins/autocomplete.lua +++ b/data/plugins/autocomplete.lua @@ -12,7 +12,7 @@ local Doc = require "core.doc" config.plugins.autocomplete = { -- Amount of characters that need to be written for autocomplete - min_len = 1, + min_len = 3, -- The max amount of visible items max_height = 6, -- The max amount of scrollable items From 9d4e944549b48ae2c311860f913bc1f217fa6748 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 28 Aug 2021 13:42:06 -0400 Subject: [PATCH 21/62] Added in two new VSC-style multicursor shortcuts. --- data/core/commands/findreplace.lua | 32 ++++++++++++++++++++++++------ data/core/keymap-macos.lua | 1 + data/core/keymap.lua | 1 + 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 6dd7ddae..b9a424fa 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -96,13 +96,33 @@ local function has_selection() return core.active_view:is(DocView) and core.active_view.doc:has_selection() end -command.add(has_selection, { - ["find-replace:select-next"] = function() - local l1, c1, l2, c2 = doc():get_selection(true) - local text = doc():get_text(l1, c1, l2, c2) - l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true }) - if l2 then doc():set_selection(l2, c2, l1, c1) end +local function has_unique_selection() + local text = nil + for idx, line1, col1, line2, col2 in doc():get_selections(true, true) do + if line1 == line2 and col1 == col2 then return false end + local selection = doc():get_text(line1, col1, line2, col2) + if text ~= nil and text ~= selection then return false end + text = selection end + return text ~= nil +end + +local function select_next(all) + local il1, ic1 = doc():get_selection(true) + for idx, l1, c1, l2, c2 in doc():get_selections(true, true) do + local text = doc():get_text(l1, c1, l2, c2) + repeat + l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true }) + if l1 == il1 and c1 == ic1 then break end + if l2 then doc():add_selection(l2, c2, l1, c1) end + until not all or not l2 + break + end +end + +command.add(has_unique_selection, { + ["find-replace:select-next"] = function() select_next(false) end, + ["find-replace:select-all"] = function() select_next(true) end }) command.add("core.docview", { diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index 647cb132..89f68949 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -66,6 +66,7 @@ local function keymap_macos(keymap) ["cmd+a"] = "doc:select-all", ["cmd+d"] = { "find-replace:select-next", "doc:select-word" }, ["cmd+l"] = "doc:select-lines", + ["cmd+shift+l"] = { "find-replace:select-all", "doc:select-word" }, ["cmd+/"] = "doc:toggle-line-comments", ["cmd+up"] = "doc:move-lines-up", ["cmd+down"] = "doc:move-lines-down", diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 0b08259d..2be0dfc7 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -170,6 +170,7 @@ keymap.add_direct { ["ctrl+a"] = "doc:select-all", ["ctrl+d"] = { "find-replace:select-next", "doc:select-word" }, ["ctrl+l"] = "doc:select-lines", + ["ctrl+shift+l"] = { "find-replace:select-all", "doc:select-word" }, ["ctrl+/"] = "doc:toggle-line-comments", ["ctrl+up"] = "doc:move-lines-up", ["ctrl+down"] = "doc:move-lines-down", From d352eb1cb9169576f2ce8972b8bcab3b208bf204 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 29 Aug 2021 17:54:57 -0400 Subject: [PATCH 22/62] Fixed cursors moving around with removal and inserts with cursors. Also fixed drawing line highlights with multicursors. --- data/core/doc/init.lua | 19 +++++++++++++++++++ data/core/docview.lua | 10 +++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 4a231295..269d6d12 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -322,6 +322,7 @@ end function Doc:raw_insert(line, col, text, undo_stack, time) -- split text into lines and merge with line at insertion point local lines = split_lines(text) + local len = #lines[#lines] local before = self.lines[line]:sub(1, col - 1) local after = self.lines[line]:sub(col) for i = 1, #lines - 1 do @@ -338,6 +339,15 @@ function Doc:raw_insert(line, col, text, undo_stack, time) push_undo(undo_stack, time, "selection", unpack(self.selections)) push_undo(undo_stack, time, "remove", line, col, line2, col2) + -- keep cursors where they should be + for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true) do + if cline1 >= line then + local line_addition = line > cline1 or ccol1 > col and #lines - 1 or 0 + local column_addition = line == cline1 and ccol1 > col and len or 0 + self:set_selections(idx, cline1 + line_addition, ccol1 + column_addition, cline2 + line_addition, ccol2 + column_addition) + end + end + -- update highlighter and assure selection is in bounds self.highlighter:invalidate(line) self:sanitize_selection() @@ -356,6 +366,15 @@ function Doc:raw_remove(line1, col1, line2, col2, undo_stack, time) -- splice line into line array common.splice(self.lines, line1, line2 - line1 + 1, { before .. after }) + + -- move all cursors back if they share a line with the removed text + for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true) do + if cline1 >= line2 then + local line_removal = line2 - line1 + local column_removal = line2 == cline2 and col2 < ccol1 and (line2 == line1 and col2 - col1 or col2) or 0 + self:set_selections(idx, cline1 - line_removal, ccol1 - column_removal, cline2 - line_removal, ccol2 - column_removal) + end + end -- update highlighter and assure selection is in bounds self.highlighter:invalidate(line1) diff --git a/data/core/docview.lua b/data/core/docview.lua index 17fb534a..161eac47 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -367,16 +367,20 @@ function DocView:draw_line_body(idx, x, y) local x1 = x + self:get_col_x_offset(idx, col1) local x2 = x + self:get_col_x_offset(idx, col2) local lh = self:get_line_height() - renderer.draw_rect(x1, y, x2 - x1, lh, style.selection) + if x1 ~= x2 then + renderer.draw_rect(x1, y, x2 - x1, lh, style.selection) + end end end + local draw_highlight = nil for lidx, line1, col1, line2, col2 in self.doc:get_selections(true) do -- draw line highlight if caret is on this line - if config.highlight_current_line and (line1 == line2 and col1 == col2) + if draw_highlight ~= false and config.highlight_current_line and line1 == idx and core.active_view == self then - self:draw_line_highlight(x + self.scroll.x, y) + draw_highlight = (line1 == line2 and col1 == col2) end end + if draw_highlight then self:draw_line_highlight(x + self.scroll.x, y) end -- draw line's text self:draw_line_text(idx, x, y) From 1d61cf989fd6d7ef023763acf7e1fd5459f49893 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 29 Aug 2021 20:05:58 -0400 Subject: [PATCH 23/62] Fixed cursor movement. --- data/core/doc/init.lua | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 269d6d12..ea219a8a 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -333,21 +333,20 @@ function Doc:raw_insert(line, col, text, undo_stack, time) -- splice lines into line array common.splice(self.lines, line, 1, lines) + + -- keep cursors where they should be + for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true, true) do + if cline1 < line then break end + local line_addition = (line < cline1 or col < ccol1) and #lines - 1 or 0 + local column_addition = line == cline1 and ccol1 > col and len or 0 + self:set_selections(idx, cline1 + line_addition, ccol1 + column_addition, cline2 + line_addition, ccol2 + column_addition) + end -- push undo local line2, col2 = self:position_offset(line, col, #text) push_undo(undo_stack, time, "selection", unpack(self.selections)) push_undo(undo_stack, time, "remove", line, col, line2, col2) - -- keep cursors where they should be - for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true) do - if cline1 >= line then - local line_addition = line > cline1 or ccol1 > col and #lines - 1 or 0 - local column_addition = line == cline1 and ccol1 > col and len or 0 - self:set_selections(idx, cline1 + line_addition, ccol1 + column_addition, cline2 + line_addition, ccol2 + column_addition) - end - end - -- update highlighter and assure selection is in bounds self.highlighter:invalidate(line) self:sanitize_selection() @@ -368,12 +367,11 @@ function Doc:raw_remove(line1, col1, line2, col2, undo_stack, time) common.splice(self.lines, line1, line2 - line1 + 1, { before .. after }) -- move all cursors back if they share a line with the removed text - for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true) do - if cline1 >= line2 then - local line_removal = line2 - line1 - local column_removal = line2 == cline2 and col2 < ccol1 and (line2 == line1 and col2 - col1 or col2) or 0 - self:set_selections(idx, cline1 - line_removal, ccol1 - column_removal, cline2 - line_removal, ccol2 - column_removal) - end + for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true, true) do + if cline1 < line2 then break end + local line_removal = line2 - line1 + local column_removal = line2 == cline2 and col2 < ccol1 and (line2 == line1 and col2 - col1 or col2) or 0 + self:set_selections(idx, cline1 - line_removal, ccol1 - column_removal, cline2 - line_removal, ccol2 - column_removal) end -- update highlighter and assure selection is in bounds @@ -411,7 +409,7 @@ end function Doc:text_input(text, idx) - for sidx, line1, col1, line2, col2 in self:get_selections(true, idx) do + for sidx, line1, col1, line2, col2 in self:get_selections(true, idx or true) do if line1 ~= line2 or col1 ~= col2 then self:delete_to_cursor(sidx) end From 604626fa32380880bb73a210a4366337c6ab9d9b Mon Sep 17 00:00:00 2001 From: Timofffee Date: Mon, 30 Aug 2021 16:21:16 +0400 Subject: [PATCH 24/62] Fix macOS keymap --- data/core/keymap-macos.lua | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index 89f68949..7f54ddbb 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -52,12 +52,14 @@ local function keymap_macos(keymap) ["shift+tab"] = "doc:unindent", ["backspace"] = "doc:backspace", ["shift+backspace"] = "doc:backspace", - ["cmd+backspace"] = "doc:delete-to-previous-word-start", + ["option+backspace"] = "doc:delete-to-previous-word-start", ["cmd+shift+backspace"] = "doc:delete-to-previous-word-start", + ["cmd+backspace"] = "doc:delete-to-start-of-indentation", ["delete"] = "doc:delete", ["shift+delete"] = "doc:delete", - ["cmd+delete"] = "doc:delete-to-next-word-end", + ["option+delete"] = "doc:delete-to-next-word-end", ["cmd+shift+delete"] = "doc:delete-to-next-word-end", + ["cmd+delete"] = "doc:delete-to-end-of-line", ["return"] = { "command:submit", "doc:newline", "dialog:select" }, ["keypad enter"] = { "command:submit", "doc:newline", "dialog:select" }, ["cmd+return"] = "doc:newline-below", @@ -68,8 +70,8 @@ local function keymap_macos(keymap) ["cmd+l"] = "doc:select-lines", ["cmd+shift+l"] = { "find-replace:select-all", "doc:select-word" }, ["cmd+/"] = "doc:toggle-line-comments", - ["cmd+up"] = "doc:move-lines-up", - ["cmd+down"] = "doc:move-lines-down", + ["option+up"] = "doc:move-lines-up", + ["option+down"] = "doc:move-lines-down", ["cmd+shift+d"] = "doc:duplicate-lines", ["cmd+shift+k"] = "doc:delete-lines", @@ -77,14 +79,16 @@ local function keymap_macos(keymap) ["right"] = { "doc:move-to-next-char", "dialog:next-entry"}, ["up"] = { "command:select-previous", "doc:move-to-previous-line" }, ["down"] = { "command:select-next", "doc:move-to-next-line" }, - ["cmd+left"] = "doc:move-to-previous-word-start", - ["cmd+right"] = "doc:move-to-next-word-end", + ["option+left"] = "doc:move-to-previous-word-start", + ["option+right"] = "doc:move-to-next-word-end", + ["cmd+left"] = "doc:move-to-start-of-indentation", + ["cmd+right"] = "doc:move-to-end-of-line", ["cmd+["] = "doc:move-to-previous-block-start", ["cmd+]"] = "doc:move-to-next-block-end", ["home"] = "doc:move-to-start-of-indentation", ["end"] = "doc:move-to-end-of-line", - ["cmd+home"] = "doc:move-to-start-of-doc", - ["cmd+end"] = "doc:move-to-end-of-doc", + ["cmd+up"] = "doc:move-to-start-of-doc", + ["cmd+down"] = "doc:move-to-end-of-doc", ["pageup"] = "doc:move-to-previous-page", ["pagedown"] = "doc:move-to-next-page", @@ -92,18 +96,20 @@ local function keymap_macos(keymap) ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", ["shift+down"] = "doc:select-to-next-line", - ["cmd+shift+left"] = "doc:select-to-previous-word-start", - ["cmd+shift+right"] = "doc:select-to-next-word-end", + ["option+shift+left"] = "doc:select-to-previous-word-start", + ["option+shift+right"] = "doc:select-to-next-word-end", + ["cmd+shift+left"] = "doc:select-to-start-of-indentation", + ["cmd+shift+right"] = "doc:select-to-end-of-line", ["cmd+shift+["] = "doc:select-to-previous-block-start", ["cmd+shift+]"] = "doc:select-to-next-block-end", ["shift+home"] = "doc:select-to-start-of-indentation", ["shift+end"] = "doc:select-to-end-of-line", - ["cmd+shift+home"] = "doc:select-to-start-of-doc", - ["cmd+shift+end"] = "doc:select-to-end-of-doc", + ["cmd+shift+up"] = "doc:select-to-start-of-doc", + ["cmd+shift+down"] = "doc:select-to-end-of-doc", ["shift+pageup"] = "doc:select-to-previous-page", ["shift+pagedown"] = "doc:select-to-next-page", - ["cmd+shift+up"] = "doc:create-cursor-previous-line", - ["cmd+shift+down"] = "doc:create-cursor-next-line" + ["cmd+option+up"] = "doc:create-cursor-previous-line", + ["cmd+option+down"] = "doc:create-cursor-next-line" } end From a75aca25380b404a2ccda61277071b7b86e1914e Mon Sep 17 00:00:00 2001 From: redtide Date: Tue, 31 Aug 2021 14:45:00 +0200 Subject: [PATCH 25/62] Renamed freedesktop resources --- build-packages.sh | 4 ++-- meson.build | 4 ++-- ...lite-xl.appdata.xml => org.lite_xl.lite_xl.appdata.xml} | 7 ++++++- ...lite-xl.lite-xl.desktop => org.lite_xl.lite_xl.desktop} | 2 +- scripts/appimage.sh | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) rename resources/linux/{org.lite-xl.lite-xl.appdata.xml => org.lite_xl.lite_xl.appdata.xml} (83%) rename resources/linux/{org.lite-xl.lite-xl.desktop => org.lite_xl.lite_xl.desktop} (80%) diff --git a/build-packages.sh b/build-packages.sh index ffe3537b..424d60ba 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -167,8 +167,8 @@ lite_build_package_linux () { strip "$bindir/lite-xl" if [ -z "$portable" ]; then mkdir -p "$pdir/share/applications" "$pdir/share/icons/hicolor/scalable/apps" "$pdir/share/metainfo" - cp "resources/linux/org.lite-xl.lite-xl.desktop" "$pdir/share/applications" - cp "resources/linux/org.lite-xl.lite-xl.appdata.xml" "$pdir/share/metainfo" + cp "resources/linux/org.lite_xl.lite_xl.desktop" "$pdir/share/applications" + cp "resources/linux/org.lite_xl.lite_xl.appdata.xml" "$pdir/share/metainfo" cp "resources/icons/lite-xl.svg" "$pdir/share/icons/hicolor/scalable/apps/lite-xl.svg" fi pushd ".package-build" diff --git a/meson.build b/meson.build index 0c5bc865..3d5f9da9 100644 --- a/meson.build +++ b/meson.build @@ -92,10 +92,10 @@ else install_data('resources/icons/lite-xl.svg', install_dir : 'share/icons/hicolor/scalable/apps' ) - install_data('resources/linux/org.lite-xl.lite-xl.desktop', + install_data('resources/linux/org.lite_xl.lite_xl.desktop', install_dir : 'share/applications' ) - install_data('resources/linux/org.lite-xl.lite-xl.appdata.xml', + install_data('resources/linux/org.lite_xl.lite_xl.appdata.xml', install_dir : 'share/metainfo' ) endif diff --git a/resources/linux/org.lite-xl.lite-xl.appdata.xml b/resources/linux/org.lite_xl.lite_xl.appdata.xml similarity index 83% rename from resources/linux/org.lite-xl.lite-xl.appdata.xml rename to resources/linux/org.lite_xl.lite_xl.appdata.xml index d2d0a73a..c5895178 100644 --- a/resources/linux/org.lite-xl.lite-xl.appdata.xml +++ b/resources/linux/org.lite_xl.lite_xl.appdata.xml @@ -1,10 +1,11 @@ - org.lite-xl.lite-xl + org.lite_xl.lite_xl MIT MIT Lite XL A lightweight text editor written in Lua +

@@ -25,4 +26,8 @@ lite-xl + + + + diff --git a/resources/linux/org.lite-xl.lite-xl.desktop b/resources/linux/org.lite_xl.lite_xl.desktop similarity index 80% rename from resources/linux/org.lite-xl.lite-xl.desktop rename to resources/linux/org.lite_xl.lite_xl.desktop index f2fa9610..c09fb5db 100644 --- a/resources/linux/org.lite-xl.lite-xl.desktop +++ b/resources/linux/org.lite_xl.lite_xl.desktop @@ -6,5 +6,5 @@ Exec=lite-xl %F Icon=lite-xl Terminal=false StartupNotify=false -Categories=Utility;TextEditor;Development; +Categories=Development;IDE; MimeType=text/plain; diff --git a/scripts/appimage.sh b/scripts/appimage.sh index b2cc5cd7..65dce3c4 100644 --- a/scripts/appimage.sh +++ b/scripts/appimage.sh @@ -117,7 +117,7 @@ generate_appimage(){ mv AppRun LiteXL.AppDir/ # These could be symlinks but it seems they doesn't work with AppimageLauncher cp resources/icons/lite-xl.svg LiteXL.AppDir/ - cp resources/linux/org.lite-xl.lite-xl.desktop LiteXL.AppDir/ + cp resources/linux/org.lite_xl.lite_xl.desktop LiteXL.AppDir/ if [[ $STATIC_BUILD == false ]]; then echo "Copying libraries..." From 7811660cafd01a977814378d57973b36f4cf15aa Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Mon, 30 Aug 2021 22:56:33 -0400 Subject: [PATCH 26/62] Fixed replace to make it multicursor-aware. --- data/core/doc/init.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index ea219a8a..47869d5a 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -418,12 +418,7 @@ function Doc:text_input(text, idx) end end - -function Doc:replace(fn) - local line1, col1, line2, col2 = self:get_selection(true) - if line1 == line2 and col1 == col2 then - line1, col1, line2, col2 = 1, 1, #self.lines, #self.lines[#self.lines] - end +function Doc:replace_cursor(idx, line1, col1, line2, col2, fn) local old_text = self:get_text(line1, col1, line2, col2) local new_text, n = fn(old_text) if old_text ~= new_text then @@ -431,12 +426,26 @@ function Doc:replace(fn) self:remove(line1, col1, line2, col2) if line1 == line2 and col1 == col2 then line2, col2 = self:position_offset(line1, col1, #new_text) - self:set_selection(line1, col1, line2, col2) + self:set_selections(idx, line1, col1, line2, col2) end end return n end +function Doc:replace(fn) + local has_selection = false + for idx, line1, col1, line2, col2 in self:get_selections(true) do + if line1 ~= line2 or col1 ~= col2 then + self:replace_cursor(idx, line1, col1, line2, col2, fn) + has_selection = true + end + end + if not has_selection then + self:set_selection(table.unpack(self.selections)) + self:replace_cursor(1, 1, 1, #self.lines, #self.lines[#self.lines], fn) + end +end + function Doc:delete_to_cursor(idx, ...) for sidx, line1, col1, line2, col2 in self:get_selections(true, idx) do From b7f2d1ad03bc39df8fbe227d77934c10b2b64ee8 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 31 Aug 2021 16:21:40 -0400 Subject: [PATCH 27/62] Forgot to return an 'n'. --- data/core/doc/init.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 47869d5a..aff31e94 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -433,17 +433,18 @@ function Doc:replace_cursor(idx, line1, col1, line2, col2, fn) end function Doc:replace(fn) - local has_selection = false + local has_selection, n = false, 0 for idx, line1, col1, line2, col2 in self:get_selections(true) do if line1 ~= line2 or col1 ~= col2 then - self:replace_cursor(idx, line1, col1, line2, col2, fn) + n = n + self:replace_cursor(idx, line1, col1, line2, col2, fn) has_selection = true end end if not has_selection then self:set_selection(table.unpack(self.selections)) - self:replace_cursor(1, 1, 1, #self.lines, #self.lines[#self.lines], fn) + n = n + self:replace_cursor(1, 1, 1, #self.lines, #self.lines[#self.lines], fn) end + return n end From de4072e207094f872be0e924c38755e02fc50624 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 1 Sep 2021 16:29:47 +0200 Subject: [PATCH 28/62] Avoid checking for unique selections on non-`DocView`s --- data/core/commands/findreplace.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index b9a424fa..48cbecaf 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -96,7 +96,8 @@ local function has_selection() return core.active_view:is(DocView) and core.active_view.doc:has_selection() end -local function has_unique_selection() +local function has_unique_selection() + if not core.active_view:is(DocView) then return false end local text = nil for idx, line1, col1, line2, col2 in doc():get_selections(true, true) do if line1 == line2 and col1 == col2 then return false end From 11521ff883aa28446f1af551d880d6df7df9c069 Mon Sep 17 00:00:00 2001 From: redtide Date: Wed, 1 Sep 2021 19:42:09 +0200 Subject: [PATCH 29/62] Specify the WM_CLASS of the application, used by some Linux DEs --- resources/linux/org.lite_xl.lite_xl.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/linux/org.lite_xl.lite_xl.desktop b/resources/linux/org.lite_xl.lite_xl.desktop index c09fb5db..d251c4dc 100644 --- a/resources/linux/org.lite_xl.lite_xl.desktop +++ b/resources/linux/org.lite_xl.lite_xl.desktop @@ -5,6 +5,6 @@ Comment=A lightweight text editor written in Lua Exec=lite-xl %F Icon=lite-xl Terminal=false -StartupNotify=false +StartupWMClass=lite-xl Categories=Development;IDE; MimeType=text/plain; From 59aa7f0090ecbd0049d15fdc2b9154ee857c1d8d Mon Sep 17 00:00:00 2001 From: Guldoman Date: Thu, 2 Sep 2021 18:58:24 +0200 Subject: [PATCH 30/62] Fix absolute path detection in `core.project_absolute_path` --- data/core/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index 5b1cca26..3bf10211 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -809,7 +809,7 @@ end -- This function should get only filenames normalized using -- common.normalize_path function. function core.project_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.project_dir .. PATHSEP .. filename From 9887dd47469f83ceb5c10c546a5df62361bf4fa5 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Thu, 2 Sep 2021 19:09:29 +0200 Subject: [PATCH 31/62] Make open files follow renames --- data/plugins/treeview.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index f9a67aaf..9bb597f2 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -441,11 +441,24 @@ command.add(nil, { ["treeview:rename"] = function() local old_filename = view.hovered_item.filename + local old_abs_filename = view.hovered_item.abs_filename core.command_view:set_text(old_filename) core.command_view:enter("Rename", function(filename) - os.rename(old_filename, filename) + filename = core.normalize_to_project_dir(filename) + local abs_filename = core.project_absolute_path(filename) + local res, err = os.rename(old_abs_filename, abs_filename) + if res then -- successfully renamed + for _, doc in ipairs(core.docs) do + if doc.abs_filename and old_abs_filename == doc.abs_filename then + doc:set_filename(filename, abs_filename) -- make doc point to the new filename + break -- only first needed + end + end + core.log("Renamed \"%s\" to \"%s\"", old_filename, filename) + else + core.error("Error while renaming \"%s\" to \"%s\": %s", old_abs_filename, abs_filename, err) + end core.reschedule_project_scan() - core.log("Renamed \"%s\" to \"%s\"", old_filename, filename) end, common.path_suggest) end, From 3278eebdad8c30c337e2e7a77087f3ba30cb00af Mon Sep 17 00:00:00 2001 From: Guldoman Date: Thu, 2 Sep 2021 19:12:26 +0200 Subject: [PATCH 32/62] Avoid exposing `treeview` commands when not usable --- data/plugins/treeview.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 9bb597f2..48d6f5a7 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -437,8 +437,10 @@ menu:register( command.add(nil, { ["treeview:toggle"] = function() view.visible = not view.visible - end, + end}) + +command.add(function() return view.hovered_item ~= nil end, { ["treeview:rename"] = function() local old_filename = view.hovered_item.filename local old_abs_filename = view.hovered_item.abs_filename From 8d355bd3a058028306d1c3c004c069aa717435aa Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 3 Sep 2021 23:33:36 +0200 Subject: [PATCH 33/62] Add missing release flag in build-packages.sh --- build-packages.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-packages.sh b/build-packages.sh index 424d60ba..666fb9e2 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -46,7 +46,7 @@ lite_build () { if [[ "$OSTYPE" == "darwin"* ]]; then setup_options+=(-Dbundle=true) fi - meson setup "${setup_options[@]}" "$build" || exit 1 + meson setup --buildtype=release "${setup_options[@]}" "$build" || exit 1 ninja -C "$build" || exit 1 } From f9c7eeeeb8265b6f741cde5cabdb060c2a57c630 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sat, 4 Sep 2021 00:32:01 +0200 Subject: [PATCH 34/62] Check if session file returned anything --- data/core/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 3bf10211..6b770fd6 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -17,7 +17,7 @@ local core = {} local function load_session() local ok, t = pcall(dofile, USERDIR .. "/session.lua") - if ok then + if ok and t then return t.recents, t.window, t.window_mode end return {} @@ -441,7 +441,7 @@ function core.init() elseif window_mode == "maximized" then system.set_window_mode("maximized") end - core.recent_projects = recent_projects + core.recent_projects = recent_projects or {} end local project_dir = core.recent_projects[1] or "." From de038a633d140a4fa3be89cd1f3de7fac2d85146 Mon Sep 17 00:00:00 2001 From: Francesco Date: Sat, 4 Sep 2021 17:24:08 +0200 Subject: [PATCH 35/62] Update README to remove reference to notarization We assume we don't need to mention the macOS package is notarized. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 339747fd..32f63d70 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A lightweight text editor written in Lua, adapted from [lite]. -* **[Get Lite XL]** — Download for Windows, Linux and Mac OS (notarized app). +* **[Get Lite XL]** — Download for Windows, Linux and Mac OS. * **[Get plugins]** — Add additional functionality, adapted for Lite XL. * **[Get color themes]** — Add additional colors themes. From 9246a16e67501c62593018d14d3eae91e8d09589 Mon Sep 17 00:00:00 2001 From: Timofffee Date: Fri, 3 Sep 2021 15:50:44 +0400 Subject: [PATCH 36/62] Bring back info.plist with meson configuration --- meson.build | 8 +++++++- resources/macos/{Info.plist => Info.plist.in} | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) rename resources/macos/{Info.plist => Info.plist.in} (96%) diff --git a/meson.build b/meson.build index 3d5f9da9..7e9b4ab1 100644 --- a/meson.build +++ b/meson.build @@ -83,7 +83,13 @@ elif get_option('bundle') and host_machine.system() == 'darwin' lite_docdir = 'Contents/Resources' lite_datadir = 'Contents/Resources' install_data('resources/icons/icon.icns', install_dir : 'Contents/Resources') - install_data('resources/macos/Info.plist', install_dir : 'Contents') + configure_file( + input : 'resources/macos/Info.plist.in', + output : 'Info.plist', + configuration : conf_data, + install : true, + install_dir : 'Contents' + ) else lite_bindir = 'bin' lite_docdir = 'share/doc/lite-xl' diff --git a/resources/macos/Info.plist b/resources/macos/Info.plist.in similarity index 96% rename from resources/macos/Info.plist rename to resources/macos/Info.plist.in index d465479c..c15fd566 100644 --- a/resources/macos/Info.plist +++ b/resources/macos/Info.plist.in @@ -19,8 +19,9 @@ NSDesktopFolderUsageDescriptionTo access, edit and index your projects. NSDownloadsFolderUsageDescriptionTo access, edit and index your projects. CFBundleShortVersionString - 2.0 + @PROJECT_VERSION@ NSHumanReadableCopyright © 2019-2021 Francesco Abbate + From cc20849afdde351bcf5bd96a43b4586b212feca7 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 4 Sep 2021 18:08:04 +0200 Subject: [PATCH 37/62] Fix build-packages to use generated Info.plist --- build-packages.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-packages.sh b/build-packages.sh index 666fb9e2..6b874cd9 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -120,7 +120,7 @@ lite_build_package_macos () { cp -r "$build/third/data/$module_name" "$datadir" done cp resources/icons/icon.icns "$appdir/Contents/Resources/icon.icns" - cp resources/macos/Info.plist "$appdir/Contents/Info.plist" + cp "$build/Info.plist" "$appdir/Contents/Info.plist" cp "$build/src/lite-xl" "$bindir/lite-xl" strip "$bindir/lite-xl" pushd ".package-build" From 91da2ddfdd8fb0a63ed30d2ef94c88e13f907f27 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 4 Sep 2021 18:15:07 +0200 Subject: [PATCH 38/62] Move innosetup meson config into scripts directory The purpose is to keep the main meson build file as simple as possible while keeping the innosetup config. --- meson.build | 8 +------- scripts/innosetup/innosetup.sh | 2 +- scripts/meson.build | 8 ++++++++ 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 scripts/meson.build diff --git a/meson.build b/meson.build index 7e9b4ab1..611d154a 100644 --- a/meson.build +++ b/meson.build @@ -14,13 +14,6 @@ conf_data.set('PROJECT_BUILD_DIR', meson.current_build_dir()) conf_data.set('PROJECT_SOURCE_DIR', meson.current_source_dir()) conf_data.set('PROJECT_VERSION', meson.project_version()) -if host_machine.system() == 'windows' - configure_file( - input : 'scripts/innosetup/innosetup.iss.in', - output : 'innosetup.iss', - configuration : conf_data - ) -endif #=============================================================================== # Compiler Settings #=============================================================================== @@ -127,3 +120,4 @@ configure_file( #=============================================================================== subdir('lib/font_renderer') subdir('src') +subdir('scripts') diff --git a/scripts/innosetup/innosetup.sh b/scripts/innosetup/innosetup.sh index b2d0e86c..44a6c787 100644 --- a/scripts/innosetup/innosetup.sh +++ b/scripts/innosetup/innosetup.sh @@ -51,5 +51,5 @@ else ARCH=Win32 fi -/c/Program\ Files\ \(x86\)/Inno\ Setup\ 6/ISCC.exe -dARCH=$ARCH $BUILD_DIR/innosetup.iss +/c/Program\ Files\ \(x86\)/Inno\ Setup\ 6/ISCC.exe -dARCH=$ARCH $BUILD_DIR/scripts/innosetup.iss mv $BUILD_DIR/LiteXL*.exe $(pwd) diff --git a/scripts/meson.build b/scripts/meson.build new file mode 100644 index 00000000..8b45814d --- /dev/null +++ b/scripts/meson.build @@ -0,0 +1,8 @@ +if host_machine.system() == 'windows' + configure_file( + input : 'innosetup/innosetup.iss.in', + output : 'innosetup.iss', + configuration : conf_data + ) +endif + From 261ab5daf226a44271f45219bb3c6ec1fe8d6ff9 Mon Sep 17 00:00:00 2001 From: redtide Date: Sun, 29 Aug 2021 10:15:55 +0200 Subject: [PATCH 39/62] Adapt all scripts to work together with build-packages.sh --- .github/workflows/build.yml | 121 ++++----- .gitignore | 2 + README.md | 16 +- build-packages.sh | 393 +++++++++++------------------ meson.build | 46 ++-- meson_options.txt | 1 + scripts/README.md | 28 ++ scripts/appimage.sh | 14 +- scripts/build.sh | 157 ++++++------ scripts/common.sh | 25 ++ scripts/innosetup/innosetup.iss.in | 19 +- scripts/innosetup/innosetup.sh | 82 +++--- scripts/install-dependencies.sh | 74 ++++++ scripts/lhelper.sh | 75 ++++++ scripts/msys2-package.sh | 56 ---- scripts/package.sh | 252 ++++++++++++++++++ scripts/source-package.sh | 69 ----- 17 files changed, 829 insertions(+), 601 deletions(-) create mode 100644 scripts/README.md create mode 100644 scripts/common.sh create mode 100644 scripts/install-dependencies.sh create mode 100644 scripts/lhelper.sh delete mode 100644 scripts/msys2-package.sh create mode 100644 scripts/package.sh delete mode 100644 scripts/source-package.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6eec7a63..2778de79 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,26 +1,25 @@ name: CI +# All builds use lhelper only for releases, +# otherwise for normal builds dependencies are dynamically linked. + on: push: branches: - '*' - # Temporarily disabled - #tags: - #- 'v[0-9]*' +# tags: +# - 'v[0-9]*' pull_request: branches: - '*' jobs: - # Note: not using git-archive(-all) because it can't include subprojects ignored by git archive_source_code: name: Source Code Tarball runs-on: ubuntu-18.04 # Only on tags/releases if: startsWith(github.ref, 'refs/tags/') steps: - - name: Set Environment Variables - run: echo "INSTALL_NAME=lite-xl-${GITHUB_REF##*/}-src" >> "$GITHUB_ENV" - uses: actions/checkout@v2 - name: Python Setup uses: actions/setup-python@v2 @@ -30,16 +29,14 @@ jobs: run: | sudo apt-get install -qq ninja-build pip3 install meson - - name: Archive source code + - name: Package shell: bash - run: bash scripts/source-package.sh --destdir "${INSTALL_NAME}" + run: bash scripts/package.sh --version ${GITHUB_REF##*/} --debug --source - uses: actions/upload-artifact@v2 with: name: Source Code Tarball - path: ${{ env.INSTALL_NAME }}.tar.gz + path: "lite-xl-*-src.tar.gz" - # All builds use lhelper only for releases, using --static build argument, - # otherwise for normal builds dependencies are dynamically linked. build_linux: name: Linux runs-on: ubuntu-18.04 @@ -52,11 +49,12 @@ jobs: CC: ${{ matrix.config.cc }} CXX: ${{ matrix.config.cxx }} steps: - - name: Set Archive Name + - name: Set Environment Variables if: ${{ matrix.config.cc == 'gcc' }} run: | + echo "$HOME/.local/bin" >> "$GITHUB_PATH" echo "INSTALL_REF=${GITHUB_REF##*/}" >> "$GITHUB_ENV" - echo "INSTALL_NAME=lite-xl-${GITHUB_REF##*/}-linux" >> "$GITHUB_ENV" + echo "INSTALL_NAME=lite-xl-${GITHUB_REF##*/}-linux-$(uname -m)" >> "$GITHUB_ENV" - uses: actions/checkout@v2 - name: Python Setup uses: actions/setup-python@v2 @@ -64,27 +62,24 @@ jobs: python-version: 3.6 - name: Update Packages run: sudo apt-get update - - name: Install Meson - run: | - sudo apt-get install -qq ninja-build - pip3 install meson - name: Install Dependencies if: ${{ !startsWith(github.ref, 'refs/tags/') }} - run: sudo apt-get install -qq libsdl2-dev libfreetype6 + run: bash scripts/install-dependencies.sh --debug + - name: Install Release Dependencies + if: ${{ startsWith(github.ref, 'refs/tags/') }} + run: | + bash scripts/install-dependencies.sh --debug --lhelper + bash scripts/lhelper.sh --debug - name: Build - if: ${{ matrix.config.cc == 'gcc' && !startsWith(github.ref, 'refs/tags/') }} - run: bash scripts/build.sh --prefix / - - name: Release Build - if: ${{ matrix.config.cc == 'gcc' && startsWith(github.ref, 'refs/tags/') }} - run: bash scripts/build.sh --prefix / --static + run: | + bash --version + bash scripts/build.sh --debug --forcefallback - name: Package if: ${{ matrix.config.cc == 'gcc' }} - run: | - DESTDIR="$(pwd)/$INSTALL_NAME" meson install --skip-subprojects -C build - tar czvf "${INSTALL_NAME}".tar.gz "${INSTALL_NAME}" + run: bash scripts/package.sh --version ${INSTALL_REF} --debug --addons --binary - name: AppImage if: ${{ matrix.config.cc == 'gcc' && startsWith(github.ref, 'refs/tags/') }} - run: bash scripts/appimage.sh --nobuild --static --version ${{ env.INSTALL_REF }} + run: bash scripts/appimage.sh --nobuild --version ${INSTALL_REF} - name: Upload Artifacts uses: actions/upload-artifact@v2 if: ${{ matrix.config.cc == 'gcc' }} @@ -104,47 +99,42 @@ jobs: - name: System Information run: | system_profiler SPSoftwareDataType + bash --version gcc -v xcodebuild -version - - name: Set Archive Name + - name: Set Environment Variables run: | - echo "INSTALL_NAME=lite-xl-${GITHUB_REF##*/}-macos" >> "$GITHUB_ENV" - bash --version + echo "$HOME/.local/bin" >> "$GITHUB_PATH" + echo "INSTALL_REF=${GITHUB_REF##*/}" >> "$GITHUB_ENV" + echo "INSTALL_NAME=lite-xl-${GITHUB_REF##*/}-macos-$(uname -m)" >> "$GITHUB_ENV" - uses: actions/checkout@v2 - name: Python Setup uses: actions/setup-python@v2 with: python-version: 3.9 - - name: Install Build Tools - run: | - brew install ninja - pip3 install meson - cd ~; npm install appdmg; cd - - ~/node_modules/appdmg/bin/appdmg.js --version - name: Install Dependencies if: ${{ !startsWith(github.ref, 'refs/tags/') }} - run: brew install sdl2 - - name: Install LHelper Dependencies - if: ${{ startsWith(github.ref, 'refs/tags/') }} - run: brew install bash md5sha1sum - - name: Build - if: ${{ !startsWith(github.ref, 'refs/tags/') }} - run: bash scripts/build.sh --prefix "${GITHUB_WORKSPACE}/Lite XL.app" - - name: Release Build + run: bash scripts/install-dependencies.sh --debug + - name: Install Release Dependencies if: ${{ startsWith(github.ref, 'refs/tags/') }} + run: | + bash scripts/install-dependencies.sh --debug --lhelper + bash scripts/lhelper.sh --debug + - name: Build run: | bash --version - bash scripts/build.sh --prefix "${GITHUB_WORKSPACE}/Lite XL.app" --static + bash scripts/build.sh --bundle --debug --forcefallback - name: Error Logs if: failure() run: | mkdir ${INSTALL_NAME} cp /usr/var/lhenv/lite-xl/logs/* ${INSTALL_NAME} tar czvf ${INSTALL_NAME}.tar.gz ${INSTALL_NAME} - - name: Install - run: meson install --skip-subprojects -C build +# - name: Package +# if: ${{ !startsWith(github.ref, 'refs/tags/') }} +# run: bash scripts/package.sh --version ${INSTALL_REF} --debug --addons - name: Create DMG Image - run: bash scripts/appdmg.sh ${{ env.INSTALL_NAME }} + run: bash scripts/package.sh --version ${INSTALL_REF} --debug --addons --dmg - name: Upload DMG Image uses: actions/upload-artifact@v2 with: @@ -178,34 +168,20 @@ jobs: git zip - name: Set Environment Variables - run: echo "INSTALL_NAME=lite-xl-${GITHUB_REF##*/}-$(echo $MSYSTEM | awk '{print tolower($0)}')" >> "$GITHUB_ENV" + run: | + echo "$HOME/.local/bin" >> "$GITHUB_PATH" + echo "INSTALL_NAME=lite-xl-${GITHUB_REF##*/}-windows-$(uname -m)" >> "$GITHUB_ENV" + echo "INSTALL_REF=${GITHUB_REF##*/}" >> "$GITHUB_ENV" - name: Install Dependencies if: ${{ !startsWith(github.ref, 'refs/tags/') }} - run: | - pacman --noconfirm -S \ - ${MINGW_PACKAGE_PREFIX}-gcc \ - ${MINGW_PACKAGE_PREFIX}-meson \ - ${MINGW_PACKAGE_PREFIX}-ninja \ - ${MINGW_PACKAGE_PREFIX}-pkg-config \ - ${MINGW_PACKAGE_PREFIX}-freetype \ - ${MINGW_PACKAGE_PREFIX}-pcre2 \ - ${MINGW_PACKAGE_PREFIX}-SDL2 + run: bash scripts/install-dependencies.sh --debug - name: Install Release Dependencies if: ${{ startsWith(github.ref, 'refs/tags/') }} - run: | - pacman --noconfirm -S \ - ${MINGW_PACKAGE_PREFIX}-gcc \ - ${MINGW_PACKAGE_PREFIX}-meson \ - ${MINGW_PACKAGE_PREFIX}-ninja \ - ${MINGW_PACKAGE_PREFIX}-pkg-config + run: bash scripts/install-dependencies.sh --debug --lhelper - name: Build - if: ${{ !startsWith(github.ref, 'refs/tags/') }} - run: bash scripts/build.sh --prefix / - - name: Release Build - if: ${{ startsWith(github.ref, 'refs/tags/') }} run: | bash --version - bash scripts/build.sh --prefix / --static + bash scripts/build.sh --debug --forcefallback - name: Error Logs if: failure() run: | @@ -213,10 +189,10 @@ jobs: cp /usr/var/lhenv/lite-xl/logs/* ${INSTALL_NAME} tar czvf ${INSTALL_NAME}.tar.gz ${INSTALL_NAME} - name: Package - run: bash scripts/msys2-package.sh --destdir ${INSTALL_NAME} + run: bash scripts/package.sh --version ${INSTALL_REF} --debug --addons --binary - name: Build Installer if: ${{ startsWith(github.ref, 'refs/tags/') }} - run: bash scripts/innosetup/innosetup.sh + run: bash scripts/innosetup/innosetup.sh --debug - name: Upload Artifacts uses: actions/upload-artifact@v2 with: @@ -234,9 +210,8 @@ jobs: deploy: name: Deployment runs-on: ubuntu-18.04 - # Temporarily disabled +# if: startsWith(github.ref, 'refs/tags/') if: false - #if: startsWith(github.ref, 'refs/tags/') needs: - archive_source_code - build_linux diff --git a/.gitignore b/.gitignore index 7dc39e42..16974405 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ subprojects/reproc/ .lite-debug.log .run* *.diff +*.exe *.tar.gz *.zip *.DS_Store @@ -17,3 +18,4 @@ subprojects/reproc/ compile_commands.json error.txt lite-xl* +LiteXL* diff --git a/README.md b/README.md index 32f63d70..73204c57 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,11 @@ If you compile Lite XL yourself, it is recommended to use the script `build-packages.sh`: ```sh -bash build-packages.sh +bash build-packages.sh -h ``` -The script will run Meson and create a zip file with the application or, -for Linux, a tar compressed archive. Lite XL can be easily installed +The script will run Meson and create a tar compressed archive with the application or, +for Windows, a zip file. Lite XL can be easily installed by unpacking the archive in any directory of your choice. Otherwise the following is an example of basic commands if you want to customize @@ -65,7 +65,15 @@ meson compile -C build DESTDIR="$(pwd)/lite-xl" meson install --skip-subprojects -C build ``` -where `` might be one of `/`, `/usr` or `/opt`, the default is `/usr/local`. +where `` might be one of `/`, `/usr` or `/opt`, the default is `/`. +To build a bundle application on macOS: + +```sh +meson setup --buildtype=release --Dbundle=true --prefix / build +meson compile -C build +DESTDIR="$(pwd)/Lite XL.app" meson install --skip-subprojects -C build +``` + Please note that the package is relocatable to any prefix and the option prefix affects only the place where the application is actually installed. diff --git a/build-packages.sh b/build-packages.sh index 6b874cd9..6014be96 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -1,259 +1,156 @@ #!/bin/bash +set -e -# strip-components is normally set to 1 to strip the initial "data" from the -# directory path. -copy_directory_from_repo () { - local tar_options=() - if [[ $1 == --strip-components=* ]]; then - tar_options+=($1) - shift - fi - local dirname="$1" - local destdir="$2" - _archive "$use_branch" "$dirname" "$destdir" "${tar_options[@]}" +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL."; exit 1 +fi + +source scripts/common.sh + +show_help() { + echo + echo "Usage: $0 " + echo + echo "Common options:" + echo + echo "-h --help Show this help and exit." + echo "-b --builddir DIRNAME Set the name of the build directory (not path)." + echo " Default: '$(get_default_build_dir)'." + echo "-p --prefix PREFIX Install directory prefix." + echo " Default: '/'." + echo " --debug Debug this script." + echo + echo "Build options:" + echo + echo "-f --forcefallback Force to build subprojects dependencies statically." + echo "-B --bundle Create an App bundle (macOS only)" + echo "-P --portable Create a portable package." + echo + echo "Package options:" + echo + echo "-d --destdir DIRNAME Set the name of the package directory (not path)." + echo " Default: 'lite-xl'." + echo "-v --version VERSION Sets the version on the package name." + echo "-A --appimage Create an AppImage (Linux only)." + echo "-D --dmg Create a DMG disk image (macOS only)." + echo " Requires NPM and AppDMG." + echo "-I --innosetup Create an InnoSetup installer (Windows only)." + echo "-S --source Create a source code package," + echo " including subprojects dependencies." + echo } -_archive () { - if [[ $git_available -eq 1 ]]; then - git archive "$1" "$2" --format=tar | tar xf - -C "$3" "$4" - else - cp -r "$2" "$3" - fi -} +main() { + local build_dir + local build_dir_option=() + local dest_dir + local dest_dir_option=() + local prefix + local prefix_option=() + local version + local version_option=() + local debug + local force_fallback + local appimage + local bundle + local innosetup + local portable -# Check if build directory is ok to be used to build. -build_dir_is_usable () { - local build="$1" - if [[ $build == */* || -z "$build" ]]; then - echo "invalid build directory, no path allowed: \"$build\"" - return 1 - fi - if [[ $git_available -eq 1 ]]; then - git ls-files --error-unmatch "$build" &> /dev/null - if [ $? == 0 ]; then - echo "invalid path, \"$build\" is under revision control" - return 1 - fi - fi -} - -# Ordinary release build -lite_build () { - local build="$1" - build_dir_is_usable "$build" || exit 1 - rm -fr "$build" - setup_options=("${@:2}") - if [[ "$OSTYPE" == "darwin"* ]]; then - setup_options+=(-Dbundle=true) - fi - meson setup --buildtype=release "${setup_options[@]}" "$build" || exit 1 - ninja -C "$build" || exit 1 -} - -# Build using Profile Guided Optimizations (PGO) -lite_build_pgo () { - local build="$1" - build_dir_is_usable "$build" || exit 1 - rm -fr "$build" - echo meson setup --buildtype=release "${@:2}" -Db_pgo=generate "$build" - meson setup --buildtype=release "${@:2}" -Db_pgo=generate "$build" || exit 1 - ninja -C "$build" || exit 1 - copy_directory_from_repo data "$build/src" - "$build/src/lite-xl" - meson configure -Db_pgo=use "$build" - ninja -C "$build" || exit 1 -} - -lite_build_package_windows () { - local portable="-msys" - if [ "$1" == "-portable" ]; then - portable="" - shift - fi - local build="$1" - local arch="$2" - local os="win" - local pdir=".package-build/lite-xl" - if [ -z "$portable" ]; then - local bindir="$pdir" - local datadir="$pdir/data" - else - local bindir="$pdir/bin" - local datadir="$pdir/share/lite-xl" - fi - mkdir -p "$bindir" - mkdir -p "$datadir" - for module_name in core plugins colors fonts; do - copy_directory_from_repo --strip-components=1 "data/$module_name" "$datadir" + for i in "$@"; do + case $i in + -h|--help) + show_help + exit 0 + ;; + -b|--builddir) + build_dir="$2" + shift + shift + ;; + -d|--destdir) + dest_dir="$2" + shift + shift + ;; + -f|--forcefallback) + force_fallback="--forcefallback" + shift + ;; + -p|--prefix) + prefix="$2" + shift + shift + ;; + -v|--version) + version="$2" + shift + shift + ;; + -A|--appimage) + appimage="--appimage" + shift + ;; + -B|--bundle) + bundle="--bundle" + shift + ;; + -D|--dmg) + dmg="--dmg" + shift + ;; + -I|--innosetup) + innosetup="--innosetup" + shift + ;; + -P|--portable) + portable="--portable" + shift + ;; + -S|--source) + source="--source" + shift + ;; + --debug) + debug="--debug" + set -x + shift + ;; + *) + # unknown option + ;; + esac done - # copy the meson generated start.lua file - cp "$build/start.lua" "$datadir/core" - for module_name in plugins colors; do - cp -r "$build/third/data/$module_name" "$datadir" - done - cp "$build/src/lite-xl.exe" "$bindir" - strip --strip-all "$bindir/lite-xl.exe" - pushd ".package-build" - local package_name="lite-xl-$os-$arch$portable.zip" - zip "$package_name" -r "lite-xl" - mv "$package_name" .. - popd - rm -fr ".package-build" - echo "created package $package_name" -} -lite_build_package_macos () { - local build="$1" - local arch="$2" - local os="macos" - - local appdir=".package-build/lite-xl.app" - local bindir="$appdir/Contents/MacOS" - local datadir="$appdir/Contents/Resources" - mkdir -p "$bindir" "$datadir" - for module_name in core plugins colors fonts; do - copy_directory_from_repo --strip-components=1 "data/$module_name" "$datadir" - done - # copy the meson generated start.lua file - cp "$build/start.lua" "$datadir/core" - for module_name in plugins colors; do - cp -r "$build/third/data/$module_name" "$datadir" - done - cp resources/icons/icon.icns "$appdir/Contents/Resources/icon.icns" - cp "$build/Info.plist" "$appdir/Contents/Info.plist" - cp "$build/src/lite-xl" "$bindir/lite-xl" - strip "$bindir/lite-xl" - pushd ".package-build" - local package_name="lite-xl-$os-$arch.zip" - zip "$package_name" -r "lite-xl.app" - mv "$package_name" .. - popd - rm -fr ".package-build" - echo "created package $package_name" -} - -lite_build_package_linux () { - local portable="" - if [ "$1" == "-portable" ]; then - portable="-portable" - shift - fi - local build="$1" - local arch="$2" - local os="linux" - local pdir=".package-build/lite-xl" - if [ "$portable" == "-portable" ]; then - local bindir="$pdir" - local datadir="$pdir/data" - local docdir="$pdir/doc" - else - local bindir="$pdir/bin" - local datadir="$pdir/share/lite-xl" - local docdir="$pdir/share/doc/lite-xl" - fi - mkdir -p "$bindir" - mkdir -p "$datadir" - mkdir -p "$docdir" - for module_name in core plugins colors fonts; do - copy_directory_from_repo --strip-components=1 "data/$module_name" "$datadir" - done - # copy the meson generated start.lua file - cp "$build/start.lua" "$datadir/core" - for module_name in plugins colors; do - cp -r "$build/third/data/$module_name" "$datadir" - done - cp "$build/src/lite-xl" "$bindir" - cp "licenses/licenses.md" "$docdir" - strip "$bindir/lite-xl" - if [ -z "$portable" ]; then - mkdir -p "$pdir/share/applications" "$pdir/share/icons/hicolor/scalable/apps" "$pdir/share/metainfo" - cp "resources/linux/org.lite_xl.lite_xl.desktop" "$pdir/share/applications" - cp "resources/linux/org.lite_xl.lite_xl.appdata.xml" "$pdir/share/metainfo" - cp "resources/icons/lite-xl.svg" "$pdir/share/icons/hicolor/scalable/apps/lite-xl.svg" - fi - pushd ".package-build" - local package_name="lite-xl-$os-$arch$portable.tar.gz" - tar czf "$package_name" "lite-xl" - mv "$package_name" .. - popd - rm -fr ".package-build" - echo "created package $package_name" -} - -lite_build_package () { - if [[ "$OSTYPE" == msys || "$OSTYPE" == win32 ]]; then - lite_build_package_windows "$@" - elif [[ "$OSTYPE" == "darwin"* ]]; then - lite_build_package_macos "$@" - elif [[ "$OSTYPE" == "linux"* || "$OSTYPE" == "freebsd"* ]]; then - lite_build_package_linux "$@" - else - echo "Unknown OS type \"$OSTYPE\"" + if [[ -n $1 ]]; then + show_help exit 1 fi + + if [[ -n $build_dir ]]; then build_dir_option=("--builddir" "${build_dir}"); fi + if [[ -n $dest_dir ]]; then dest_dir_option=("--destdir" "${dest_dir}"); fi + if [[ -n $prefix ]]; then prefix_option=("--prefix" "${prefix}"); fi + if [[ -n $version ]]; then version_option=("--version" "${version}"); fi + + source scripts/build.sh \ + ${build_dir_option[@]} \ + ${prefix_option[@]} \ + $debug \ + $force_fallback \ + $bundle \ + $portable + + source scripts/package.sh \ + ${build_dir_option[@]} \ + ${dest_dir_option[@]} \ + ${prefix_option[@]} \ + ${version_option[@]} \ + --binary \ + --addons \ + $debug \ + $appimage \ + $dmg \ + $innosetup \ + $source } -lite_copy_third_party_modules () { - local build="$1" - curl --insecure -L "https://github.com/rxi/lite-colors/archive/master.zip" -o "$build/rxi-lite-colors.zip" - mkdir -p "$build/third/data/colors" "$build/third/data/plugins" - unzip "$build/rxi-lite-colors.zip" -d "$build" - mv "$build/lite-colors-master/colors" "$build/third/data" - rm -fr "$build/lite-colors-master" -} - -build_opts=() -unset arch -while [ ! -z {$1+x} ]; do - case $1 in - -renderer) - build_opts+=("-Drenderer=true") - shift - ;; - -pgo) - pgo=true - shift - ;; - -branch=*) - use_branch="${1#-branch=}" - shift - ;; - *) - arch="$1" - break - esac -done - -if [ -z ${arch+set} ]; then - echo "usage: $0 [options] " - exit 1 -fi - - if [[ -d ".git" || $BUILD_PROHIBIT_GIT -ne 0 ]]; then - git_available=1; - else - echo "Use of git prohibited. Either '.git' wasn't found or BUILD_PROHIBIT_GIT was set." - git_available=0; - fi - -if [ -z ${use_branch+set} ]; then - if [[ $git_available -eq 1 ]]; then - use_branch="$(git rev-parse --abbrev-ref HEAD)" - else - # it really doesn't matter if git isn't present - use_branch="master" - fi -fi - -build_dir=".build-$arch" - -if [ -z ${pgo+set} ]; then - lite_build "$build_dir" "${build_opts[@]}" -else - lite_build_pgo "$build_dir" "${build_opts[@]}" -fi -lite_copy_third_party_modules "$build_dir" -lite_build_package "$build_dir" "$arch" -if [[ ! ( "$OSTYPE" == "linux"* || "$OSTYPE" == "freebsd"* || "$OSTYPE" == "darwin"* ) ]]; then - lite_build_package -portable "$build_dir" "$arch" -fi +main "$@" diff --git a/meson.build b/meson.build index 611d154a..9d3eac31 100644 --- a/meson.build +++ b/meson.build @@ -42,26 +42,28 @@ endif #=============================================================================== # Dependencies #=============================================================================== -libm = cc.find_library('m', required : false) -libdl = cc.find_library('dl', required : false) -lua_dep = dependency('lua5.2', fallback: ['lua', 'lua_dep'], - default_options: ['shared=false', 'use_readline=false', 'app=false'] -) -pcre2_dep = dependency('libpcre2-8') -sdl_dep = dependency('sdl2', method: 'config-tool') -reproc_dep = dependency('reproc', fallback: ['reproc', 'reproc_dep'], - default_options: [ - 'default_library=static', 'multithreaded=false', - 'reproc-cpp=false', 'examples=false' - ] -) +if not get_option('source-only') + libm = cc.find_library('m', required : false) + libdl = cc.find_library('dl', required : false) + lua_dep = dependency('lua5.2', fallback: ['lua', 'lua_dep'], + default_options: ['shared=false', 'use_readline=false', 'app=false'] + ) + pcre2_dep = dependency('libpcre2-8') + sdl_dep = dependency('sdl2', method: 'config-tool') + reproc_dep = dependency('reproc', fallback: ['reproc', 'reproc_dep'], + default_options: [ + 'default_library=static', 'multithreaded=false', + 'reproc-cpp=false', 'examples=false' + ] + ) -lite_deps = [lua_dep, sdl_dep, reproc_dep, pcre2_dep, libm, libdl] + lite_deps = [lua_dep, sdl_dep, reproc_dep, pcre2_dep, libm, libdl] -if host_machine.system() == 'windows' - # Note that we need to explicitly add the windows socket DLL because - # the pkg-config file from reproc does not include it. - lite_deps += meson.get_compiler('cpp').find_library('ws2_32', required: true) + if host_machine.system() == 'windows' + # Note that we need to explicitly add the windows socket DLL because + # the pkg-config file from reproc does not include it. + lite_deps += meson.get_compiler('cpp').find_library('ws2_32', required: true) + endif endif #=============================================================================== # Install Configuration @@ -118,6 +120,8 @@ configure_file( #=============================================================================== # Targets #=============================================================================== -subdir('lib/font_renderer') -subdir('src') -subdir('scripts') +if not get_option('source-only') + subdir('lib/font_renderer') + subdir('src') + subdir('scripts') +endif diff --git a/meson_options.txt b/meson_options.txt index ce7eca98..1cf3e22f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,4 @@ option('bundle', type : 'boolean', value : false, description: 'Build a macOS bundle') +option('source-only', type : 'boolean', value : false, description: 'Configure source files only, doesn\'t checks for dependencies') option('portable', type : 'boolean', value : false, description: 'Portable install') option('renderer', type : 'boolean', value : false, description: 'Use SDL renderer') diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 00000000..a236599c --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,28 @@ +# Scripts + +Various scripts and configurations used to configure, build, and package Lite XL. + +### Build + +- **build.sh** +- **build-packages.sh**: In root directory, as all in one script; relies to the + ones in this directory. + +### Package + +- **appdmg.sh**: Create a macOS DMG image using [AppDMG][1]. +- **appimage.sh**: [AppImage][2] builder. +- **innosetup.sh**: Creates a 32/64 bit [InnoSetup][3] installer package. +- **package.sh**: Creates all binary / DMG image / installer / source packages. + +### Utility + +- **common.sh**: Common functions used by other scripts. +- **install-dependencies.sh**: Installs required applications to build, package + and run Lite XL, mainly useful for CI and documentation purpose. + Preferably not to be used in user systems. +- **fontello-config.json**: Used by the icons generator. + +[1]: https://github.com/LinusU/node-appdmg +[2]: https://docs.appimage.org/ +[3]: https://jrsoftware.org/isinfo.php diff --git a/scripts/appimage.sh b/scripts/appimage.sh index 65dce3c4..8844fafe 100644 --- a/scripts/appimage.sh +++ b/scripts/appimage.sh @@ -6,9 +6,11 @@ if [ ! -e "src/api/api.h" ]; then exit 1 fi +source scripts/common.sh + show_help(){ echo - echo $0 + echo "Usage: $0 " echo echo "Available options:" echo @@ -23,7 +25,7 @@ show_help(){ } ARCH="$(uname -m)" -BUILD_DIR=build +BUILD_DIR="$(get_default_build_dir)" RUN_BUILD=true STATIC_BUILD=false @@ -67,7 +69,7 @@ if [[ -n $1 ]]; then exit 1 fi -setup_appimagetool(){ +setup_appimagetool() { if ! which appimagetool > /dev/null ; then if [ ! -e appimagetool ]; then if ! wget -O appimagetool "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-${ARCH}.AppImage" ; then @@ -80,7 +82,7 @@ setup_appimagetool(){ fi } -download_appimage_apprun(){ +download_appimage_apprun() { if [ ! -e AppRun ]; then if ! wget -O AppRun "https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-${ARCH}" ; then echo "Could not download AppRun for the arch '${ARCH}'." @@ -91,7 +93,7 @@ download_appimage_apprun(){ fi } -build_litexl(){ +build_litexl() { if [ -e build ]; then rm -rf build fi @@ -106,7 +108,7 @@ build_litexl(){ meson compile -C ${BUILD_DIR} } -generate_appimage(){ +generate_appimage() { if [ -e LiteXL.AppDir ]; then rm -rf LiteXL.AppDir fi diff --git a/scripts/build.sh b/scripts/build.sh index b0e013b1..7ceb3ce4 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,103 +1,102 @@ #!/bin/bash -set -ex +set -e if [ ! -e "src/api/api.h" ]; then - echo "Please run this script from the root directory of Lite XL." - exit 1 + echo "Please run this script from the root directory of Lite XL."; exit 1 fi -show_help(){ +source scripts/common.sh + +show_help() { echo echo "Usage: $0 " echo echo "Available options:" echo echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." - echo " Default: 'build'." - echo "-p --prefix Install directory prefix. Mandatory." - echo "-s --static Specify if building using static libraries" - echo " by using lhelper tool." + echo " Default: '$(get_default_build_dir)'." + echo " --debug Debug this script." + echo "-f --forcefallback Force to build dependencies statically." + echo "-h --help Show this help and exit." + echo "-p --prefix PREFIX Install directory prefix. Default: '/'." + echo "-B --bundle Create an App bundle (macOS only)" + echo "-P --portable Create a portable binary package." + echo " macOS: disabled when used with --bundle," + echo " Windows: Implicit being the only option." echo } -install_lhelper() { - if [[ ! -d lhelper ]]; then - git clone https://github.com/franko/lhelper.git - pushd lhelper; bash install-github; popd +main() { + local platform="$(get_platform_name)" + local build_dir="$(get_default_build_dir)" + local prefix=/ + local force_fallback + local bundle + local portable - if [[ "$OSTYPE" == "darwin"* ]]; then - CC=clang CXX=clang++ lhelper create lite-xl -n - else - lhelper create lite-xl -n - fi + for i in "$@"; do + case $i in + -h|--help) + show_help + exit 0 + ;; + -b|--builddir) + build_dir="$2" + shift + shift + ;; + --debug) + set -x + shift + ;; + -f|--forcefallback) + force_fallback="--wrap-mode=forcefallback" + shift + ;; + -p|--prefix) + prefix="$2" + shift + shift + ;; + -B|--bundle) + if [[ "$platform" != "macos" ]]; then + echo "Warning: ignoring --bundle option, works only under macOS." + else + bundle="-Dbundle=true" + fi + shift + ;; + -P|--portable) + portable="-Dportable=true" + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then + show_help + exit 1 fi - # Not using `lhelper activate lite-xl` - source "$(lhelper env-source lite-xl)" - - lhelper install freetype2 - lhelper install sdl2 2.0.14-wait-event-timeout-1 - lhelper install pcre2 - - # Help MSYS2 to find the SDL2 include and lib directories to avoid errors - # during build and linking when using lhelper. - if [[ "$OSTYPE" == "msys" ]]; then - CFLAGS=-I${LHELPER_ENV_PREFIX}/include/SDL2 - LDFLAGS=-L${LHELPER_ENV_PREFIX}/lib + if [[ $platform == "macos" && -n $bundle && -n $portable ]]; then + echo "Warning: \"bundle\" and \"portable\" specified; excluding portable package." + portable="" fi -} -build() { + rm -rf "${build_dir}" + CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS meson setup \ --buildtype=release \ - --prefix "$PREFIX" \ - --wrap-mode=forcefallback \ - "${BUILD_DIR}" + --prefix "$prefix" \ + $force_fallback \ + $bundle \ + $portable \ + "${build_dir}" - meson compile -C build + meson compile -C "${build_dir}" } -BUILD_DIR=build -STATIC_BUILD=false - -for i in "$@"; do - case $i in - -h|--belp) - show_help - exit 0 - ;; - -b|--builddir) - BUILD_DIR="$2" - shift - shift - ;; - -p|--prefix) - PREFIX="$2" - shift - shift - ;; - -s|--static) - STATIC_BUILD=true - shift - ;; - *) - # unknown option - ;; - esac -done - -if [[ -n $1 ]]; then - show_help - exit 1 -fi - -if [[ -z $PREFIX ]]; then - echo "ERROR: prefix argument is missing." - exit 1 -fi - -if [[ $STATIC_BUILD == true ]]; then - install_lhelper -fi - -build +main "$@" diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 00000000..2b49d362 --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -e + +get_platform_name() { + if [[ "$OSTYPE" == "msys" ]]; then + echo "windows" + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "macos" + elif [[ "$OSTYPE" == "linux"* || "$OSTYPE" == "freebsd"* ]]; then + echo "linux" + else + echo "UNSUPPORTED-OS" + fi +} + +get_default_build_dir() { + platform=$(get_platform_name) + echo "build-$platform-$(uname -m)" +} + +if [[ $(get_platform_name) == "UNSUPPORTED-OS" ]]; then + echo "Error: unknown OS type: \"$OSTYPE\"" + exit 1 +fi diff --git a/scripts/innosetup/innosetup.iss.in b/scripts/innosetup/innosetup.iss.in index 83a730d8..2b669fc0 100644 --- a/scripts/innosetup/innosetup.iss.in +++ b/scripts/innosetup/innosetup.iss.in @@ -9,7 +9,7 @@ ; Use /dArch option to create a setup for a different architecture, e.g.: ; iscc /dArch=x86 innosetup.iss #ifndef Arch -#define Arch "x64" + #define Arch "x64" #endif [Setup] @@ -27,8 +27,11 @@ AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} #if Arch=="x64" -ArchitecturesAllowed=x64 -ArchitecturesInstallIn64BitMode={#Arch} + ArchitecturesAllowed=x64 + ArchitecturesInstallIn64BitMode=x64 + #define ArchInternal "x86_64" +#else + #define ArchInternal "i686" #endif AllowNoIcons=yes @@ -48,7 +51,7 @@ PrivilegesRequiredOverridesAllowed=dialog UsedUserAreasWarning=no OutputDir=. -OutputBaseFilename=LiteXL-{#MyAppVersion}-{#Arch}-setup +OutputBaseFilename=LiteXL-{#MyAppVersion}-{#ArchInternal}-setup ;DisableDirPage=yes ;DisableProgramGroupPage=yes @@ -67,18 +70,16 @@ Name: "portablemode"; Description: "Portable Mode"; Flags: unchecked [Files] Source: "{#BuildDir}/src/lite-xl.exe"; DestDir: "{app}"; Flags: ignoreversion -; MSYS2 produces no external dlls on 32 bit builds when using lhelper -#if Arch=="x64" -Source: "{#BuildDir}/mingwLibs{#Arch}/*"; DestDir: "{app}"; Flags: ignoreversion -#endif +Source: "{#BuildDir}/mingwLibs{#Arch}/*"; DestDir: "{app}"; Flags: ignoreversion ; Check: DirExists(ExpandConstant('{#BuildDir}/mingwLibs{#Arch}')) Source: "{#SourceDir}/data/*"; DestDir: "{app}/data"; Flags: ignoreversion recursesubdirs ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] +Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Check: not WizardIsTaskSelected('portablemode') Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"; Check: not WizardIsTaskSelected('portablemode') -Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon; Check: not WizardIsTaskSelected('portablemode') +; Name: "{usersendto}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" [Run] Filename: "{app}/{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent diff --git a/scripts/innosetup/innosetup.sh b/scripts/innosetup/innosetup.sh index 44a6c787..4384d13c 100644 --- a/scripts/innosetup/innosetup.sh +++ b/scripts/innosetup/innosetup.sh @@ -1,55 +1,65 @@ #!/bin/bash -set -ex +set -e if [ ! -e "src/api/api.h" ]; then - echo "Please run this script from the root directory of Lite XL." - exit 1 + echo "Please run this script from the root directory of Lite XL."; exit 1 fi -show_help(){ +source scripts/common.sh + +show_help() { echo echo "Usage: $0 " echo echo "Available options:" echo echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." - echo " Default: 'build'." + echo " Default: '$(get_default_build_dir)'." + echo " --debug Debug this script." echo } -BUILD_DIR=build +main() { + local build_dir=$(get_default_build_dir) + local arch -for i in "$@"; do - case $i in - -h|--belp) - show_help - exit 0 - ;; - -b|--BUILD_DIR) - BUILD_DIR="$2" - shift - shift - ;; - *) - # unknown option - ;; - esac -done + if [[ $MSYSTEM == "MINGW64" ]]; then arch=x64; else arch=Win32; fi -if [[ -n $1 ]]; then - show_help - exit 1 -fi + for i in "$@"; do + case $i in + -h|--help) + show_help + exit 0 + ;; + -b|--builddir) + build_dir="$2" + shift + shift + ;; + --debug) + set -x + shift + ;; + *) + # unknown option + ;; + esac + done -# TODO: Required MinGW dlls are built only (?) when using lhelper on 64 bit -if [[ $MSYSTEM == "MINGW64" ]]; then - ARCH=x64; - mingwLibsDir=$BUILD_DIR/mingwLibs$ARCH + if [[ -n $1 ]]; then + show_help + exit 1 + fi + + # Copy MinGW libraries dependencies. + # MSYS2 ldd command seems to be only 64bit, so use ntldd + # see https://github.com/msys2/MINGW-packages/issues/4164 + local mingwLibsDir="${build_dir}/mingwLibs$arch" mkdir -p "$mingwLibsDir" - ldd "$BUILD_DIR/src/lite-xl.exe" | grep mingw | awk '{print $3}' | xargs -I '{}' cp -v '{}' $mingwLibsDir -else - ARCH=Win32 -fi + ntldd -R "${build_dir}/src/lite-xl.exe" | grep mingw | awk '{print $3}' | sed 's#\\#/#g' | xargs -I '{}' cp -v '{}' $mingwLibsDir -/c/Program\ Files\ \(x86\)/Inno\ Setup\ 6/ISCC.exe -dARCH=$ARCH $BUILD_DIR/scripts/innosetup.iss -mv $BUILD_DIR/LiteXL*.exe $(pwd) + "/c/Program Files (x86)/Inno Setup 6/ISCC.exe" -dARCH=$arch "${build_dir}/scripts/innosetup.iss" + pushd "${build_dir}/scripts"; mv LiteXL*.exe "./../../"; popd +} + +main "$@" diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh new file mode 100644 index 00000000..bad3b358 --- /dev/null +++ b/scripts/install-dependencies.sh @@ -0,0 +1,74 @@ +#!/bin/bash +set -ex + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL."; exit 1 +fi + +show_help() { + echo + echo "Lite XL dependecies installer. Mainly used for CI but can also work on users systems." + echo "USE IT AT YOUR OWN RISK!" + echo + echo "Usage: $0 " + echo + echo "Available options:" + echo + echo "-l --lhelper Install tools required by LHelper and doesn't" + echo " install external libraries." + echo " --debug Debug this script." + echo +} + +main() { + local lhelper=false + + for i in "$@"; do + case $i in + -s|--lhelper) + lhelper=true + shift + ;; + --debug) + set -x + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then + show_help + exit 1 + fi + + if [[ "$OSTYPE" == "linux"* ]]; then + if [[ $lhelper == true ]]; then + sudo apt-get install -qq ninja-build + else + sudo apt-get install -qq ninja-build libsdl2-dev libfreetype6 + fi + pip3 install meson + elif [[ "$OSTYPE" == "darwin"* ]]; then + if [[ $lhelper == true ]]; then + brew install bash md5sha1sum ninja + else + brew install ninja sdl2 + fi + pip3 install meson + cd ~; npm install appdmg; cd - + ~/node_modules/appdmg/bin/appdmg.js --version + elif [[ "$OSTYPE" == "msys" ]]; then + if [[ $lhelper == true ]]; then + pacman --noconfirm -S \ + ${MINGW_PACKAGE_PREFIX}-{gcc,meson,ninja,ntldd,pkg-config} unzip + else + pacman --noconfirm -S \ + ${MINGW_PACKAGE_PREFIX}-{gcc,meson,ninja,ntldd,pkg-config,freetype,pcre2,SDL2} unzip + fi + fi +} + +main "$@" diff --git a/scripts/lhelper.sh b/scripts/lhelper.sh new file mode 100644 index 00000000..af6ae158 --- /dev/null +++ b/scripts/lhelper.sh @@ -0,0 +1,75 @@ +#!/bin/bash +set -e + +show_help() { + echo + echo "Usage: $0 " + echo + echo "Available options:" + echo + echo " --debug Debug this script." + echo "-h --help Show this help and exit." + echo "-p --prefix PREFIX Install directory prefix." + echo " Default: '$HOME/.local'." + echo +} + +main() { + local lhelper_prefix="$HOME/.local" + + for i in "$@"; do + case $i in + -h|--help) + show_help + exit 0 + ;; + -p|--prefix) + lhelper_prefix="$2" + echo "LHelper prefix set to: \"${lhelper_prefix}\"" + shift + shift + ;; + --debug) + set -x + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then show_help; exit 1; fi + + if [[ ! -f ${lhelper_prefix}/bin/lhelper ]]; then + + git clone https://github.com/franko/lhelper.git + + # FIXME: This should be set in ~/.bash_profile if not using CI + # export PATH="${HOME}/.local/bin:${PATH}" + mkdir -p "${lhelper_prefix}/bin" + pushd lhelper; bash install "${lhelper_prefix}"; popd + + if [[ "$OSTYPE" == "darwin"* ]]; then + CC=clang CXX=clang++ lhelper create lite-xl -n + else + lhelper create lite-xl -n + fi + fi + + # Not using $(lhelper activate lite-xl) to support CI + source "$(lhelper env-source lite-xl)" + + lhelper install freetype2 + lhelper install sdl2 2.0.14-wait-event-timeout-1 + lhelper install pcre2 + + # Help MSYS2 to find the SDL2 include and lib directories to avoid errors + # during build and linking when using lhelper. + if [[ "$OSTYPE" == "msys" ]]; then + CFLAGS=-I${LHELPER_ENV_PREFIX}/include/SDL2 + LDFLAGS=-L${LHELPER_ENV_PREFIX}/lib + fi +} + +main diff --git a/scripts/msys2-package.sh b/scripts/msys2-package.sh deleted file mode 100644 index 5138d8a3..00000000 --- a/scripts/msys2-package.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -set -ex - -if [ ! -e "src/api/api.h" ]; then - echo "Please run this script from the root directory of Lite XL." - exit 1 -fi - -# FIXME: For some strange reason sometimes an error occurs randomly on the -# MINGW32 build of GitHub Actions; the environment variable $INSTALL_NAME -# is correct, but it expands with a drive letter at the end (all builds). - -show_help(){ - echo - echo "Usage: $0 " - echo - echo "Available options:" - echo - echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." - echo " Default: 'build'." - echo "-d --destdir DIRNAME Sets the name of the install directory (not path)." - echo -} - -BUILD_DIR=build - -for i in "$@"; do - case $i in - -h|--belp) - show_help - exit 0 - ;; - -b|--builddir) - BUILD_DIR="$2" - shift - shift - ;; - -d|--destdir) - DEST_DIR="$2" - shift - shift - ;; - *) - # unknown option - ;; - esac -done - -if [[ -n $1 ]]; then - show_help - exit 1 -fi - -DESTDIR="$(pwd)/${DEST_DIR}" meson install --skip-subprojects -C ${BUILD_DIR} - -zip -9rv ${DEST_DIR}.zip ${DEST_DIR}/* diff --git a/scripts/package.sh b/scripts/package.sh new file mode 100644 index 00000000..b014c41c --- /dev/null +++ b/scripts/package.sh @@ -0,0 +1,252 @@ +#!/bin/bash +set -e + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL."; exit 1 +fi + +source scripts/common.sh + +show_help() { + echo + echo "Usage: $0 " + echo + echo "Available options:" + echo + echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." + echo " Default: '$(get_default_build_dir)'." + echo "-d --destdir DIRNAME Set the name of the package directory (not path)." + echo " Default: 'lite-xl'." + echo "-h --help Show this help and exit." + echo "-p --prefix PREFIX Install directory prefix. Default: '/'." + echo "-v --version VERSION Sets the version on the package name." + echo " --addons Install 3rd party addons (currently RXI colors)." + echo " --debug Debug this script." + echo "-A --appimage Create an AppImage (Linux only)." + echo "-B --binary Create a normal / portable package or macOS bundle," + echo " depending on how the build was configured. (Default.)" + echo "-D --dmg Create a DMG disk image with AppDMG (macOS only)." + echo "-I --innosetup Create a InnoSetup package (Windows only)." + echo "-S --source Create a source code package," + echo " including subprojects dependencies." + echo +} + +# Addons installation: some distributions forbid external downloads +# so make it as optional module. +install_addons() { + local build_dir="$1" + local data_dir="$2" + + if [[ -d "${build_dir}/third/data/colors" ]]; then + echo "Warning: found previous colors addons installation, skipping." + return 0 + fi + + # Copy third party color themes + curl --insecure \ + -L "https://github.com/rxi/lite-colors/archive/master.zip" \ + -o "${build_dir}/rxi-lite-colors.zip" + + mkdir -p "${build_dir}/third/data/colors" + unzip "${build_dir}/rxi-lite-colors.zip" -d "${build_dir}" + mv "${build_dir}/lite-colors-master/colors" "${build_dir}/third/data" + rm -rf "${build_dir}/lite-colors-master" + + for module_name in colors; do + cp -r "${build_dir}/third/data/$module_name" "${data_dir}" + done +} + +source_package() { + local build_dir=build-src + local package_name=$1 + + rm -rf ${build_dir} + rm -rf ${package_name} + rm -f ${package_name}.tar.gz + + meson subprojects download + meson setup ${build_dir} -Dsource-only=true + + # Note: not using git-archive(-all) because it can't include subprojects ignored by git + rsync -arv \ + --exclude /*build*/ \ + --exclude *.git* \ + --exclude lhelper \ + --exclude lite-xl* \ + --exclude submodules \ + . ${package_name} + + cp "${build_dir}/start.lua" "${package_name}/data/core" + + tar rf ${package_name}.tar ${package_name} + gzip -9 ${package_name}.tar +} + +main() { + local arch="$(uname -m)" + local platform="$(get_platform_name)" + local build_dir="$(get_default_build_dir)" + local dest_dir=lite-xl + local prefix=/ + local version + local addons=false + local appimage=false + local binary=false + local dmg=false + local innosetup=false + local source=false + + for i in "$@"; do + case $i in + -b|--builddir) + build_dir="$2" + shift + shift + ;; + -d|--destdir) + dest_dir="$2" + shift + shift + ;; + -h|--help) + show_help + exit 0 + ;; + -p|--prefix) + prefix="$2" + shift + shift + ;; + -v|--version) + if [[ -n $2 ]]; then version="-$2"; fi + shift + shift + ;; + -A|--appimage) + if [[ "$platform" != "linux" ]]; then + echo "Warning: ignoring --appimage option, works only under Linux." + else + appimage=true + fi + shift + ;; + -B|--binary) + binary=true + shift + ;; + -D|--dmg) + if [[ "$platform" != "macos" ]]; then + echo "Warning: ignoring --dmg option, works only under macOS." + else + dmg=true + fi + shift + ;; + -I|--innosetup) + if [[ "$platform" != "windows" ]]; then + echo "Warning: ignoring --innosetup option, works only under Windows." + else + innosetup=true + fi + shift + ;; + -S|--source) + source=true + shift + ;; + --addons) + addons=true + shift + ;; + --debug) + set -x + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then show_help; exit 1; fi + + # The source package doesn't require a previous build, + # nor the following install step, so run it now. + if [[ $source == true ]]; then source_package "lite-xl$version-src"; fi + + # No packages request + if [[ $appimage == false && $binary == false && $dmg == false && $innosetup == false ]]; then + # Source only, return. + if [[ $source == true ]]; then return 0; fi + # Build the binary package as default instead doing nothing. + binary=true + fi + + rm -rf "${dest_dir}" + + DESTDIR="$(pwd)/${dest_dir}" meson install -C "${build_dir}" + + local data_dir="$(pwd)/${dest_dir}/data" + local exe_file="$(pwd)/${dest_dir}/lite-xl" + local package_name=lite-xl$version-$platform-$arch + local bundle=false + local stripcmd="strip" + + if [[ -d "${data_dir}" ]]; then + # Portable archive + exe_file="$(pwd)/${dest_dir}/lite-xl" + if [[ $platform == "windows" ]]; then + exe_file="${exe_file}.exe" + stripcmd="strip --strip-all" + else + # Windows archive is always portable + package_name+="-portable" + fi + elif [[ $platform == "macos" && ! -d "${data_dir}" ]]; then + # macOS bundle app + bundle=true + # Specify "bundle" on compressed archive only, implicit on images + if [[ $dmg == false ]]; then package_name+="-bundle"; fi + rm -rf "Lite XL.app"; mv "${dest_dir}" "Lite XL.app" + dest_dir="Lite XL.app" + data_dir="$(pwd)/${dest_dir}/Contents/Resources" + exe_file="$(pwd)/${dest_dir}/Contents/MacOS/lite-xl" + else + data_dir="$(pwd)/${dest_dir}/$prefix/share/lite-xl" + exe_file="$(pwd)/${dest_dir}/$prefix/bin/lite-xl" + fi + + mkdir -p "${data_dir}" + + if [[ $addons == true ]]; then install_addons "${build_dir}" "${data_dir}"; fi + + # TODO: use --skip-subprojects when 0.58.0 will be available on supported + # distributions to avoid subprojects' include and lib directories to be copied. + # Install Meson with PIP to get the latest version is not always possible. + pushd "${dest_dir}" + find . -type d -name 'include' -prune -exec rm -rf {} \; + find . -type d -name 'lib' -prune -exec rm -rf {} \; + find . -type d -empty -delete + popd + + $stripcmd "${exe_file}" + + if [[ $binary == true ]]; then + rm -f "${package_name}".tar.gz + rm -f "${package_name}".zip + + if [[ $platform == "windows" ]]; then + zip -9rv ${package_name}.zip ${dest_dir}/* + else + tar czvf "${package_name}".tar.gz "${dest_dir}" + fi + fi + + if [[ $appimage == true ]]; then source scripts/appimage.sh; fi + if [[ $bundle == true && $dmg == true ]]; then source scripts/appdmg.sh "${package_name}"; fi + if [[ $innosetup == true ]]; then source scripts/innosetup/innosetup.sh -b "${build_dir}"; fi +} + +main "$@" diff --git a/scripts/source-package.sh b/scripts/source-package.sh deleted file mode 100644 index aff80c9d..00000000 --- a/scripts/source-package.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -set -ex - -if [ ! -e "src/api/api.h" ]; then - echo "Please run this script from the root directory of Lite XL." - exit 1 -fi - -show_help(){ - echo - echo "Usage: $0 " - echo - echo "Available options:" - echo - echo "-b --builddir DIRNAME Sets the name of the build directory (no path)." - echo " Default: 'build'." - echo "-d --destdir DIRNAME Sets the name of the install directory (no path)." - echo -} - -BUILD_DIR=build -DEST_DIR=lite-xl-src - -for i in "$@"; do - case $i in - -h|--belp) - show_help - exit 0 - ;; - -b|--builddir) - BUILD_DIR="$2" - shift - shift - ;; - -d|--destdir) - DEST_DIR="$2" - shift - shift - ;; - *) - # unknown option - ;; - esac -done - -if [[ -n $1 ]]; then - show_help - exit 1 -fi - -if test -d ${BUILD_DIR}; then rm -rf ${BUILD_DIR}; fi -if test -d ${DEST_DIR}; then rm -rf ${DEST_DIR}; fi -if test -f ${DEST_DIR}.tar.gz; then rm ${DEST_DIR}.tar.gz; fi - -meson subprojects download -meson setup ${BUILD_DIR} - -rsync -arv \ - --exclude /*build*/ \ - --exclude *.git* \ - --exclude lhelper \ - --exclude lite-xl* \ - --exclude submodules \ - . ${DEST_DIR} - -cp "${BUILD_DIR}/start.lua" "${DEST_DIR}/data/core" - -tar rf ${DEST_DIR}.tar ${DEST_DIR} -gzip -9 ${DEST_DIR}.tar From b4080ba14831d3a1bfa4ef198811a2cfb1e7ce22 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 5 Sep 2021 15:43:22 +0200 Subject: [PATCH 40/62] Bring back pgo option in new build package script --- build-packages.sh | 10 +++++++++- scripts/build.sh | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/build-packages.sh b/build-packages.sh index 6014be96..4ecda0a0 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -25,6 +25,8 @@ show_help() { echo "-f --forcefallback Force to build subprojects dependencies statically." echo "-B --bundle Create an App bundle (macOS only)" echo "-P --portable Create a portable package." + echo "-O --pgo Use profile guided optimizations (pgo)." + echo " Requires running the application iteractively." echo echo "Package options:" echo @@ -55,6 +57,7 @@ main() { local bundle local innosetup local portable + local pgo for i in "$@"; do case $i in @@ -110,6 +113,10 @@ main() { source="--source" shift ;; + -O|--pgo) + pgo="--pgo" + shift + ;; --debug) debug="--debug" set -x @@ -137,7 +144,8 @@ main() { $debug \ $force_fallback \ $bundle \ - $portable + $portable \ + $pgo source scripts/package.sh \ ${build_dir_option[@]} \ diff --git a/scripts/build.sh b/scripts/build.sh index 7ceb3ce4..75212468 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -21,6 +21,7 @@ show_help() { echo "-p --prefix PREFIX Install directory prefix. Default: '/'." echo "-B --bundle Create an App bundle (macOS only)" echo "-P --portable Create a portable binary package." + echo "-O --pgo Use profile guided optimizations (pgo)." echo " macOS: disabled when used with --bundle," echo " Windows: Implicit being the only option." echo @@ -33,6 +34,7 @@ main() { local force_fallback local bundle local portable + local pgo for i in "$@"; do case $i in @@ -70,6 +72,10 @@ main() { portable="-Dportable=true" shift ;; + -O|--pgo) + pgo="-Db_pgo=generate" + shift + ;; *) # unknown option ;; @@ -94,9 +100,18 @@ main() { $force_fallback \ $bundle \ $portable \ + $pgo \ "${build_dir}" meson compile -C "${build_dir}" + + if [ ! -z ${pgo+x} ]; then + cp -r data "${build_dir}/src" + "${build_dir}/src/lite-xl" + meson configure -Db_pgo=use "${build_dir}" + meson compile -C "${build_dir}" + rm -fr "${build_dir}/data" + fi } main "$@" From aa9e2e2df516bf2204c3c8dce380c3a3c9bee656 Mon Sep 17 00:00:00 2001 From: redtide Date: Sun, 5 Sep 2021 19:29:17 +0200 Subject: [PATCH 41/62] Fixed some build scripts issues, keep bash always updated on macOS --- scripts/install-dependencies.sh | 2 +- scripts/package.sh | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh index bad3b358..2f9519b1 100644 --- a/scripts/install-dependencies.sh +++ b/scripts/install-dependencies.sh @@ -55,7 +55,7 @@ main() { if [[ $lhelper == true ]]; then brew install bash md5sha1sum ninja else - brew install ninja sdl2 + brew install bash ninja sdl2 fi pip3 install meson cd ~; npm install appdmg; cd - diff --git a/scripts/package.sh b/scripts/package.sh index b014c41c..1370aee8 100644 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -192,10 +192,12 @@ main() { local exe_file="$(pwd)/${dest_dir}/lite-xl" local package_name=lite-xl$version-$platform-$arch local bundle=false + local portable=false local stripcmd="strip" if [[ -d "${data_dir}" ]]; then - # Portable archive + echo "Creating a portable, compressed archive..." + portable=true exe_file="$(pwd)/${dest_dir}/lite-xl" if [[ $platform == "windows" ]]; then exe_file="${exe_file}.exe" @@ -205,15 +207,20 @@ main() { package_name+="-portable" fi elif [[ $platform == "macos" && ! -d "${data_dir}" ]]; then - # macOS bundle app - bundle=true - # Specify "bundle" on compressed archive only, implicit on images - if [[ $dmg == false ]]; then package_name+="-bundle"; fi - rm -rf "Lite XL.app"; mv "${dest_dir}" "Lite XL.app" - dest_dir="Lite XL.app" data_dir="$(pwd)/${dest_dir}/Contents/Resources" - exe_file="$(pwd)/${dest_dir}/Contents/MacOS/lite-xl" - else + if [[ -d "${data_dir}" ]]; then + echo "Creating a macOS bundle application..." + bundle=true + # Specify "bundle" on compressed archive only, implicit on images + if [[ $dmg == false ]]; then package_name+="-bundle"; fi + rm -rf "Lite XL.app"; mv "${dest_dir}" "Lite XL.app" + dest_dir="Lite XL.app" + exe_file="$(pwd)/${dest_dir}/Contents/MacOS/lite-xl" + fi + fi + + if [[ $bundle == false && $portable == false ]]; then + echo "Creating a compressed archive..." data_dir="$(pwd)/${dest_dir}/$prefix/share/lite-xl" exe_file="$(pwd)/${dest_dir}/$prefix/bin/lite-xl" fi From 90c721b823eec21930ddb91d486f1858d4cbf93c Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 15:11:20 +0200 Subject: [PATCH 42/62] Adopt bigger fonts by default --- data/core/init.lua | 4 ++-- data/core/style.lua | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 6b770fd6..018beadb 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -320,8 +320,8 @@ local style = require "core.style" ------------------------------- Fonts ---------------------------------------- -- customize fonts: --- style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 13 * SCALE) --- style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 13 * SCALE) +-- style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 14 * SCALE) +-- style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 14 * SCALE) -- -- font names used by lite: -- style.font : user interface diff --git a/data/core/style.lua b/data/core/style.lua index 7cf16eb1..faca166e 100644 --- a/data/core/style.lua +++ b/data/core/style.lua @@ -21,11 +21,11 @@ style.tab_width = common.round(170 * SCALE) -- -- On High DPI monitor or non RGB monitor you may consider using antialiasing grayscale instead. -- The antialiasing grayscale with full hinting is interesting for crisp font rendering. -style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 13 * SCALE) +style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 14 * SCALE) style.big_font = style.font:copy(40 * SCALE) -style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 14 * SCALE, {antialiasing="grayscale", hinting="full"}) -style.icon_big_font = style.icon_font:copy(20 * SCALE) -style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 13 * SCALE) +style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 16 * SCALE, {antialiasing="grayscale", hinting="full"}) +style.icon_big_font = style.icon_font:copy(24 * SCALE) +style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 14 * SCALE) style.background = { common.color "#2e2e32" } style.background2 = { common.color "#252529" } From 67d7b894ae90e04413a2075d5e2f7cf4a8976bef Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 15:23:41 +0200 Subject: [PATCH 43/62] Add initial suggestion in open-project-folder --- data/core/commands/core.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 215ff654..432ded89 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -164,6 +164,10 @@ command.add(nil, { end, ["core:open-project-folder"] = function() + local dirname = common.dirname(core.project_dir) + if dirname then + core.command_view:set_text(common.home_encode(dirname) .. PATHSEP) + end core.command_view:enter("Open Project", function(text, item) text = common.home_expand(item and item.text or text) local path_stat = system.get_file_info(text) From 2b277bb50224fdc52aa76c838b66640010dfa4bb Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 06:44:15 -0700 Subject: [PATCH 44/62] Fix problem with -psn argument on macOS --- data/core/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index 018beadb..e84792ac 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -461,7 +461,10 @@ function core.init() project_dir = arg_filename project_dir_explicit = true else - delayed_error = string.format("error: invalid file or directory %q", ARGS[i]) + -- on macOS we can get an argument like "-psn_0_52353" that we just ignore. + if not ARGS[i]:match("^-psn") then + delayed_error = string.format("error: invalid file or directory %q", ARGS[i]) + end end end From 0a36e66abaa908fe84306938db178431c81ce25b Mon Sep 17 00:00:00 2001 From: Guldoman Date: Tue, 7 Sep 2021 22:14:40 +0200 Subject: [PATCH 45/62] Fix `treeview:open-in-system` command on Windows The first argument is the title for the `CMD` window. --- data/plugins/treeview.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 48d6f5a7..84d5dd28 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -536,7 +536,7 @@ command.add(function() return view.hovered_item ~= nil end, { local hovered_item = view.hovered_item if PLATFORM == "Windows" then - system.exec("start " .. hovered_item.abs_filename) + system.exec(string.format("start \"\" %q", hovered_item.abs_filename)) elseif string.find(PLATFORM, "Mac") then system.exec(string.format("open %q", hovered_item.abs_filename)) elseif PLATFORM == "Linux" then From 48c709a95fc2e84e12f667c20349e7de0d6022a2 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 22:46:58 +0200 Subject: [PATCH 46/62] Prepare 2.0.2 version and changelog --- changelog.md | 35 +++++++++++++++++++++++++++++++++++ meson.build | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index d6e30519..2cf29061 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,40 @@ This files document the changes done in Lite XL for each release. +### 2.0.2 + +Fix problem project directory when starting the application from Launcher on macOS. + +Improved LogView by @takase1121. + +Fix problem when trying to close an unsaved new document. +Fix `treeview:open-in-system` command on Windows. +Fix rename command to update name of document if opened. +Contributed by @Guldoman. + +Improve the find and replace dialog so that previously used expressions can be recalled +using "up" and "down" keys. + +Multi-cursors fixes and improvement by @adamharrison. + +Build package script rewrite and enhancement by @redtide. + +Use bigger fonts by default. + +Other minor improvements and fixes. + +### 2.0.1 + +Fix a few bugs and we mandate the mod-version 2 for plugins. +This means that users should ensure they have up-to-date plugins for Lite XL 2.0. + +Here some details about the bug fixes: + +- fix a bug that created a fatal error when using the command to change project folder or when closing all the active documents +- add a limit to avoid scaling fonts too much and fix a related invalid memory access for very small fonts +- fix focus problem with NagView when switching project directory +- fix error that prevented the verification of plugins versions +- fix error on X11 that caused a bug window event on exit + ### 2.0 The 2.0 version of lite contains *breaking changes* to lite, in terms of how plugin settings are structured; diff --git a/meson.build b/meson.build index 9d3eac31..047ce90e 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('lite-xl', ['c', 'cpp'], - version : '2.0.1', + version : '2.0.2', license : 'MIT', meson_version : '>= 0.54', default_options : ['c_std=gnu11', 'cpp_std=c++03'] From 16170e8db9628d83b80fa24f077ea2b9fdef574f Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 8 Sep 2021 10:27:45 +0200 Subject: [PATCH 47/62] Improve info.plist for macOS package config As suggested by @redtide and @Timofffee. --- resources/macos/Info.plist.in | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/resources/macos/Info.plist.in b/resources/macos/Info.plist.in index c15fd566..4d715f2f 100644 --- a/resources/macos/Info.plist.in +++ b/resources/macos/Info.plist.in @@ -2,24 +2,28 @@ -CFBundleExecutable + CFBundleExecutable lite-xl CFBundleGetInfoString lite-xl CFBundleIconFile - icon + icon.icns CFBundleName - lite-xl + Lite XL CFBundlePackageType APPL NSHighResolutionCapable - LSMinimumSystemVersion10.11 - NSDocumentsFolderUsageDescriptionTo access, edit and index your projects. - NSDesktopFolderUsageDescriptionTo access, edit and index your projects. - NSDownloadsFolderUsageDescriptionTo access, edit and index your projects. + LSMinimumSystemVersion + 10.11 + NSDocumentsFolderUsageDescription + To access, edit and index your projects. + NSDesktopFolderUsageDescription + To access, edit and index your projects. + NSDownloadsFolderUsageDescription + To access, edit and index your projects. CFBundleShortVersionString - @PROJECT_VERSION@ + @PROJECT_VERSION@ NSHumanReadableCopyright © 2019-2021 Francesco Abbate From dfb64fbdf196aa85ef8b41ec279d372b15badec9 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 9 Sep 2021 15:39:41 +0200 Subject: [PATCH 48/62] Do not add selection with newlines in replace If the selected text containes newlines it doesn't make sense to use it as the initial text in the "replace text" command view. Do not use the selected text if a newline is found in the selection. Fix #511. --- data/core/commands/findreplace.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 48cbecaf..03aa7737 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -135,7 +135,9 @@ command.add("core.docview", { end, ["find-replace:replace"] = function() - replace("Text", doc():get_text(doc():get_selection(true)), function(text, old, new) + local selected_text = doc():get_text(doc():get_selection()) + local has_newlines = selected_text:find("\n", 1, true) + replace("Text", has_newlines and "" or selected_text, function(text, old, new) if not find_regex then return text:gsub(old:gsub("%W", "%%%1"), new:gsub("%%", "%%%%"), nil) end From f85fe102d99aa6af042ac1f6f7855bfaf7c07f92 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 17:06:19 +0200 Subject: [PATCH 49/62] Implement hidden suggestions for find dialog --- data/core/commands/findreplace.lua | 5 ++++- data/core/commandview.lua | 23 +++++++++++++++++++---- data/core/init.lua | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 03aa7737..73a5ae07 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -49,7 +49,9 @@ local function find(label, search_fn) core.command_view:set_text(text, true) core.status_view:show_tooltip(get_find_tooltip()) - core.command_view:enter(label, function(text) + core.command_view:set_hidden_suggestions() + core.command_view:enter(label, function(text, item) + table.insert(core.previous_find, text) core.status_view:remove_tooltip() if found then last_fn, last_text = search_fn, text @@ -61,6 +63,7 @@ local function find(label, search_fn) end, function(text) found = update_preview(last_sel, search_fn, text) last_fn, last_text = search_fn, text + return core.previous_find end, function(explicit) core.status_view:remove_tooltip() if explicit then diff --git a/data/core/commandview.lua b/data/core/commandview.lua index eb7febc7..d41db0d5 100644 --- a/data/core/commandview.lua +++ b/data/core/commandview.lua @@ -34,6 +34,7 @@ function CommandView:new() self.suggestion_idx = 1 self.suggestions = {} self.suggestions_height = 0 + self.show_suggestions = true self.last_change_id = 0 self.gutter_width = 0 self.gutter_text_brightness = 0 @@ -45,6 +46,11 @@ function CommandView:new() end +function CommandView:set_hidden_suggestions() + self.show_suggestions = false +end + + function CommandView:get_name() return View.get_name(self) end @@ -83,10 +89,16 @@ end function CommandView:move_suggestion_idx(dir) - local n = self.suggestion_idx + dir - self.suggestion_idx = common.clamp(n, 1, #self.suggestions) + local current_suggestion = self.suggestions[self.suggestion_idx].text + if self.show_suggestions or self:get_text() == current_suggestion then + local n = self.suggestion_idx + dir + self.suggestion_idx = common.clamp(n, 1, #self.suggestions) + end self:complete() self.last_change_id = self.doc:get_change_id() + if not self.show_suggestions then + self.state.suggest(self:get_text()) + end end @@ -134,6 +146,7 @@ function CommandView:exit(submitted, inexplicit) self.doc:reset() self.suggestions = {} if not submitted then cancel(not inexplicit) end + self.show_suggestions = true end @@ -187,7 +200,7 @@ function CommandView:update() -- update suggestions box height local lh = self:get_suggestion_line_height() - local dest = math.min(#self.suggestions, max_suggestions) * lh + local dest = self.show_suggestions and math.min(#self.suggestions, max_suggestions) * lh or 0 self:move_towards("suggestions_height", dest) -- update suggestion cursor offset @@ -256,7 +269,9 @@ end function CommandView:draw() CommandView.super.draw(self) - core.root_view:defer_draw(draw_suggestions_box, self) + if self.show_suggestions then + core.root_view:defer_draw(draw_suggestions_box, self) + end end diff --git a/data/core/init.lua b/data/core/init.lua index e84792ac..b1072b38 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -496,6 +496,7 @@ function core.init() core.redraw = true core.visited_files = {} + core.previous_find = {} core.restart_request = false core.quit_request = false core.replacements = whitespace_replacements() From 4bcc1cc07c76cfdac92aba13322e0d5687dd8f1a Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 18:07:26 +0200 Subject: [PATCH 50/62] Fix error with hidden suggestions Avoid indexing a nil if there are no suggestions. --- data/core/commandview.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/commandview.lua b/data/core/commandview.lua index d41db0d5..5ccb8d3a 100644 --- a/data/core/commandview.lua +++ b/data/core/commandview.lua @@ -89,7 +89,7 @@ end function CommandView:move_suggestion_idx(dir) - local current_suggestion = self.suggestions[self.suggestion_idx].text + local current_suggestion = #self.suggestions > 0 and self.suggestions[self.suggestion_idx].text if self.show_suggestions or self:get_text() == current_suggestion then local n = self.suggestion_idx + dir self.suggestion_idx = common.clamp(n, 1, #self.suggestions) From fa8b3b33b180d265f472877a23fb8df9a9eca191 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 18:08:54 +0200 Subject: [PATCH 51/62] Use hidden suggestions also for replace dialog --- data/core/commands/findreplace.lua | 7 +++++-- data/core/init.lua | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 73a5ae07..7027f293 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -78,19 +78,22 @@ local function replace(kind, default, fn) core.command_view:set_text(default, true) core.status_view:show_tooltip(get_find_tooltip()) + core.command_view:set_hidden_suggestions() core.command_view:enter("Find To Replace " .. kind, function(old) core.command_view:set_text(old, true) local s = string.format("Replace %s %q With", kind, old) + core.command_view:set_hidden_suggestions() core.command_view:enter(s, function(new) + table.insert(core.previous_replace, new) local n = doc():replace(function(text) return fn(text, old, new) end) core.log("Replaced %d instance(s) of %s %q with %q", n, kind, old, new) - end, function() end, function() + end, function() return core.previous_replace end, function() core.status_view:remove_tooltip() end) - end, function() end, function() + end, function() return core.previous_find end, function() core.status_view:remove_tooltip() end) end diff --git a/data/core/init.lua b/data/core/init.lua index b1072b38..1978ce38 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -497,6 +497,7 @@ function core.init() core.redraw = true core.visited_files = {} core.previous_find = {} + core.previous_replace = {} core.restart_request = false core.quit_request = false core.replacements = whitespace_replacements() From b440a2258118c916dfec657c676befca53e108ac Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 18:33:58 +0200 Subject: [PATCH 52/62] Remeber initial user text for hidden suggestions When using hidden suggestions remember the text user was typing when navigating suggestions. Ensure also that in the previously searched expressiosn we have no duplicate entries. --- data/core/commands/findreplace.lua | 15 +++++++++++++-- data/core/commandview.lua | 26 ++++++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 7027f293..56761690 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -41,6 +41,16 @@ local function update_preview(sel, search_fn, text) end end + +local function insert_unique(t, v) + local n = #t + for i = 1, n do + if t[i] == v then return end + end + t[n + 1] = v +end + + local function find(label, search_fn) last_view, last_sel, last_finds = core.active_view, { core.active_view.doc:get_selection() }, {} @@ -51,7 +61,7 @@ local function find(label, search_fn) core.command_view:set_hidden_suggestions() core.command_view:enter(label, function(text, item) - table.insert(core.previous_find, text) + insert_unique(core.previous_find, text) core.status_view:remove_tooltip() if found then last_fn, last_text = search_fn, text @@ -80,12 +90,13 @@ local function replace(kind, default, fn) core.status_view:show_tooltip(get_find_tooltip()) core.command_view:set_hidden_suggestions() core.command_view:enter("Find To Replace " .. kind, function(old) + insert_unique(core.previous_find, old) core.command_view:set_text(old, true) local s = string.format("Replace %s %q With", kind, old) core.command_view:set_hidden_suggestions() core.command_view:enter(s, function(new) - table.insert(core.previous_replace, new) + insert_unique(core.previous_replace, new) local n = doc():replace(function(text) return fn(text, old, new) end) diff --git a/data/core/commandview.lua b/data/core/commandview.lua index 5ccb8d3a..b91f1394 100644 --- a/data/core/commandview.lua +++ b/data/core/commandview.lua @@ -89,14 +89,27 @@ end function CommandView:move_suggestion_idx(dir) - local current_suggestion = #self.suggestions > 0 and self.suggestions[self.suggestion_idx].text - if self.show_suggestions or self:get_text() == current_suggestion then + if self.show_suggestions then local n = self.suggestion_idx + dir self.suggestion_idx = common.clamp(n, 1, #self.suggestions) - end - self:complete() - self.last_change_id = self.doc:get_change_id() - if not self.show_suggestions then + self:complete() + self.last_change_id = self.doc:get_change_id() + else + local current_suggestion = #self.suggestions > 0 and self.suggestions[self.suggestion_idx].text + local text = self:get_text() + if text == current_suggestion then + local n = self.suggestion_idx + dir + if n == 0 and self.save_suggestion then + self:set_text(self.save_suggestion) + else + self.suggestion_idx = common.clamp(n, 1, #self.suggestions) + self:complete() + end + else + self.save_suggestion = text + self:complete() + end + self.last_change_id = self.doc:get_change_id() self.state.suggest(self:get_text()) end end @@ -147,6 +160,7 @@ function CommandView:exit(submitted, inexplicit) self.suggestions = {} if not submitted then cancel(not inexplicit) end self.show_suggestions = true + self.save_suggestion = nil end From 403b7f6fb6d619f920e350ed9bb468dbb8300eb3 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 18:42:36 +0200 Subject: [PATCH 53/62] Add missing remove tooltip call --- data/core/commands/findreplace.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 56761690..f41a748a 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -96,6 +96,7 @@ local function replace(kind, default, fn) local s = string.format("Replace %s %q With", kind, old) core.command_view:set_hidden_suggestions() core.command_view:enter(s, function(new) + core.status_view:remove_tooltip() insert_unique(core.previous_replace, new) local n = doc():replace(function(text) return fn(text, old, new) From 04250a206a64bec1e207d2dfa74c36862a52daea Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 7 Sep 2021 22:31:36 +0200 Subject: [PATCH 54/62] Add previous find and replace in session --- data/core/init.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 1978ce38..af291767 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -17,10 +17,7 @@ local core = {} local function load_session() local ok, t = pcall(dofile, USERDIR .. "/session.lua") - if ok and t then - return t.recents, t.window, t.window_mode - end - return {} + return ok and t or {} end @@ -30,6 +27,8 @@ local function save_session() fp:write("return {recents=", common.serialize(core.recent_projects), ", window=", common.serialize(table.pack(system.get_window_size())), ", window_mode=", common.serialize(system.get_window_mode()), + ", previous_find=", common.serialize(core.previous_find), + ", previous_replace=", common.serialize(core.previous_replace), "}\n") fp:close() end @@ -435,13 +434,15 @@ function core.init() end do - local recent_projects, window_position, window_mode = load_session() - if window_mode == "normal" then - system.set_window_size(table.unpack(window_position)) - elseif window_mode == "maximized" then + local session = load_session() + if session.window_mode == "normal" then + system.set_window_size(table.unpack(session.window)) + elseif session.window_mode == "maximized" then system.set_window_mode("maximized") end - core.recent_projects = recent_projects or {} + core.recent_projects = session.recents or {} + core.previous_find = session.previous_find or {} + core.previous_replace = session.previous_replace or {} end local project_dir = core.recent_projects[1] or "." @@ -496,8 +497,6 @@ function core.init() core.redraw = true core.visited_files = {} - core.previous_find = {} - core.previous_replace = {} core.restart_request = false core.quit_request = false core.replacements = whitespace_replacements() From aa0e083cb9d0399cb3aafdfd4735ffbe5394e6c7 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 8 Sep 2021 22:47:37 +0200 Subject: [PATCH 55/62] Allow `find-replace:select-next` to select more occurrences after wrap The initial position for the search is defined by the last selection towards the end of the file. After reaching the end of the file, it would always select the same selection to start the search from. Now, we start the search from each selection, until a new occurrence is found. --- data/core/commands/findreplace.lua | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index f41a748a..902623be 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -126,6 +126,20 @@ local function has_unique_selection() return text ~= nil end +local function is_in_selection(line, col, l1, c1, l2, c2) + if line < l1 or line > l2 then return false end + if line == l1 and col <= c1 then return false end + if line == l2 and col > c2 then return false end + return true +end + +local function is_in_any_selection(line, col) + for idx, l1, c1, l2, c2 in doc():get_selections(true, false) do + if is_in_selection(line, col, l1, c1, l2, c2) then return true end + end + return false +end + local function select_next(all) local il1, ic1 = doc():get_selection(true) for idx, l1, c1, l2, c2 in doc():get_selections(true, true) do @@ -133,9 +147,15 @@ local function select_next(all) repeat l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true }) if l1 == il1 and c1 == ic1 then break end - if l2 then doc():add_selection(l2, c2, l1, c1) end + if l2 and (all or not is_in_any_selection(l2, c2)) then + doc():add_selection(l2, c2, l1, c1) + if not all then + core.active_view:scroll_to_make_visible(l2, c2) + return + end + end until not all or not l2 - break + if all then break end end end From d9afc40a174122485dec73d2025fd8079fb58c88 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 9 Sep 2021 19:12:56 +0200 Subject: [PATCH 56/62] Bring back command find-replace:select-next Bring back the command like before to keep single selection but with ctrl+f3 keybindings. Change the name of the new multi-cursor command but keep the ctrl+d keybinding. --- changelog.md | 3 +++ data/core/commands/findreplace.lua | 10 ++++++++-- data/core/keymap-macos.lua | 5 +++-- data/core/keymap.lua | 5 +++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 2cf29061..5ea7b87c 100644 --- a/changelog.md +++ b/changelog.md @@ -35,6 +35,9 @@ Here some details about the bug fixes: - fix error that prevented the verification of plugins versions - fix error on X11 that caused a bug window event on exit +Change behavior of `ctrl+d` to add a multi-cursor selection to the next occurrence. +The old behavior to move the selection to the next occurrence is now done using the shortcut `ctrl+f3`. + ### 2.0 The 2.0 version of lite contains *breaking changes* to lite, in terms of how plugin settings are structured; diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 902623be..c5f2bf07 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -160,8 +160,14 @@ local function select_next(all) end command.add(has_unique_selection, { - ["find-replace:select-next"] = function() select_next(false) end, - ["find-replace:select-all"] = function() select_next(true) end + ["find-replace:select-next"] = function() + local l1, c1, l2, c2 = doc():get_selection(true) + local text = doc():get_text(l1, c1, l2, c2) + l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true }) + if l2 then doc():set_selection(l2, c2, l1, c1) end + end, + ["find-replace:select-add-next"] = function() select_next(false) end, + ["find-replace:select-add-all"] = function() select_next(true) end }) command.add("core.docview", { diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index 7f54ddbb..53a20468 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -66,9 +66,10 @@ local function keymap_macos(keymap) ["cmd+shift+return"] = "doc:newline-above", ["cmd+j"] = "doc:join-lines", ["cmd+a"] = "doc:select-all", - ["cmd+d"] = { "find-replace:select-next", "doc:select-word" }, + ["cmd+d"] = { "find-replace:select-add-next", "doc:select-word" }, + ["cmd+f3"] = "find-replace:select-next", ["cmd+l"] = "doc:select-lines", - ["cmd+shift+l"] = { "find-replace:select-all", "doc:select-word" }, + ["cmd+shift+l"] = { "find-replace:select-add-all", "doc:select-word" }, ["cmd+/"] = "doc:toggle-line-comments", ["option+up"] = "doc:move-lines-up", ["option+down"] = "doc:move-lines-down", diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 2be0dfc7..50eadec6 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -168,9 +168,10 @@ keymap.add_direct { ["ctrl+shift+return"] = "doc:newline-above", ["ctrl+j"] = "doc:join-lines", ["ctrl+a"] = "doc:select-all", - ["ctrl+d"] = { "find-replace:select-next", "doc:select-word" }, + ["ctrl+d"] = { "find-replace:select-add-next", "doc:select-word" }, + ["ctrl+f3"] = "find-replace:select-next", ["ctrl+l"] = "doc:select-lines", - ["ctrl+shift+l"] = { "find-replace:select-all", "doc:select-word" }, + ["ctrl+shift+l"] = { "find-replace:select-add-all", "doc:select-word" }, ["ctrl+/"] = "doc:toggle-line-comments", ["ctrl+up"] = "doc:move-lines-up", ["ctrl+down"] = "doc:move-lines-down", From 83607aec4a5553a2a6b7a6d448996df2212be2db Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 9 Sep 2021 22:37:26 +0200 Subject: [PATCH 57/62] Reword changelog --- changelog.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index 5ea7b87c..57ab9646 100644 --- a/changelog.md +++ b/changelog.md @@ -4,24 +4,33 @@ This files document the changes done in Lite XL for each release. Fix problem project directory when starting the application from Launcher on macOS. -Improved LogView by @takase1121. +Improved LogView. Entries can now be expanded and there is a context menu to copy the item's content. + +Change the behavior of `ctrl+d` to add a multi-cursor selection to the next occurrence. +The old behavior to move the selection to the next occurrence is now done using the shortcut `ctrl+f3`. + +Added a command to create a multi-cursor with all the occurrences of the current selection. +Activated with the shortcut `ctrl+shift+l`. Fix problem when trying to close an unsaved new document. + +No longer shows an error for the `-psn` argument passed to the application on macOS. + Fix `treeview:open-in-system` command on Windows. + Fix rename command to update name of document if opened. -Contributed by @Guldoman. Improve the find and replace dialog so that previously used expressions can be recalled using "up" and "down" keys. -Multi-cursors fixes and improvement by @adamharrison. - -Build package script rewrite and enhancement by @redtide. +Build package script rewrite with many improvements. Use bigger fonts by default. Other minor improvements and fixes. +With many thanks to the contributors: @adamharrison, @takase1121, @Guldoman, @redtide, @Timofffee, @boppyt, @Jan200101. + ### 2.0.1 Fix a few bugs and we mandate the mod-version 2 for plugins. @@ -35,9 +44,6 @@ Here some details about the bug fixes: - fix error that prevented the verification of plugins versions - fix error on X11 that caused a bug window event on exit -Change behavior of `ctrl+d` to add a multi-cursor selection to the next occurrence. -The old behavior to move the selection to the next occurrence is now done using the shortcut `ctrl+f3`. - ### 2.0 The 2.0 version of lite contains *breaking changes* to lite, in terms of how plugin settings are structured; From cec1e4efb9cffeb759165d6e4521721ae2ef2eb5 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 9 Sep 2021 23:30:18 +0200 Subject: [PATCH 58/62] Do not fail search if there was an option change --- data/core/commands/findreplace.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index c5f2bf07..2412c4e1 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -12,6 +12,7 @@ local last_finds, last_view, last_fn, last_text, last_sel local case_sensitive = config.find_case_sensitive or false local find_regex = config.find_regex or false +local found_expression local function doc() return core.active_view:is(DocView) and core.active_view.doc or last_view.doc @@ -34,10 +35,10 @@ local function update_preview(sel, search_fn, text) if ok and line1 and text ~= "" then last_view.doc:set_selection(line2, col2, line1, col1) last_view:scroll_to_line(line2, true) - return true + found_expression = true else last_view.doc:set_selection(unpack(sel)) - return false + found_expression = false end end @@ -54,7 +55,8 @@ end local function find(label, search_fn) last_view, last_sel, last_finds = core.active_view, { core.active_view.doc:get_selection() }, {} - local text, found = last_view.doc:get_text(unpack(last_sel)), false + local text = last_view.doc:get_text(unpack(last_sel)) + found_expression = false core.command_view:set_text(text, true) core.status_view:show_tooltip(get_find_tooltip()) @@ -63,7 +65,7 @@ local function find(label, search_fn) core.command_view:enter(label, function(text, item) insert_unique(core.previous_find, text) core.status_view:remove_tooltip() - if found then + if found_expression then last_fn, last_text = search_fn, text else core.error("Couldn't find %q", text) @@ -71,7 +73,7 @@ local function find(label, search_fn) last_view:scroll_to_make_visible(unpack(last_sel)) end end, function(text) - found = update_preview(last_sel, search_fn, text) + update_preview(last_sel, search_fn, text) last_fn, last_text = search_fn, text return core.previous_find end, function(explicit) From afd067219769686076d74a8e3c31290e3e4ec566 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 10 Sep 2021 14:54:55 +0200 Subject: [PATCH 59/62] Use line/col to identify selection in replace command --- data/core/commands/findreplace.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 2412c4e1..f8e8e45a 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -181,9 +181,9 @@ command.add("core.docview", { end, ["find-replace:replace"] = function() - local selected_text = doc():get_text(doc():get_selection()) - local has_newlines = selected_text:find("\n", 1, true) - replace("Text", has_newlines and "" or selected_text, function(text, old, new) + local l1, c1, l2, c2 = doc():get_selection() + local selected_text = doc():get_text(l1, c1, l2, c2) + replace("Text", l1 == l2 and selected_text or "", function(text, old, new) if not find_regex then return text:gsub(old:gsub("%W", "%%%1"), new:gsub("%%", "%%%%"), nil) end From 218999dff899872fb38d3c8889d5bc27cc600ed1 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 10 Sep 2021 14:55:04 +0200 Subject: [PATCH 60/62] Avoid bug when replacement stop at end of string Detect when we are past the end of the string to avoid by checking if byte is not nil. Fix #510. --- data/core/regex.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/regex.lua b/data/core/regex.lua index 19306e04..69203cbd 100644 --- a/data/core/regex.lua +++ b/data/core/regex.lua @@ -23,7 +23,7 @@ end -- Moves to the end of the identified character. local function end_character(str, index) local byte = string.byte(str, index + 1) - while byte >= 128 and byte < 192 do + while byte and byte >= 128 and byte < 192 do index = index + 1 byte = string.byte(str, index + 1) end From 8dd530e5cf4c1be080fcd387fc38aa6afc44be83 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 10 Sep 2021 15:47:33 +0200 Subject: [PATCH 61/62] Add -branch option in repackage script --- scripts/repackage.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/repackage.sh b/scripts/repackage.sh index 99368582..3239ea5e 100644 --- a/scripts/repackage.sh +++ b/scripts/repackage.sh @@ -10,7 +10,7 @@ copy_directory_from_repo () { fi local dirname="$1" local destdir="$2" - git archive master "$dirname" --format=tar | tar xf - -C "$destdir" "${tar_options[@]}" + git archive "$lite_branch" "$dirname" --format=tar | tar xf - -C "$destdir" "${tar_options[@]}" } lite_copy_third_party_modules () { @@ -23,12 +23,17 @@ lite_copy_third_party_modules () { rm "$build/rxi-lite-colors.zip" } +lite_branch=master while [ ! -z ${1+x} ]; do case "$1" in -dir) use_dir="$(realpath $2)" shift 2 ;; + -branch) + lite_branch="$2" + shift 2 + ;; *) echo "unknown option: $1" exit 1 From 18189e63b603040bb534d2aabcc2029f3f964421 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 10 Sep 2021 15:48:43 +0200 Subject: [PATCH 62/62] Fix repackage script to restore project version --- scripts/repackage.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/repackage.sh b/scripts/repackage.sh index 3239ea5e..f8da579f 100644 --- a/scripts/repackage.sh +++ b/scripts/repackage.sh @@ -78,6 +78,8 @@ for filename in $(ls -1 *.zip *.tar.*); do fi rm "$filename" find lite-xl -name lite -exec chmod a+x '{}' \; + start_file=$(find lite-xl -name start.lua) + lite_version=$(cat "$start_file" | awk 'match($0, /^\s*VERSION\s*=\s*"(.+)"/, a) { print(a[1]) }') xcoredir="$(find lite-xl -type d -name 'core')" coredir="$(dirname $xcoredir)" echo "coredir: $coredir" @@ -86,6 +88,7 @@ for filename in $(ls -1 *.zip *.tar.*); do rm -fr "$coredir/$module_name" (cd .. && copy_directory_from_repo --strip-components=1 "data/$module_name" "$workdir/$coredir") done + sed -i "s/@PROJECT_VERSION@/$lite_version/g" "$start_file" for module_name in plugins colors; do cp -r "third/data/$module_name" "$coredir" done