From dc501cb41a80fc61f4cc08f51bcbe8dd581e5792 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 25 Aug 2021 23:45:18 +0200 Subject: [PATCH 01/16] Fix plugin version check --- data/core/init.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 4af35921..92156c93 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -687,17 +687,19 @@ function core.load_plugins() for filename, plugin_dir in pairs(files) do local basename = filename:match("(.-)%.lua$") or filename - local version_match = check_plugin_version(plugin_dir .. '/' .. filename) - 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 - table.insert(list, filename) - end - if version_match and config.plugins[basename] ~= false then - local ok = core.try(require, "plugins." .. basename) - if ok then core.log_quiet("Loaded plugin %q from %s", basename, plugin_dir) end - if not ok then - no_errors = false + local is_lua_file, version_match = check_plugin_version(plugin_dir .. '/' .. filename) + 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 + table.insert(list, filename) + end + if version_match and config.plugins[basename] ~= false then + local ok = core.try(require, "plugins." .. basename) + if ok then core.log_quiet("Loaded plugin %q from %s", basename, plugin_dir) end + if not ok then + no_errors = false + end end end end From daf916769f5fdb85c412e9098d4893a5ff00ac01 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 27 Aug 2021 00:13:40 +0200 Subject: [PATCH 02/16] Fix bug with close-all command There are really multiple things here in the close_all_docviews function: 1. we reset the Node's tab_offset 2. we ensure the core's active_view is properly set 3. we close LogViews as well as DocViews Some conditions seems to never happen but we stay safe and try to cover all possible cases. --- data/core/rootview.lua | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 7b13487b..9cedcf52 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -8,6 +8,7 @@ local View = require "core.view" local CommandView = require "core.commandview" local NagView = require "core.nagview" local DocView = require "core.docview" +local LogView = require "core.logview" local EmptyView = View:extend() @@ -595,19 +596,35 @@ end function Node:close_all_docviews(keep_active) + local node_active_view = self.active_view + local lost_active_view = false if self.type == "leaf" then local i = 1 while i <= #self.views do local view = self.views[i] - if view:is(DocView) and not view:is(CommandView) and + if (view:is(DocView) or view:is(LogView)) and not view:is(CommandView) and (not keep_active or view ~= self.active_view) then table.remove(self.views, i) + if view == node_active_view then + lost_active_view = true + end else i = i + 1 end end - if #self.views == 0 and self.is_primary_node then - self:add_view(EmptyView()) + self.tab_offset = 1 + if #self.views == 0 then + if self.is_primary_node then + self:add_view(EmptyView()) + elseif node_active_view == core.active_view then + -- Apparently we never gets here. In practice the primary node + -- is cleared first and get the active view on the empty view it sets. + local default_view = core.root_view:get_primary_node().views[1] + core.set_active_view(default_view) + end + elseif #self.views > 0 and lost_active_view then + -- We never get there either + self:set_active_view(self.views[1]) end else self.a:close_all_docviews(keep_active) From 456f6eda657fd2bc67fa375491032bab8c7dea32 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 27 Aug 2021 00:17:43 +0200 Subject: [PATCH 03/16] Do not use os.exit to exit the application Properly quit the application by terminating the core.run() function. Otherwise a BadWindow event was happening when closing the window. --- data/core/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 92156c93..bd87385a 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -494,6 +494,7 @@ function core.init() core.redraw = true core.visited_files = {} core.restart_request = false + core.quit_request = false core.replacements = whitespace_replacements() core.root_view = RootView() @@ -632,7 +633,7 @@ local function quit_with_function(quit_fn, force) end function core.quit(force) - quit_with_function(os.exit, force) + quit_with_function(function() core.quit_request = true end, force) end @@ -1032,7 +1033,7 @@ function core.run() core.frame_start = system.get_time() local did_redraw = core.step() local need_more_work = run_threads() - if core.restart_request then break end + if core.restart_request or core.quit_request then break end if not did_redraw and not need_more_work then idle_iterations = idle_iterations + 1 -- do not wait of events at idle_iterations = 1 to give a chance at core.step to run From 7f4d9789d605be378487361d731ecf02420cecf6 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 27 Aug 2021 13:02:28 +0200 Subject: [PATCH 04/16] Simplify commit daf91676 about active view setting --- data/core/rootview.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 9cedcf52..8bc402f9 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -613,17 +613,15 @@ function Node:close_all_docviews(keep_active) end end self.tab_offset = 1 - if #self.views == 0 then - if self.is_primary_node then - self:add_view(EmptyView()) - elseif node_active_view == core.active_view then - -- Apparently we never gets here. In practice the primary node - -- is cleared first and get the active view on the empty view it sets. - local default_view = core.root_view:get_primary_node().views[1] - core.set_active_view(default_view) - end + if #self.views == 0 and self.is_primary_node then + -- if we are not the primary view and we had the active view it doesn't + -- matter to reattribute the active view because, within the close_all_docviews + -- top call, the primary node will take the active view anyway. + -- Set the empty view and takes the active view. + self:add_view(EmptyView()) elseif #self.views > 0 and lost_active_view then - -- We never get there either + -- In practice we never get there but if a view remain we need + -- to reset the Node's active view. self:set_active_view(self.views[1]) end else From bb6b99b16777f0b34c1ea28db78525b4041d0f31 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 27 Aug 2021 14:42:57 +0200 Subject: [PATCH 05/16] Further simplifies logic for active view in close-all command --- data/core/rootview.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 8bc402f9..47f028cb 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -596,8 +596,6 @@ end function Node:close_all_docviews(keep_active) - local node_active_view = self.active_view - local lost_active_view = false if self.type == "leaf" then local i = 1 while i <= #self.views do @@ -605,9 +603,6 @@ function Node:close_all_docviews(keep_active) if (view:is(DocView) or view:is(LogView)) and not view:is(CommandView) and (not keep_active or view ~= self.active_view) then table.remove(self.views, i) - if view == node_active_view then - lost_active_view = true - end else i = i + 1 end @@ -619,9 +614,10 @@ function Node:close_all_docviews(keep_active) -- top call, the primary node will take the active view anyway. -- Set the empty view and takes the active view. self:add_view(EmptyView()) - elseif #self.views > 0 and lost_active_view then - -- In practice we never get there but if a view remain we need - -- to reset the Node's active view. + elseif #self.views > 0 then + -- In practice we never get there but if it ever happen we need to + -- reset the Node's active view. We do this irrespectively of what the + -- previous active view was. self:set_active_view(self.views[1]) end else From a8f4c0c4e514b76836bf0b78af62fc22624254bb Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 27 Aug 2021 15:22:09 +0200 Subject: [PATCH 06/16] Set initial text for core:change-project-folder --- data/core/commands/core.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index d7d0f1a3..cacd37c0 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -147,6 +147,8 @@ command.add(nil, { end, ["core:change-project-folder"] = function() + local dirname = common.dirname(core.project_dir) + core.command_view:set_text(dirname .. PATHSEP) 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 9592ce85f5fd029b3d55f8f0c579fc3c5181503f Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 27 Aug 2021 23:20:08 +0200 Subject: [PATCH 07/16] Revert "Further simplifies logic for active view in close-all command" This reverts commit bb6b99b16777f0b34c1ea28db78525b4041d0f31. --- data/core/rootview.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 47f028cb..8bc402f9 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -596,6 +596,8 @@ end function Node:close_all_docviews(keep_active) + local node_active_view = self.active_view + local lost_active_view = false if self.type == "leaf" then local i = 1 while i <= #self.views do @@ -603,6 +605,9 @@ function Node:close_all_docviews(keep_active) if (view:is(DocView) or view:is(LogView)) and not view:is(CommandView) and (not keep_active or view ~= self.active_view) then table.remove(self.views, i) + if view == node_active_view then + lost_active_view = true + end else i = i + 1 end @@ -614,10 +619,9 @@ function Node:close_all_docviews(keep_active) -- top call, the primary node will take the active view anyway. -- Set the empty view and takes the active view. self:add_view(EmptyView()) - elseif #self.views > 0 then - -- In practice we never get there but if it ever happen we need to - -- reset the Node's active view. We do this irrespectively of what the - -- previous active view was. + elseif #self.views > 0 and lost_active_view then + -- In practice we never get there but if a view remain we need + -- to reset the Node's active view. self:set_active_view(self.views[1]) end else From d46475532f95a1371dd9187382c407eec7d52a98 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 27 Aug 2021 23:55:17 +0200 Subject: [PATCH 08/16] Introduce View objects context property Used to determine if an instance of the given class should be closed or not when a project session is terminated. --- data/core/commandview.lua | 2 ++ data/core/docview.lua | 1 + data/core/logview.lua | 1 + data/core/rootview.lua | 5 +---- data/core/view.lua | 4 ++++ data/plugins/projectsearch.lua | 1 + 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/data/core/commandview.lua b/data/core/commandview.lua index 4d518d02..eb7febc7 100644 --- a/data/core/commandview.lua +++ b/data/core/commandview.lua @@ -15,6 +15,8 @@ end local CommandView = DocView:extend() +CommandView.context = "application" + local max_suggestions = 10 local noop = function() end diff --git a/data/core/docview.lua b/data/core/docview.lua index 89da8190..17fb534a 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -9,6 +9,7 @@ local View = require "core.view" local DocView = View:extend() +DocView.context = "session" local function move_to_line_offset(dv, line, col, offset) local xo = dv.last_x_offset diff --git a/data/core/logview.lua b/data/core/logview.lua index d7142fb5..b731df3c 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -5,6 +5,7 @@ local View = require "core.view" local LogView = View:extend() +LogView.context = "session" function LogView:new() LogView.super.new(self) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 8bc402f9..f2499e68 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -5,10 +5,8 @@ local style = require "core.style" local keymap = require "core.keymap" local Object = require "core.object" local View = require "core.view" -local CommandView = require "core.commandview" local NagView = require "core.nagview" local DocView = require "core.docview" -local LogView = require "core.logview" local EmptyView = View:extend() @@ -602,8 +600,7 @@ function Node:close_all_docviews(keep_active) local i = 1 while i <= #self.views do local view = self.views[i] - if (view:is(DocView) or view:is(LogView)) and not view:is(CommandView) and - (not keep_active or view ~= self.active_view) then + if view.context == "session" and (not keep_active or view ~= self.active_view) then table.remove(self.views, i) if view == node_active_view then lost_active_view = true diff --git a/data/core/view.lua b/data/core/view.lua index 2fb431d6..d1374ee4 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -7,6 +7,10 @@ local Object = require "core.object" local View = Object:extend() +-- context can be "application" or "session". The instance of objects +-- with context "session" will be closed when a project session is +-- terminated. The context "application" is for functional UI elements. +View.context = "application" function View:new() self.position = { x = 0, y = 0 } diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index 3873da3b..45967697 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -9,6 +9,7 @@ local View = require "core.view" local ResultsView = View:extend() +ResultsView.context = "session" function ResultsView:new(text, fn) ResultsView.super.new(self) From 4f8de02bcf2fb19b0d64bc03f6b3b7bc93b606ee Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 28 Aug 2021 00:08:25 +0200 Subject: [PATCH 09/16] Remove unused Object's method "implement" Not used in the code base. --- data/core/object.lua | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/data/core/object.lua b/data/core/object.lua index af41b7e9..0941ce5d 100644 --- a/data/core/object.lua +++ b/data/core/object.lua @@ -20,17 +20,6 @@ function Object:extend() end -function Object:implement(...) - for _, cls in pairs({...}) do - for k, v in pairs(cls) do - if self[k] == nil and type(v) == "function" then - self[k] = v - end - end - end -end - - function Object:is(T) local mt = getmetatable(self) while mt do From 06252382ec60d15ff2ff367bfab450d64908de7a Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 28 Aug 2021 00:21:29 +0200 Subject: [PATCH 10/16] Fix focus problem with NagView with root:close-all Fix provided by @Guldoman in PR: https://github.com/lite-xl/lite-xl/pull/419 --- data/core/init.lua | 6 +++++- data/core/nagview.lua | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index bd87385a..f6034a06 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -746,8 +746,12 @@ end function core.set_active_view(view) assert(view, "Tried to set active view to nil") - if core.active_view and core.active_view.force_focus then return end if view ~= core.active_view then + if core.active_view and core.active_view.force_focus then + core.next_active_view = view + return + end + core.next_active_view = nil if view.doc and view.doc.filename then core.set_visited(view.doc.filename) end diff --git a/data/core/nagview.lua b/data/core/nagview.lua index 6d6f89f4..3d448cd4 100644 --- a/data/core/nagview.lua +++ b/data/core/nagview.lua @@ -193,7 +193,8 @@ function NagView:next() self:change_hovered(common.find_index(self.options, "default_yes")) end self.force_focus = self.message ~= nil - core.set_active_view(self.message ~= nil and self or core.last_active_view) + core.set_active_view(self.message ~= nil and self or + core.next_active_view or core.last_active_view) end function NagView:show(title, message, options, on_select) From 5e801492951dc7737cb28a3ad22f9f33707578b7 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sat, 28 Aug 2021 06:02:12 +0200 Subject: [PATCH 11/16] Avoid having no `pixel_width` On small scales `pixel_width` could become `0`. This caused the creation of buffers of size `0` with consequent overflows. --- lib/font_renderer/font_renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/font_renderer/font_renderer.cpp b/lib/font_renderer/font_renderer.cpp index 8026a89d..14110107 100644 --- a/lib/font_renderer/font_renderer.cpp +++ b/lib/font_renderer/font_renderer.cpp @@ -245,7 +245,7 @@ FR_Bitmap *FR_Bake_Font_Bitmap(FR_Renderer *font_renderer, int font_height, } const int glyph_avg_width = glyph_count > 0 ? x_size_sum / (glyph_count * subpixel_scale) : font_height; - const int pixels_width = glyph_avg_width * 28; + const int pixels_width = glyph_avg_width > 0 ? glyph_avg_width * 28 : 28; // dry run simulating pixel position to estimate required image's height int x = x_start, y = 0, y_bottom = y; From dac3a9cba52862a7d58afdcb76cb693005c72e70 Mon Sep 17 00:00:00 2001 From: Daniel Rocha Date: Fri, 27 Aug 2021 20:02:04 -0300 Subject: [PATCH 12/16] Fix minimal scale possible --- data/plugins/scale.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/data/plugins/scale.lua b/data/plugins/scale.lua index 3e3e1a41..68577285 100644 --- a/data/plugins/scale.lua +++ b/data/plugins/scale.lua @@ -13,6 +13,8 @@ config.plugins.scale = { use_mousewheel = true } +local MIN_SCALE = 0.25; + local scale_level = 0 local scale_steps = 0.05 @@ -89,6 +91,13 @@ local function inc_scale() end local function dec_scale() + local new_scale_level = default_scale + (scale_level - 1) * scale_steps + + if new_scale_level < MIN_SCALE then + set_scale(MIN_SCALE) + return + end + scale_level = scale_level - 1 set_scale(default_scale + scale_level * scale_steps) end From 49ec7c88e85a4081906c7a575975caf20d015382 Mon Sep 17 00:00:00 2001 From: Daniel Rocha Date: Fri, 27 Aug 2021 20:12:09 -0300 Subject: [PATCH 13/16] Fix the additional four spaces to two spaces in the indent --- data/plugins/scale.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/data/plugins/scale.lua b/data/plugins/scale.lua index 68577285..2b340e5c 100644 --- a/data/plugins/scale.lua +++ b/data/plugins/scale.lua @@ -81,25 +81,25 @@ function RootView:on_mouse_wheel(d, ...) end local function res_scale() - scale_level = 0 - set_scale(default_scale) + scale_level = 0 + set_scale(default_scale) end local function inc_scale() - scale_level = scale_level + 1 - set_scale(default_scale + scale_level * scale_steps) + scale_level = scale_level + 1 + set_scale(default_scale + scale_level * scale_steps) end local function dec_scale() - local new_scale_level = default_scale + (scale_level - 1) * scale_steps + local new_scale_level = default_scale + (scale_level - 1) * scale_steps - if new_scale_level < MIN_SCALE then - set_scale(MIN_SCALE) - return - end + if new_scale_level < MIN_SCALE then + set_scale(MIN_SCALE) + return + end - scale_level = scale_level - 1 - set_scale(default_scale + scale_level * scale_steps) + scale_level = scale_level - 1 + set_scale(default_scale + scale_level * scale_steps) end From 2b1c157a36998db53cfe2ab11ba3242491d5cd85 Mon Sep 17 00:00:00 2001 From: Daniel Rocha Date: Fri, 27 Aug 2021 23:57:51 -0300 Subject: [PATCH 14/16] Refactored minimum scale bug fix code --- data/plugins/scale.lua | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/data/plugins/scale.lua b/data/plugins/scale.lua index 2b340e5c..8d16304b 100644 --- a/data/plugins/scale.lua +++ b/data/plugins/scale.lua @@ -13,7 +13,7 @@ config.plugins.scale = { use_mousewheel = true } -local MIN_SCALE = 0.25; +local MINIMUM_SCALE = 0.25; local scale_level = 0 local scale_steps = 0.05 @@ -90,16 +90,9 @@ local function inc_scale() set_scale(default_scale + scale_level * scale_steps) end -local function dec_scale() - local new_scale_level = default_scale + (scale_level - 1) * scale_steps - - if new_scale_level < MIN_SCALE then - set_scale(MIN_SCALE) - return - end - +local function dec_scale() scale_level = scale_level - 1 - set_scale(default_scale + scale_level * scale_steps) + set_scale(math.max(default_scale + scale_level * scale_steps), MINIMUM_SCALE) end From eeac85d4b4ba0324c3a5dd0a51ca73e0a925aacb Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 28 Aug 2021 16:44:25 +0200 Subject: [PATCH 15/16] Bump new version number --- meson.build | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 709288d7..5dee12ec 100644 --- a/meson.build +++ b/meson.build @@ -1,12 +1,10 @@ project('lite-xl', ['c', 'cpp'], - version : '2.0.0', + version : '2.0.1', license : 'MIT', meson_version : '>= 0.54', default_options : ['c_std=gnu11', 'cpp_std=c++03'] ) -# TODO: the project version could be automatically generated from git with: -# version : run_command('bash', 'scripts/version.sh').stdout(), #=============================================================================== # Configuration From f1c004411ceec9a4af3199c3125ba26533b769fe Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 28 Aug 2021 08:08:53 -0700 Subject: [PATCH 16/16] Add missing home_encode for change-project-folder --- data/core/commands/core.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index cacd37c0..7ac36976 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -148,7 +148,7 @@ command.add(nil, { ["core:change-project-folder"] = function() local dirname = common.dirname(core.project_dir) - core.command_view:set_text(dirname .. PATHSEP) + core.command_view:set_text(common.home_encode(dirname) .. PATHSEP) 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