From b77b1c022125647d3b49b5ef6c56de29efe1d93f Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sat, 20 Nov 2021 03:15:08 +0100 Subject: [PATCH 01/10] Add `Doc:get_indent_info` It returns the indentation type, size and confirmation status, used by the `Doc`. --- data/core/doc/init.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 640e9fd5..bdf6263a 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -115,6 +115,14 @@ function Doc:clean() end +function Doc:get_indent_info() + if not self.indent_info then return config.tab_type, config.indent_size, false end + return self.indent_info.type or config.tab_type, + self.indent_info.size or config.indent_size, + self.indent_info.confirmed +end + + function Doc:get_change_id() return self.undo_stack.idx end From 3d9901695bdec387bccbc7bc9bc9702b2d66fa13 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sat, 20 Nov 2021 03:20:49 +0100 Subject: [PATCH 02/10] Use the new `Doc:get_indent_info` throughout `core` --- data/core/commands/doc.lua | 15 ++++----------- data/core/doc/init.lua | 18 ++++++++++-------- data/core/docview.lua | 4 ++-- data/core/statusview.lua | 6 +++--- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index fe1fa3b1..b2f55e26 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -16,14 +16,6 @@ local function doc() end -local function get_indent_string() - if config.tab_type == "hard" then - return "\t" - end - return string.rep(" ", config.indent_size) -end - - local function doc_multiline_selections(sort) local iter, state, idx, line1, col1, line2, col2 = doc():get_selections(sort) return function() @@ -157,11 +149,12 @@ local commands = { end, ["doc:backspace"] = function() + local _, indent_size = doc():get_indent_info() for idx, line1, col1, line2, col2 in doc():get_selections() do if line1 == line2 and col1 == col2 then local text = doc():get_text(line1, 1, line1, col1) - if #text >= config.indent_size and text:find("^ *$") then - doc():delete_to_cursor(idx, 0, -config.indent_size) + if #text >= indent_size and text:find("^ *$") then + doc():delete_to_cursor(idx, 0, -indent_size) return end end @@ -271,7 +264,7 @@ local commands = { ["doc:toggle-line-comments"] = function() local comment = doc().syntax.comment if not comment then return end - local indentation = get_indent_string() + local indentation = doc():get_indent_string() local comment_text = comment .. " " for idx, line1, _, line2 in doc_multiline_selections(true) do local uncomment = true diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index bdf6263a..af692a4d 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -494,19 +494,21 @@ end function Doc:select_to(...) return self:select_to_cursor(nil, ...) end -local function get_indent_string() - if config.tab_type == "hard" then +function Doc:get_indent_string() + local indent_type, indent_size = self:get_indent_info() + if indent_type == "hard" then return "\t" end - return string.rep(" ", config.indent_size) + return string.rep(" ", indent_size) end -- 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) +function Doc:get_line_indent(line, rnd_up) local _, e = line:find("^[ \t]+") - local soft_tab = string.rep(" ", config.indent_size) - if config.tab_type == "hard" then + local indent_type, indent_size = self:get_indent_info() + local soft_tab = string.rep(" ", indent_size) + if indent_type == "hard" then local indent = e and line:sub(1, e):gsub(soft_tab, "\t") or "" return e, indent:gsub(" +", rnd_up and "\t" or "") else @@ -528,14 +530,14 @@ end -- * if you are unindenting, the cursor will jump to the start of the line, -- and remove the appropriate amount of spaces (or a tab). function Doc:indent_text(unindent, line1, col1, line2, col2) - local text = get_indent_string() + local text = self:get_indent_string() local _, se = self.lines[line1]:find("^[ \t]+") local in_beginning_whitespace = col1 == 1 or (se and col1 <= se + 1) local has_selection = line1 ~= line2 or col1 ~= col2 if unindent or has_selection or in_beginning_whitespace then local l1d, l2d = #self.lines[line1], #self.lines[line2] for line = line1, line2 do - local e, rnded = get_line_indent(self.lines[line], unindent) + local e, rnded = self:get_line_indent(self.lines[line], unindent) self:remove(line, 1, line, (e or 0) + 1) self:insert(line, 1, unindent and rnded:sub(1, #rnded - #text) or rnded .. text) diff --git a/data/core/docview.lua b/data/core/docview.lua index 60ef62bc..74fbb0bb 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -395,8 +395,8 @@ end function DocView:draw() self:draw_background(style.background) - - self:get_font():set_tab_size(config.indent_size) + local _, indent_size = self.doc:get_indent_info() + self:get_font():set_tab_size(indent_size) local minline, maxline = self:get_visible_line_range() local lh = self:get_line_height() diff --git a/data/core/statusview.lua b/data/core/statusview.lua index 3342bdb9..59773cf0 100644 --- a/data/core/statusview.lua +++ b/data/core/statusview.lua @@ -108,9 +108,9 @@ function StatusView:get_items() local dv = core.active_view local line, col = dv.doc:get_selection() local dirty = dv.doc:is_dirty() - local indent = dv.doc.indent_info - local indent_label = (indent and indent.type == "hard") and "tabs: " or "spaces: " - local indent_size = indent and tostring(indent.size) .. (indent.confirmed and "" or "*") or "unknown" + local indent_type, indent_size, indent_confirmed = dv.doc:get_indent_info() + local indent_label = (indent_type == "hard") and "tabs: " or "spaces: " + local indent_size_str = tostring(indent_size) .. (indent_confirmed and "" or "*") or "unknown" return { dirty and style.accent or style.text, style.icon_font, "f", From 2de48b6ac8541f90949c9ca03db3a3bcf5ecd36e Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sat, 20 Nov 2021 03:22:53 +0100 Subject: [PATCH 03/10] Adapt `detectindent` to the new indentation architecture --- data/plugins/detectindent.lua | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/data/plugins/detectindent.lua b/data/plugins/detectindent.lua index 20541c82..9ac29882 100644 --- a/data/plugins/detectindent.lua +++ b/data/plugins/detectindent.lua @@ -121,40 +121,17 @@ end local clean = Doc.clean function Doc:clean(...) clean(self, ...) - if not cache[self].confirmed then + local _, _, confirmed = self:get_indent_info() + if not confirmed then update_cache(self) end end -local function with_indent_override(doc, fn, ...) - local c = cache[doc] - if not c then - return fn(...) - end - local type, size = config.tab_type, config.indent_size - config.tab_type, config.indent_size = c.type, c.size or config.indent_size - local r1, r2, r3 = fn(...) - config.tab_type, config.indent_size = type, size - return r1, r2, r3 -end - - -local perform = command.perform -function command.perform(...) - return with_indent_override(core.active_view.doc, perform, ...) -end - - -local draw = DocView.draw -function DocView:draw(...) - return with_indent_override(self.doc, draw, self, ...) -end - - local function set_indent_type(doc, type) + local _, indent_size = doc:get_indent_info() cache[doc] = {type = type, - size = cache[doc].value or config.indent_size, + size = indent_size, confirmed = true} doc.indent_info = cache[doc] end @@ -180,7 +157,8 @@ end local function set_indent_size(doc, size) - cache[doc] = {type = cache[doc].type or config.tab_type, + local indent_type = doc:get_indent_info() + cache[doc] = {type = indent_type, size = size, confirmed = true} doc.indent_info = cache[doc] From cc3fddd1e56b44a2bd98582b72080093bb5c9800 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 23 Nov 2021 20:34:01 -0500 Subject: [PATCH 04/10] Added in check to make sure you can use a scrollbar on a split. --- data/core/rootview.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 49da2923..bedea557 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -877,11 +877,11 @@ end function RootView:on_mouse_pressed(button, x, y, clicks) local div = self.root_node:get_divider_overlapping_point(x, y) - if div then + local node = self.root_node:get_child_overlapping_point(x, y) + if div and (node and not node.active_view:scrollbar_overlaps_point(x, y)) then self.dragged_divider = div return true end - local node = self.root_node:get_child_overlapping_point(x, y) if node.hovered_scroll_button > 0 then node:scroll_tabs(node.hovered_scroll_button) return true @@ -1030,7 +1030,7 @@ function RootView:on_mouse_moved(x, y, dx, dy) local tab_index = self.overlapping_node and self.overlapping_node:get_tab_overlapping_point(x, y) if self.overlapping_node and self.overlapping_node:get_scroll_button_index(x, y) then core.request_cursor("arrow") - elseif div then + elseif div and (self.overlapping_node and not self.overlapping_node.active_view:scrollbar_overlaps_point(x, y)) then core.request_cursor(div.type == "hsplit" and "sizeh" or "sizev") elseif tab_index then core.request_cursor("arrow") @@ -1125,10 +1125,10 @@ function RootView:update_drag_overlay() if split_type == "tab" and (over ~= self.dragged_node.node or #over.views > 1) then local tab_index, tab_x, tab_y, tab_w, tab_h = over:get_drag_overlay_tab_position(self.mouse.x, self.mouse.y) self:set_drag_overlay(self.drag_overlay_tab, - tab_x + (tab_index and 0 or tab_w), tab_y, - style.caret_width, tab_h, - -- avoid showing tab overlay moving between nodes - over ~= self.drag_overlay_tab.last_over) + tab_x + (tab_index and 0 or tab_w), tab_y, + style.caret_width, tab_h, + -- avoid showing tab overlay moving between nodes + over ~= self.drag_overlay_tab.last_over) self:set_show_overlay(self.drag_overlay, false) self.drag_overlay_tab.last_over = over else From 64f66e5d1e22d8ea38fdc7b8830cfe4b4c008c06 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 23 Nov 2021 21:03:38 -0500 Subject: [PATCH 05/10] Added in cut, copy and paste to the context menu. Also removed find pattern, as that's no longer a valid command. Also made it so commands only show up if their predicates are valid. --- data/core/command.lua | 3 +++ data/core/commands/doc.lua | 31 ++++++++++++++++++------------- data/core/contextmenu.lua | 8 ++++++-- data/core/doc/init.lua | 7 +++++++ data/plugins/contextmenu.lua | 16 ++++++++-------- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/data/core/command.lua b/data/core/command.lua index 2531fb96..2cf851da 100644 --- a/data/core/command.lua +++ b/data/core/command.lua @@ -41,6 +41,9 @@ function command.get_all_valid() return res end +function command.is_valid(name, ...) + return command.map[name] and command.map[name].predicate(...) +end local function perform(name, ...) local cmd = command.map[name] diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index fe1fa3b1..89a17be0 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -92,6 +92,21 @@ local function set_cursor(x, y, snap_type) core.blink_reset() end +local selection_commands = { + ["doc:cut"] = function() + cut_or_copy(true) + end, + + ["doc:copy"] = function() + cut_or_copy(false) + end, + + ["doc:select-none"] = function() + local line, col = doc():get_selection() + doc():set_selection(line, col) + end +} + local commands = { ["doc:undo"] = function() doc():undo() @@ -101,14 +116,6 @@ local commands = { doc():redo() end, - ["doc:cut"] = function() - cut_or_copy(true) - end, - - ["doc:copy"] = function() - cut_or_copy(false) - end, - ["doc:paste"] = function() local clipboard = system.get_clipboard() -- If the clipboard has changed since our last look, use that instead @@ -173,11 +180,6 @@ local commands = { doc():set_selection(1, 1, math.huge, math.huge) end, - ["doc:select-none"] = function() - local line, col = doc():get_selection() - doc():set_selection(line, col) - end, - ["doc:select-lines"] = function() for idx, line1, _, line2 in doc():get_selections(true) do append_line_if_last_line(line2) @@ -481,3 +483,6 @@ commands["doc:move-to-next-char"] = function() end command.add("core.docview", commands) +command.add(function() + return core.active_view:is(DocView) and core.active_view.doc:has_any_selection() +end ,selection_commands) diff --git a/data/core/contextmenu.lua b/data/core/contextmenu.lua index d6131cdf..9db35bb3 100644 --- a/data/core/contextmenu.lua +++ b/data/core/contextmenu.lua @@ -66,9 +66,13 @@ function ContextMenu:show(x, y) for _, items in ipairs(self.itemset) do if items.predicate(x, y) then items_list.width = math.max(items_list.width, items.items.width) - items_list.height = items_list.height + items.items.height + items_list.height = items_list.height for _, subitems in ipairs(items.items) do - table.insert(items_list, subitems) + if not subitems.command or command.is_valid(subitems.command) then + local lw, lh = get_item_size(subitems) + items_list.height = items_list.height + lh + table.insert(items_list, subitems) + end end end end diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 03dcc31e..a46e428c 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -149,6 +149,13 @@ function Doc:has_selection() return line1 ~= line2 or col1 ~= col2 end +function Doc:has_any_selection() + for idx, line1, col1, line2, col2 in self:get_selections() do + if line1 ~= line2 or col1 ~= col2 then return true end + end + return false +end + function Doc:sanitize_selection() for idx, line1, col1, line2, col2 in self:get_selections() do self:set_selections(idx, line1, col1, line2, col2) diff --git a/data/plugins/contextmenu.lua b/data/plugins/contextmenu.lua index dc95567f..4b34dfd5 100644 --- a/data/plugins/contextmenu.lua +++ b/data/plugins/contextmenu.lua @@ -62,15 +62,15 @@ menu:register("core.logview", { if require("plugins.scale") then menu:register("core.docview", { - { text = "Font +", command = "scale:increase" }, - { text = "Font -", command = "scale:decrease" }, - { text = "Font Reset", command = "scale:reset" }, + { text = "Cut", command = "doc:cut" }, + { text = "Copy", command = "doc:copy" }, + { text = "Paste", command = "doc:paste" }, + { text = "Font +", command = "scale:increase" }, + { text = "Font -", command = "scale:decrease" }, + { text = "Font Reset", command = "scale:reset" }, ContextMenu.DIVIDER, - { text = "Find", command = "find-replace:find" }, - { text = "Replace", command = "find-replace:replace" }, - ContextMenu.DIVIDER, - { text = "Find Pattern", command = "find-replace:find-pattern" }, - { text = "Replace Pattern", command = "find-replace:replace-pattern" }, + { text = "Find", command = "find-replace:find" }, + { text = "Replace", command = "find-replace:replace" } }) end From 463605ff41a844d3b301a5fe21f6f27ca5e510e8 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 23 Nov 2021 21:56:07 -0500 Subject: [PATCH 06/10] Fixed event propogation. --- data/core/rootview.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 49da2923..e497919e 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -900,9 +900,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks) end elseif not self.dragged_node then -- avoid sending on_mouse_pressed events when dragging tabs core.set_active_view(node.active_view) - if not self.on_view_mouse_pressed(button, x, y, clicks) then - return node.active_view:on_mouse_pressed(button, x, y, clicks) - end + return self.on_view_mouse_pressed(button, x, y, clicks) or node.active_view:on_mouse_pressed(button, x, y, clicks) end end From 7ee23da1870525b3dd4820f1add874f2437ccd13 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 23 Nov 2021 22:30:35 -0500 Subject: [PATCH 07/10] Added in additional environment variables to scale off of. --- 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 31fed147..f3bc89c6 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -2,7 +2,7 @@ VERSION = "@PROJECT_VERSION@" MOD_VERSION = "2" -SCALE = tonumber(os.getenv("LITE_SCALE")) or SCALE +SCALE = tonumber(os.getenv("LITE_SCALE") or os.getenv("GDK_SCALE") or os.getenv("QT_SCALE_FACTOR")) or SCALE PATHSEP = package.config:sub(1, 1) EXEDIR = EXEFILE:match("^(.+)[/\\][^/\\]+$") From 59f64088e1e88f2f2a29e4d5418ccdf781fdc12e Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 24 Nov 2021 06:16:54 +0100 Subject: [PATCH 08/10] Remove changed files/dirs from `TreeView` cache --- data/core/init.lua | 2 +- data/plugins/treeview.lua | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index 35609496..b0aef1af 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -1157,7 +1157,7 @@ end -- no-op but can be overrided by plugins -function core.on_dirmonitor_modify() +function core.on_dirmonitor_modify(dir, filepath) end diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 659393ec..2e66083a 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -42,6 +42,14 @@ function TreeView:new() self.target_size = default_treeview_size self.cache = {} self.tooltip = { x = 0, y = 0, begin = 0, alpha = 0 } + + local on_dirmonitor_modify = core.on_dirmonitor_modify + function core.on_dirmonitor_modify(dir, filepath) + if self.cache[dir.name] then + self.cache[dir.name][filepath] = nil + end + on_dirmonitor_modify(dir, filepath) + end end From 272ecd64bf8cf7f6b0cb7d92496a7e42ec0b7ab1 Mon Sep 17 00:00:00 2001 From: Joshua Minor Date: Fri, 26 Nov 2021 23:25:34 -0800 Subject: [PATCH 09/10] Removed docs for get_width_subpixel and subpixel_scale which no longer exist. --- docs/api/renderer.lua | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/docs/api/renderer.lua b/docs/api/renderer.lua index 6820a14d..7a9b636d 100644 --- a/docs/api/renderer.lua +++ b/docs/api/renderer.lua @@ -61,15 +61,6 @@ function renderer.font:set_tab_size(chars) end ---@return number function renderer.font:get_width(text) end ---- ----Get the width in subpixels of the given text when ----rendered with this font. ---- ----@param text string ---- ----@return number -function renderer.font:get_width_subpixel(text) end - --- ---Get the height in pixels that occupies a single character ---when rendered with this font. @@ -77,12 +68,6 @@ function renderer.font:get_width_subpixel(text) end ---@return number function renderer.font:get_height() end ---- ----Gets the font subpixel scale. ---- ----@return number -function renderer.font:subpixel_scale() end - --- ---Get the current size of the font. --- From 01e38f041ad01f82e3b66f0e678dc059bafe79f6 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 27 Nov 2021 13:16:49 -0500 Subject: [PATCH 10/10] Used basenames for ignore_files rather than full paths. --- 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 1e343e6c..aadccc66 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -100,7 +100,7 @@ local function get_project_file_info(root, file) if info then info.filename = strip_leading_path(file) return (info.size < config.file_size_limit * 1e6 and - not common.match_pattern(info.filename, config.ignore_files) + not common.match_pattern(common.basename(info.filename), config.ignore_files) and info) end end