From 73bda963a5b4afa33b911beea9a8d4d39bf0b4d9 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 31 May 2021 09:41:37 +0200 Subject: [PATCH 01/16] Deprecate core.add_save_hook to override Doc:save In order to stay simple and closer to the lite's design principles we deprecate the core.add_save_hook function and the related mechanism. Instead we now directly override the Doc:save() method. The method is already overrided from core.init to add the automatic reloading of style when user's module is saved. The cleanup is related to the discussion in issue #229. --- data/core/commands/doc.lua | 12 ++++++------ data/core/init.lua | 33 ++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index ffaf029b..8165b426 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -47,7 +47,7 @@ local function save(filename) core.log("Saved \"%s\"", saved_filename) end --- returns the size of the original indent, and the indent +-- returns the size of the original indent, and the indent -- in your config format, rounded either up or down local function get_line_indent(line, rnd_up) local _, e = line:find("^[ \t]+") @@ -58,18 +58,18 @@ local function get_line_indent(line, rnd_up) else local indent = e and line:sub(1, e):gsub("\t", soft_tab) or "" local number = #indent / #soft_tab - return e, indent:sub(1, + return e, indent:sub(1, (rnd_up and math.ceil(number) or math.floor(number))*#soft_tab) end end -- un/indents text; behaviour varies based on selection and un/indent. --- * if there's a selection, it will stay static around the +-- * if there's a selection, it will stay static around the -- text for both indenting and unindenting. --- * if you are in the beginning whitespace of a line, and are indenting, the +-- * if you are in the beginning whitespace of a line, and are indenting, the -- cursor will insert the exactly appropriate amount of spaces, and jump the -- cursor to the beginning of first non whitespace characters --- * if you are not in the beginning whitespace of a line, and you indent, it +-- * if you are not in the beginning whitespace of a line, and you indent, it -- inserts the appropriate whitespace, as if you typed them normally. -- * if you are unindenting, the cursor will jump to the start of the line, -- and remove the appropriate amount of spaces (or a tab). @@ -83,7 +83,7 @@ local function indent_text(unindent) for line = line1, line2 do local e, rnded = get_line_indent(doc().lines[line], unindent) doc():remove(line, 1, line, (e or 0) + 1) - doc():insert(line, 1, + doc():insert(line, 1, unindent and rnded:sub(1, #rnded - #text) or rnded .. text) end l1d, l2d = #doc().lines[line1] - l1d, #doc().lines[line2] - l2d diff --git a/data/core/init.lua b/data/core/init.lua index a7ae2a26..cc4b46d8 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -411,6 +411,20 @@ local function whitespace_replacements() end +local function reload_on_user_module_save() + -- auto-realod style when user's module is saved by overriding Doc:Save() + local doc_save = Doc.save + local user_filename = system.absolute_path(USERDIR .. PATHSEP .. "init.lua") + function Doc:save(filename, abs_filename) + doc_save(self, filename, abs_filename) + if self.abs_filename == user_filename then + core.reload_module("core.style") + core.load_user_directory() + end + end +end + + function core.init() command = require "core.command" keymap = require "core.keymap" @@ -553,6 +567,8 @@ function core.init() if item.text == "Exit" then os.exit(1) end end) end + + reload_on_user_module_save() end @@ -612,13 +628,19 @@ do end +-- DEPRECATED function core.doc_save_hooks = {} function core.add_save_hook(fn) + core.error("The function core.add_save_hook is deprecated." .. + " Modules should now directly override the Doc:save function.") core.doc_save_hooks[#core.doc_save_hooks + 1] = fn end +-- DEPRECATED function function core.on_doc_save(filename) + -- for backward compatibility in modules. Hooks are deprecated, the function Doc:save + -- should be directly overidded. for _, hook in ipairs(core.doc_save_hooks) do hook(filename) end @@ -1065,15 +1087,4 @@ function core.on_error(err) end -core.add_save_hook(function(filename) - local doc = core.active_view.doc - local user_filename = system.absolute_path(USERDIR .. PATHSEP .. "init.lua") - if doc and doc:is(Doc) and doc.abs_filename == user_filename then - core.reload_module("core.style") - core.load_user_directory() - end -end) - - - return core From d941535600189563d13a2eed0ab34e7eb6faa7dc Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Thu, 3 Jun 2021 21:48:15 +0200 Subject: [PATCH 02/16] Enable lite-xl to be started from a symlink to the deployed binary (#249) Use resolved executablePath instead of resourcePath to allow lanching the lite-xl binary via a symlink, like typically done by Homebrew: /usr/local/bin/lite-xl -> /Applications/lite-xl.app/Contents/MacOS/lite-xl The resourcePath returns /usr/local in this case instead of /Applications/lite-xl.app/Contents/Resources, which makes later access to the resource files fail. Resolving the symlink to the executable and then the relative path to the expected directory Resources is a workaround for starting the application from both the launcher directly and the command line via the symlink. --- src/bundle_open.m | 21 +++++++++++++++++++-- src/main.c | 8 +++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/bundle_open.m b/src/bundle_open.m index 58811862..f4f0b94c 100644 --- a/src/bundle_open.m +++ b/src/bundle_open.m @@ -4,8 +4,25 @@ void set_macos_bundle_resources(lua_State *L) { @autoreleasepool { - NSString* resource_path = [[NSBundle mainBundle] resourcePath]; - lua_pushstring(L, [resource_path UTF8String]); + /* Use resolved executablePath instead of resourcePath to allow lanching + the lite-xl binary via a symlink, like typically done by Homebrew: + + /usr/local/bin/lite-xl -> /Applications/lite-xl.app/Contents/MacOS/lite-xl + + The resourcePath returns /usr/local in this case instead of + /Applications/lite-xl.app/Contents/Resources, which makes later + access to the resource files fail. Resolving the symlink to the + executable and then the relative path to the expected directory + Resources is a workaround for starting the application from both + the launcher directly and the command line via the symlink. + */ + NSString* executable_path = [[NSBundle mainBundle] executablePath]; + char resolved_path[PATH_MAX + 16 + 1]; + realpath([executable_path UTF8String], resolved_path); + strcat(resolved_path, "/../../Resources"); + char resource_path[PATH_MAX + 1]; + realpath(resolved_path, resource_path); + lua_pushstring(L, resource_path); lua_setglobal(L, "MACOS_RESOURCES"); }} diff --git a/src/main.c b/src/main.c index b0eb50d6..341f820b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include +#include #include #include "api/api.h" #include "rencache.h" @@ -62,8 +63,13 @@ static void get_exe_filename(char *buf, int sz) { int len = readlink(path, buf, sz - 1); buf[len] = '\0'; #elif __APPLE__ + /* use realpath to resolve a symlink if the process was launched from one. + ** This happens when Homebrew installs a cack and creates a symlink in + ** /usr/loca/bin for launching the executable from the command line. */ unsigned size = sz; - _NSGetExecutablePath(buf, &size); + char exepath[size]; + _NSGetExecutablePath(exepath, &size); + realpath(exepath, buf); #else strcpy(buf, "./lite"); #endif From 2365dfa9c081189db2d247e2c71213ff3f235f97 Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Thu, 3 Jun 2021 22:14:50 +0200 Subject: [PATCH 03/16] Flush the SDL_QUIT event when Cmd+W is detected in SDL_KEYDOWN as well (#248) On macos 11.2.3 with sdl 2.0.14 the keyup handler for cmd+w was not enough. Maybe the quit event started to be triggered from the keydown handler? In any case, flushing the quit event there too helped. --- src/api/system.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index 89c037c2..bbe0801b 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -152,6 +152,14 @@ top: return 4; case SDL_KEYDOWN: +#ifdef __APPLE__ + /* on macos 11.2.3 with sdl 2.0.14 the keyup handler for cmd+w below + ** was not enough. Maybe the quit event started to be triggered from the + ** keydown handler? In any case, flushing the quit event here too helped. */ + if ((e.key.keysym.sym == SDLK_w) && (e.key.keysym.mod & KMOD_GUI)) { + SDL_FlushEvent(SDL_QUIT); + } +#endif lua_pushstring(L, "keypressed"); lua_pushstring(L, key_name(buf, e.key.keysym.sym)); return 2; @@ -162,8 +170,7 @@ top: ** we want to flush this event and let the keymapper ** handle this key combination. ** Thanks to mathewmariani, taken from his lite-macos github repository. */ - if ((e.key.keysym.sym == SDLK_w) && (e.key.keysym.mod & KMOD_GUI)) - { + if ((e.key.keysym.sym == SDLK_w) && (e.key.keysym.mod & KMOD_GUI)) { SDL_FlushEvent(SDL_QUIT); } #endif From f682215b41a046d573db347c66abea8418974893 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 4 Jun 2021 14:05:54 +0200 Subject: [PATCH 04/16] Do not show empty documents when restoring session When a filename cannot be read when restoring a session do not create a document. Previous behavior was to create an empty "unsaved" document. --- data/plugins/workspace.lua | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/data/plugins/workspace.lua b/data/plugins/workspace.lua index 25c7f672..7697d318 100644 --- a/data/plugins/workspace.lua +++ b/data/plugins/workspace.lua @@ -29,7 +29,7 @@ local function workspace_files_for(project_dir) end -local function load_workspace_file(project_dir) +local function consume_workspace_file(project_dir) for filename, id in workspace_files_for(project_dir) do local load_f = loadfile(filename) local workspace = load_f and load_f() @@ -99,16 +99,26 @@ end local function load_view(t) if t.type == "doc" then - local ok, doc = pcall(core.open_doc, t.filename) - if not ok then - return DocView(core.open_doc()) + local dv + if not t.filename then + -- document not associated to a file + dv = DocView(core.open_doc()) + if t.text then dv.doc:insert(1, 1, t.text) end + else + -- we have a filename, try to read the file + local ok, doc = pcall(core.open_doc, t.filename) + if ok then + dv = DocView(doc) + end + end + -- doc view "dv" can be nil here if the filename associated to the document + -- cannot be read. + if dv and dv.doc then + dv.doc:set_selection(table.unpack(t.selection)) + dv.last_line, dv.last_col = dv.doc:get_selection() + dv.scroll.x, dv.scroll.to.x = t.scroll.x, t.scroll.x + dv.scroll.y, dv.scroll.to.y = t.scroll.y, t.scroll.y end - local dv = DocView(doc) - if t.text then doc:insert(1, 1, t.text) end - doc:set_selection(table.unpack(t.selection)) - dv.last_line, dv.last_col = doc:get_selection() - dv.scroll.x, dv.scroll.to.x = t.scroll.x, t.scroll.x - dv.scroll.y, dv.scroll.to.y = t.scroll.y, t.scroll.y return dv end return require(t.module)() @@ -141,13 +151,19 @@ end local function load_node(node, t) if t.type == "leaf" then local res - for _, v in ipairs(t.views) do + local active_view + for i, v in ipairs(t.views) do local view = load_view(v) - if v.active then res = view end - node:add_view(view) + if view then + if v.active then res = view end + node:add_view(view) + if t.active_view == i then + active_view = view + end + end end - if t.active_view then - node:set_active_view(node.views[t.active_view]) + if active_view then + node:set_active_view(active_view) end return res else @@ -184,7 +200,7 @@ end local function load_workspace() - local workspace = load_workspace_file(core.project_dir) + local workspace = consume_workspace_file(core.project_dir) if workspace then local root = get_unlocked_root(core.root_view.root_node) local active_view = load_node(root, workspace.documents) From ab9960cddf2e509ecc08c0747b152af6ef6fde5b Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 4 Jun 2021 14:42:08 +0200 Subject: [PATCH 05/16] Do not save log views in session file --- data/plugins/workspace.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/plugins/workspace.lua b/data/plugins/workspace.lua index 7697d318..77efd7c9 100644 --- a/data/plugins/workspace.lua +++ b/data/plugins/workspace.lua @@ -2,6 +2,7 @@ local core = require "core" local common = require "core.common" local DocView = require "core.docview" +local LogView = require "core.logview" local function workspace_files_for(project_dir) @@ -85,6 +86,7 @@ local function save_view(view) text = not view.doc.filename and view.doc:get_text(1, 1, math.huge, math.huge) } end + if mt == LogView then return end for name, mod in pairs(package.loaded) do if mod == mt then return { From 1ea28eb38b3442a79d29922d75a0afcebf254d1a Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 8 Jun 2021 12:06:54 +0200 Subject: [PATCH 06/16] Fix error in workspace file error reporting --- data/plugins/workspace.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/plugins/workspace.lua b/data/plugins/workspace.lua index 77efd7c9..9c1e20c8 100644 --- a/data/plugins/workspace.lua +++ b/data/plugins/workspace.lua @@ -12,7 +12,7 @@ local function workspace_files_for(project_dir) if not info_wsdir then local ok, err = system.mkdir(workspace_dir) if not ok then - error("cannot create workspace directory: %s", err) + error("cannot create workspace directory: \"" .. err .. "\"") end end return coroutine.wrap(function() From 3fe8b135af0a613a10fdbe13a34ca0f216c85e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Buckwalter?= Date: Tue, 8 Jun 2021 16:13:00 +0200 Subject: [PATCH 07/16] Use `ctrl` for next tab on macos Fixes #261. --- data/core/keymap-macos.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index 0809615f..f631ff9c 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -18,8 +18,8 @@ local function keymap_macos(keymap) ["alt+k"] = "root:switch-to-down", ["ctrl+w"] = "root:close", - ["cmd+tab"] = "root:switch-to-next-tab", - ["cmd+shift+tab"] = "root:switch-to-previous-tab", + ["ctrl+tab"] = "root:switch-to-next-tab", + ["ctrl+shift+tab"] = "root:switch-to-previous-tab", ["cmd+pageup"] = "root:move-tab-left", ["cmd+pagedown"] = "root:move-tab-right", ["alt+1"] = "root:switch-to-tab-1", From 212e5e326cd8c8ddd2b49c0db5feef2d7d3d9102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Buckwalter?= Date: Wed, 9 Jun 2021 20:23:40 +0200 Subject: [PATCH 08/16] MacOS modifier key adjustment (replace `alt`) per #262 (#263) * Use `cmd` as modifier key for tab seletion (macos) Part of #262. * Use `cmd+shift` instead of `alt` on macos Fixes #262. --- data/core/keymap-macos.lua | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index f631ff9c..ccbb102a 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -6,31 +6,31 @@ local function keymap_macos(keymap) ["cmd+n"] = "core:new-doc", ["cmd+shift+c"] = "core:change-project-folder", ["cmd+shift+o"] = "core:open-project-folder", - ["alt+return"] = "core:toggle-fullscreen", + ["cmd+ctrl+return"] = "core:toggle-fullscreen", - ["alt+shift+j"] = "root:split-left", - ["alt+shift+l"] = "root:split-right", - ["alt+shift+i"] = "root:split-up", - ["alt+shift+k"] = "root:split-down", - ["alt+j"] = "root:switch-to-left", - ["alt+l"] = "root:switch-to-right", - ["alt+i"] = "root:switch-to-up", - ["alt+k"] = "root:switch-to-down", + ["cmd+ctrl+shift+j"] = "root:split-left", + ["cmd+ctrl+shift+l"] = "root:split-right", + ["cmd+ctrl+shift+i"] = "root:split-up", + ["cmd+ctrl+shift+k"] = "root:split-down", + ["cmd+ctrl+j"] = "root:switch-to-left", + ["cmd+ctrl+l"] = "root:switch-to-right", + ["cmd+ctrl+i"] = "root:switch-to-up", + ["cmd+ctrl+k"] = "root:switch-to-down", ["ctrl+w"] = "root:close", ["ctrl+tab"] = "root:switch-to-next-tab", ["ctrl+shift+tab"] = "root:switch-to-previous-tab", ["cmd+pageup"] = "root:move-tab-left", ["cmd+pagedown"] = "root:move-tab-right", - ["alt+1"] = "root:switch-to-tab-1", - ["alt+2"] = "root:switch-to-tab-2", - ["alt+3"] = "root:switch-to-tab-3", - ["alt+4"] = "root:switch-to-tab-4", - ["alt+5"] = "root:switch-to-tab-5", - ["alt+6"] = "root:switch-to-tab-6", - ["alt+7"] = "root:switch-to-tab-7", - ["alt+8"] = "root:switch-to-tab-8", - ["alt+9"] = "root:switch-to-tab-9", + ["cmd+1"] = "root:switch-to-tab-1", + ["cmd+2"] = "root:switch-to-tab-2", + ["cmd+3"] = "root:switch-to-tab-3", + ["cmd+4"] = "root:switch-to-tab-4", + ["cmd+5"] = "root:switch-to-tab-5", + ["cmd+6"] = "root:switch-to-tab-6", + ["cmd+7"] = "root:switch-to-tab-7", + ["cmd+8"] = "root:switch-to-tab-8", + ["cmd+9"] = "root:switch-to-tab-9", ["cmd+f"] = "find-replace:find", ["cmd+r"] = "find-replace:replace", From 704a8dea0993f9903c524f035818a51b5c6793dd Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 9 Jun 2021 23:37:03 +0200 Subject: [PATCH 09/16] Group mouse move events from C API function Groups together consecutive mouse move events like done in core.step() lua function but on the C side. It does not introduce any meaningful speedup but it theory is more efficient and simplifies the Lua code. The simplification of the Lua code alone is enough to justify this change? --- data/core/init.lua | 14 +++----------- src/api/system.c | 8 ++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index cc4b46d8..95eb7973 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -948,26 +948,18 @@ end function core.step() -- handle events local did_keymap = false - local mouse_moved = false - local mouse = { x = 0, y = 0, dx = 0, dy = 0 } - for type, a,b,c,d in system.poll_event do - if type == "mousemoved" then - mouse_moved = true - mouse.x, mouse.y = a, b - mouse.dx, mouse.dy = mouse.dx + c, mouse.dy + d - elseif type == "textinput" and did_keymap then + if type == "textinput" and did_keymap then did_keymap = false + elseif type == "mousemoved" then + core.try(core.on_event, type, a, b, c, d) else local _, res = core.try(core.on_event, type, a, b, c, d) did_keymap = res or did_keymap end core.redraw = true end - if mouse_moved then - core.try(core.on_event, "mousemoved", mouse.x, mouse.y, mouse.dx, mouse.dy) - end local width, height = renderer.get_size() diff --git a/src/api/system.c b/src/api/system.c index bbe0801b..d00a9e47 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -201,6 +201,14 @@ top: return 4; case SDL_MOUSEMOTION: + SDL_PumpEvents(); + SDL_Event event_plus; + while (SDL_PeepEvents(&event_plus, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) { + e.motion.x = event_plus.motion.x; + e.motion.y = event_plus.motion.y; + e.motion.xrel += event_plus.motion.xrel; + e.motion.yrel += event_plus.motion.yrel; + } lua_pushstring(L, "mousemoved"); lua_pushnumber(L, e.motion.x); lua_pushnumber(L, e.motion.y); From 2af92e9af1797e40bfd155885abcee88932931d4 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 11 Jun 2021 14:57:41 +0200 Subject: [PATCH 10/16] Fix whitespace errors --- src/api/system.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index d00a9e47..4b98509f 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -538,11 +538,11 @@ static int f_fuzzy_match(lua_State *L) { bool files = false; if (lua_gettop(L) > 2 && lua_isboolean(L,3)) files = lua_toboolean(L, 3); - + int score = 0; int run = 0; - - // Match things *backwards*. This allows for better matching on filenames than the above + + // Match things *backwards*. This allows for better matching on filenames than the above // function. For example, in the lite project, opening "renderer" has lib/font_render/build.sh // as the first result, rather than src/renderer.c. Clearly that's wrong. if (files) { From 4fc910dbdbfefc8143c22f058f478ffc0462bec1 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 8 Jun 2021 21:31:09 -0400 Subject: [PATCH 11/16] Replaced fill loop with SDL_FillRect. --- src/renderer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/renderer.c b/src/renderer.c index b08c25d9..cd269687 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -309,7 +309,8 @@ void ren_draw_rect(RenRect rect, RenColor color) { int dr = surface->w - (x2 - x1); if (color.a == 0xff) { - rect_draw_loop(color); + SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; + SDL_FillRect(surface, &rect, SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a)); } else { rect_draw_loop(blend_pixel(*d, color)); } From 66275fe207430336747fbf6e90cf5de7baa86c3f Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 17 Jun 2021 18:23:30 +0200 Subject: [PATCH 12/16] Fix error in dirname computation in TreeView In TreeView:on_mouse_pressed() we need to find the directory a relative filename belongs to from its absolute filename. The code was using string.find to locate the relative filename within the absolute path but in some very specific cases we can find a pattern which is not the right-most one leading to a wrong directory name. Fix the error by adding a loop to make sure we find the right-most match. The standard Lua library has not a string.rfind to make a reverse search. Add a check to avoid trying to updating a topdir project directory. --- data/core/init.lua | 10 ++++++++++ data/plugins/treeview.lua | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 95eb7973..992eb5de 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -194,6 +194,16 @@ local function project_scan_thread() end +function core.is_project_folder(dirname) + for _, dir in ipairs(core.project_directories) do + if dir.name == dirname then + return true + end + end + return false +end + + function core.scan_project_folder(dirname, filename) for _, dir in ipairs(core.project_directories) do if dir.name == dirname then diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 8615343a..8214bda4 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -222,10 +222,19 @@ function TreeView:on_mouse_pressed(button, x, y, clicks) else if core.project_files_limit and not hovered_item.expanded then local filename, abs_filename = hovered_item.filename, hovered_item.abs_filename - local index = string.find(abs_filename, filename, 1, true) + local index = 0 + -- The loop below is used to find the first match starting from the end + -- in case there are multiple matches. + while index and index + #filename < #abs_filename do + index = string.find(abs_filename, filename, index + 1, true) + end + -- we assume here index is not nil because the abs_filename must contain the + -- relative filename local dirname = string.sub(abs_filename, 1, index - 2) - core.scan_project_folder(dirname, filename) - self:invalidate_cache(dirname) + if core.is_project_folder(dirname) then + core.scan_project_folder(dirname, filename) + self:invalidate_cache(dirname) + end end hovered_item.expanded = not hovered_item.expanded end From d45ec645d3008884dcf9f4dae3bd9b6525cf63cb Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 17 Jun 2021 17:15:08 -0400 Subject: [PATCH 13/16] Added in the ability to customize the config directory used with the environment variable XDG_CONFIG_HOME. (#271) --- data/core/start.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/start.lua b/data/core/start.lua index 513fda22..3ef806cc 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -12,7 +12,7 @@ else local prefix = EXEDIR:match("^(.+)[/\\]bin$") DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data') end -USERDIR = HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user') +USERDIR = os.getenv("XDG_CONFIG_HOME") or (HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user')) package.path = DATADIR .. '/?.lua;' .. package.path package.path = DATADIR .. '/?/init.lua;' .. package.path From cfd3bebfcc081e0a1f53e218ee69ae4984a07423 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 18 Jun 2021 12:00:24 +0200 Subject: [PATCH 14/16] Provide specific syntax plugin for C++ We have only the problem to attribute the .h either to C or C++ but we don't have currently any way to discriminate them. --- data/plugins/language_c.lua | 2 +- data/plugins/language_cpp.lua | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 data/plugins/language_cpp.lua diff --git a/data/plugins/language_c.lua b/data/plugins/language_c.lua index b311884b..836e1692 100644 --- a/data/plugins/language_c.lua +++ b/data/plugins/language_c.lua @@ -2,7 +2,7 @@ local syntax = require "core.syntax" syntax.add { - files = { "%.c$", "%.h$", "%.inl$", "%.cpp$", "%.hpp$" }, + files = { "%.c$", "%.h$", "%.inl$" }, comment = "//", patterns = { { pattern = "//.-\n", type = "comment" }, diff --git a/data/plugins/language_cpp.lua b/data/plugins/language_cpp.lua new file mode 100644 index 00000000..2e3b7924 --- /dev/null +++ b/data/plugins/language_cpp.lua @@ -0,0 +1,69 @@ +-- mod-version:1 -- lite-xl 1.16 +local syntax = require "core.syntax" + +syntax.add { + files = { "%.cpp$", "%.h$", "%.hpp$", "%.inl$" }, + comment = "//", + patterns = { + { pattern = "//.-\n", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = "0x%x+", type = "number" }, + { pattern = "%d+[%d%.eE]*f?", type = "number" }, + { pattern = "%.?%d+f?", type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "class%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "namespace%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "[%a_][%w_]*::", type = "symbol" }, + { pattern = "::", type = "symbol" }, + -- { pattern = "[%a_][%w_]*%f[(]", type = "function" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + { pattern = "#include%s()<.->", type = {"keyword", "string"} }, + { pattern = "#[%a_][%w_]*", type = "keyword" }, + }, + symbols = { + ["if"] = "keyword", + ["then"] = "keyword", + ["else"] = "keyword", + ["elseif"] = "keyword", + ["do"] = "keyword", + ["while"] = "keyword", + ["for"] = "keyword", + ["break"] = "keyword", + ["continue"] = "keyword", + ["return"] = "keyword", + ["goto"] = "keyword", + ["typedef"] = "keyword", + ["enum"] = "keyword", + ["extern"] = "keyword", + ["static"] = "keyword", + ["volatile"] = "keyword", + ["const"] = "keyword", + ["inline"] = "keyword", + ["switch"] = "keyword", + ["case"] = "keyword", + ["default"] = "keyword", + ["auto"] = "keyword", + ["void"] = "keyword", + ["template"] = "keyword", + ["typename"] = "keyword", + ["int"] = "keyword2", + ["short"] = "keyword2", + ["long"] = "keyword2", + ["float"] = "keyword2", + ["double"] = "keyword2", + ["char"] = "keyword2", + ["unsigned"] = "keyword2", + ["bool"] = "keyword2", + ["true"] = "literal", + ["false"] = "literal", + ["nullptr"] = "literal", + ["public"] = "keyword", + ["private"] = "keyword", + ["protected"] = "keyword", + }, +} + From ee404965a109fb0ca351886f323a4a8000485cc7 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 20 Jun 2021 23:09:58 +0200 Subject: [PATCH 15/16] Bump version 1.16.2 and update changelog --- changelog.md | 14 ++++++++++++++ data/core/start.lua | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index eb203747..ea903922 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,19 @@ This files document the changes done in Lite XL for each release. +### 1.16.12 + +Add syntax support for C++. + +Respect the `XDG_CONFIG_HOME` variable if set to define the USERDIR. + +Fix an error that prevented navigating large repositories in some rare situations. + +Minor preformance improvements for drawing operations and events handling. + +Improve macOS keybindings thanks to @bjornbm and @prantlf. + +Improve behavior of applications when restoring workspaces to avoid displaying empty documents. + ### 1.16.11 When opening directories with too many files lite-xl now keep diplaying files and directories in the treeview. diff --git a/data/core/start.lua b/data/core/start.lua index 3ef806cc..6c1126b1 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -1,5 +1,5 @@ -- this file is used by lite-xl to setup the Lua environment when starting -VERSION = "1.16.11" +VERSION = "1.16.12" MOD_VERSION = "1" SCALE = tonumber(os.getenv("LITE_SCALE")) or SCALE From b086db24e8a96aff825b63c5adca6d2894f29003 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 20 Jun 2021 23:10:52 +0200 Subject: [PATCH 16/16] Integrate language_cpp plugins from lite-pugins --- data/plugins/language_cpp.lua | 109 +++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 28 deletions(-) diff --git a/data/plugins/language_cpp.lua b/data/plugins/language_cpp.lua index 2e3b7924..cf3d7cd2 100644 --- a/data/plugins/language_cpp.lua +++ b/data/plugins/language_cpp.lua @@ -1,30 +1,77 @@ -- mod-version:1 -- lite-xl 1.16 +pcall(require, "plugins.language_c") + local syntax = require "core.syntax" syntax.add { - files = { "%.cpp$", "%.h$", "%.hpp$", "%.inl$" }, + files = { + "%.h$", "%.inl$", "%.cpp$", "%.cc$", "%.C$", "%.cxx$", + "%.c++$", "%.hh$", "%.H$", "%.hxx$", "%.hpp$", "%.h++$" + }, comment = "//", patterns = { - { pattern = "//.-\n", type = "comment" }, - { pattern = { "/%*", "%*/" }, type = "comment" }, - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { pattern = "0x%x+", type = "number" }, - { pattern = "%d+[%d%.eE]*f?", type = "number" }, - { pattern = "%.?%d+f?", type = "number" }, - { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, - { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, - { pattern = "class%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, - { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, - { pattern = "namespace%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, - { pattern = "[%a_][%w_]*::", type = "symbol" }, - { pattern = "::", type = "symbol" }, - -- { pattern = "[%a_][%w_]*%f[(]", type = "function" }, - { pattern = "[%a_][%w_]*", type = "symbol" }, - { pattern = "#include%s()<.->", type = {"keyword", "string"} }, - { pattern = "#[%a_][%w_]*", type = "keyword" }, + { pattern = "//.-\n", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = "0x%x+", type = "number" }, + { pattern = "%d+[%d%.eE]*f?", type = "number" }, + { pattern = "%.?%d+f?", type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "class%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "namespace%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "[%a_][%w_]*::", type = "symbol" }, + { pattern = "::", type = "symbol" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + { pattern = "#include%s()<.->", type = {"keyword", "string"} }, + { pattern = "#[%a_][%w_]*", type = "keyword" }, }, symbols = { + ["alignof"] = "keyword", + ["alignas"] = "keyword", + ["private"] = "keyword", + ["protected"] = "keyword", + ["public"] = "keyword", + ["register"] = "keyword", + ["nullptr"] = "keyword", + ["operator"] = "keyword", + ["asm"] = "keyword", + ["catch"] = "keyword", + ["throw"] = "keyword", + ["try"] = "keyword", + ["compl"] = "keyword", + ["explicit"] = "keyword", + ["export"] = "keyword", + ["concept"] = "keyword", + ["consteval"] = "keyword", + ["constexpr"] = "keyword", + ["constinit"] = "keyword", + ["const_cast"] = "keyword", + ["dynamic_cast"] = "keyword", + ["reinterpret_cast"] = "keyword", + ["static_cast"] = "keyword", + ["static_assert"] = "keyword", + ["template"] = "keyword", + ["this"] = "keyword", + ["thread_local"] = "keyword", + ["requires"] = "keyword", + ["co_wait"] = "keyword", + ["co_return"] = "keyword", + ["co_yield"] = "keyword", + ["decltype"] = "keyword", + ["delete"] = "keyword", + ["export"] = "keyword", + ["friend"] = "keyword", + ["typeid"] = "keyword", + ["typename"] = "keyword", + ["mutable"] = "keyword", + ["override"] = "keyword", + ["virtual"] = "keyword", + ["using"] = "keyword", + ["new"] = "keyword", + ["noexcept"] = "keyword", ["if"] = "keyword", ["then"] = "keyword", ["else"] = "keyword", @@ -47,9 +94,8 @@ syntax.add { ["case"] = "keyword", ["default"] = "keyword", ["auto"] = "keyword", + ["const"] = "keyword", ["void"] = "keyword", - ["template"] = "keyword", - ["typename"] = "keyword", ["int"] = "keyword2", ["short"] = "keyword2", ["long"] = "keyword2", @@ -58,12 +104,19 @@ syntax.add { ["char"] = "keyword2", ["unsigned"] = "keyword2", ["bool"] = "keyword2", - ["true"] = "literal", - ["false"] = "literal", - ["nullptr"] = "literal", - ["public"] = "keyword", - ["private"] = "keyword", - ["protected"] = "keyword", - }, + ["true"] = "keyword2", + ["false"] = "keyword2", + ["#include"] = "keyword", + ["#if"] = "keyword", + ["#ifdef"] = "keyword", + ["#ifndef"] = "keyword", + ["#else"] = "keyword", + ["#elseif"] = "keyword", + ["#endif"] = "keyword", + ["#define"] = "keyword", + ["#warning"] = "keyword", + ["#error"] = "keyword", + ["#pragma"] = "keyword", + }, }