From 3b3677ca4b21e8384fe505d842cd88feecf56ad4 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Sat, 10 Jul 2021 22:47:03 +0800 Subject: [PATCH 01/25] add config.lineguide option --- data/plugins/lineguide.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/data/plugins/lineguide.lua b/data/plugins/lineguide.lua index 8ef3ee68..adc67389 100644 --- a/data/plugins/lineguide.lua +++ b/data/plugins/lineguide.lua @@ -6,16 +6,18 @@ local DocView = require "core.docview" local draw_overlay = DocView.draw_overlay function DocView:draw_overlay(...) - local ns = ("n"):rep(config.line_limit) - local ss = self:get_font():subpixel_scale() - local offset = self:get_font():get_width_subpixel(ns) / ss - local x = self:get_line_screen_position(1) + offset - local y = self.position.y - local w = math.ceil(SCALE * 1) - local h = self.size.y + if config.lineguide then + local ns = self:get_font():get_width_subpixel("n") * config.line_limit + local ss = self:get_font():subpixel_scale() + local offset = ns / ss + local x = self:get_line_screen_position(1) + offset + local y = self.position.y + local w = math.ceil(SCALE * 1) + local h = self.size.y - local color = style.guide or style.selection - renderer.draw_rect(x, y, w, h, color) + local color = style.guide or style.selection + renderer.draw_rect(x, y, w, h, color) + end draw_overlay(self, ...) end From 1725b3ab834f79020c520080ac5184c6d1dfb122 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Mon, 2 Aug 2021 09:54:55 +0800 Subject: [PATCH 02/25] revert config.lineguide option --- data/plugins/lineguide.lua | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/data/plugins/lineguide.lua b/data/plugins/lineguide.lua index adc67389..b838eebb 100644 --- a/data/plugins/lineguide.lua +++ b/data/plugins/lineguide.lua @@ -6,18 +6,16 @@ local DocView = require "core.docview" local draw_overlay = DocView.draw_overlay function DocView:draw_overlay(...) - if config.lineguide then - local ns = self:get_font():get_width_subpixel("n") * config.line_limit - local ss = self:get_font():subpixel_scale() - local offset = ns / ss - local x = self:get_line_screen_position(1) + offset - local y = self.position.y - local w = math.ceil(SCALE * 1) - local h = self.size.y + local ns = self:get_font():get_width_subpixel("n") * config.line_limit + local ss = self:get_font():subpixel_scale() + local offset = ns / ss + local x = self:get_line_screen_position(1) + offset + local y = self.position.y + local w = math.ceil(SCALE * 1) + local h = self.size.y - local color = style.guide or style.selection - renderer.draw_rect(x, y, w, h, color) - end + local color = style.guide or style.selection + renderer.draw_rect(x, y, w, h, color) draw_overlay(self, ...) end From 30ccde896d1ffe37cbd8990e9b8aaef275e18935 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Sun, 29 Aug 2021 09:14:12 +0800 Subject: [PATCH 03/25] replace unpack() with table.unpack() I have no idea unpack() is still used and how it still worked. --- data/core/commands/findreplace.lua | 12 ++++++------ data/core/doc/init.lua | 10 +++++----- data/core/tokenizer.lua | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 6dd7ddae..d5d9f6a3 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -36,7 +36,7 @@ local function update_preview(sel, search_fn, text) last_view:scroll_to_line(line2, true) return true else - last_view.doc:set_selection(unpack(sel)) + last_view.doc:set_selection(table.unpack(sel)) return false end end @@ -44,7 +44,7 @@ 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, found = last_view.doc:get_text(table.unpack(last_sel)), false core.command_view:set_text(text, true) core.status_view:show_tooltip(get_find_tooltip()) @@ -55,8 +55,8 @@ local function find(label, search_fn) last_fn, last_text = search_fn, text else core.error("Couldn't find %q", text) - last_view.doc:set_selection(unpack(last_sel)) - last_view:scroll_to_make_visible(unpack(last_sel)) + last_view.doc:set_selection(table.unpack(last_sel)) + last_view:scroll_to_make_visible(table.unpack(last_sel)) end end, function(text) found = update_preview(last_sel, search_fn, text) @@ -64,8 +64,8 @@ local function find(label, search_fn) end, function(explicit) core.status_view:remove_tooltip() if explicit then - last_view.doc:set_selection(unpack(last_sel)) - last_view:scroll_to_make_visible(unpack(last_sel)) + last_view.doc:set_selection(table.unpack(last_sel)) + last_view:scroll_to_make_visible(table.unpack(last_sel)) end end) end diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 4a231295..067cf9e6 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -198,9 +198,9 @@ local function selection_iterator(invariant, idx) local target = invariant[3] and (idx*4 - 7) or (idx*4 + 1) if target > #invariant[1] or target <= 0 or (type(invariant[3]) == "number" and invariant[3] ~= idx - 1) then return end if invariant[2] then - return idx+(invariant[3] and -1 or 1), sort_positions(unpack(invariant[1], target, target+4)) + return idx+(invariant[3] and -1 or 1), sort_positions(table.unpack(invariant[1], target, target+4)) else - return idx+(invariant[3] and -1 or 1), unpack(invariant[1], target, target+4) + return idx+(invariant[3] and -1 or 1), table.unpack(invariant[1], target, target+4) end end @@ -301,7 +301,7 @@ local function pop_undo(self, undo_stack, redo_stack, modified) local line1, col1, line2, col2 = table.unpack(cmd) self:raw_remove(line1, col1, line2, col2, redo_stack, cmd.time) elseif cmd.type == "selection" then - self.selections = { unpack(cmd) } + self.selections = { table.unpack(cmd) } end modified = modified or (cmd.type ~= "selection") @@ -335,7 +335,7 @@ function Doc:raw_insert(line, col, text, undo_stack, time) -- 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, "selection", table.unpack(self.selections)) push_undo(undo_stack, time, "remove", line, col, line2, col2) -- update highlighter and assure selection is in bounds @@ -347,7 +347,7 @@ end function Doc:raw_remove(line1, col1, line2, col2, undo_stack, time) -- push undo local text = self:get_text(line1, col1, line2, col2) - push_undo(undo_stack, time, "selection", unpack(self.selections)) + push_undo(undo_stack, time, "selection", table.unpack(self.selections)) push_undo(undo_stack, time, "insert", line1, col1, text) -- get line content before/after removed text diff --git a/data/core/tokenizer.lua b/data/core/tokenizer.lua index a20dba5e..bdf6197b 100644 --- a/data/core/tokenizer.lua +++ b/data/core/tokenizer.lua @@ -155,7 +155,7 @@ function tokenizer.tokenize(incoming_syntax, text, state) if count % 2 == 0 then break end end until not res[1] or not close or not target[3] - return unpack(res) + return table.unpack(res) end while i <= #text do From 7e4236a82fc2a7cbef11a5f31fbc194e2f43521c Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Wed, 8 Sep 2021 23:09:20 +0800 Subject: [PATCH 04/25] add keymap.unbind(), update contextmenu to use keymap.get_binding() This is something probably people are looking for... --- data/core/contextmenu.lua | 2 +- data/core/keymap.lua | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/data/core/contextmenu.lua b/data/core/contextmenu.lua index 36247597..d6131cdf 100644 --- a/data/core/contextmenu.lua +++ b/data/core/contextmenu.lua @@ -49,7 +49,7 @@ function ContextMenu:register(predicate, items) local width, height = 0, 0 --precalculate the size of context menu for i, item in ipairs(items) do if item ~= DIVIDER then - item.info = keymap.reverse_map[item.command] + item.info = keymap.get_binding(item.command) end local lw, lh = get_item_size(item) width = math.max(width, lw) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 2be0dfc7..759362d1 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -5,10 +5,9 @@ keymap.modkeys = {} keymap.map = {} keymap.reverse_map = {} -local macos = rawget(_G, "MACOS") -- Thanks to mathewmariani, taken from his lite-macos github repository. -local modkeys_os = require("core.modkeys-" .. (macos and "macos" or "generic")) +local modkeys_os = require("core.modkeys-" .. (MACOS and "macos" or "generic")) local modkey_map = modkeys_os.map local modkeys = modkeys_os.keys @@ -30,14 +29,15 @@ function keymap.add_direct(map) end keymap.map[stroke] = commands for _, cmd in ipairs(commands) do - keymap.reverse_map[cmd] = stroke + keymap.reverse_map[cmd] = keymap.reverse_map[cmd] or {} + table.insert(keymap.reverse_map[cmd], stroke) end end end function keymap.add(map, overwrite) for stroke, commands in pairs(map) do - if macos then + if MACOS then stroke = stroke:gsub("%f[%a]ctrl%f[%A]", "cmd") end if type(commands) == "string" then @@ -52,14 +52,39 @@ function keymap.add(map, overwrite) end end for _, cmd in ipairs(commands) do - keymap.reverse_map[cmd] = stroke + keymap.reverse_map[cmd] = keymap.reverse_map[cmd] or {} + table.insert(keymap.reverse_map[cmd], stroke) end end end +local function remove_only(tbl, k, v) + for key, values in pairs(tbl) do + if key == k then + if v then + for i, value in ipairs(values) do + if value == v then + table.remove(values, i) + end + end + else + tbl[key] = nil + end + break + end + end +end + + +function keymap.unbind(cmd, key) + remove_only(keymap.map, key, cmd) + remove_only(keymap.reverse_map, cmd, key) +end + + function keymap.get_binding(cmd) - return keymap.reverse_map[cmd] + return table.unpack(keymap.reverse_map[cmd] or {}) end @@ -94,7 +119,7 @@ function keymap.on_key_released(k) end -if macos then +if MACOS then local keymap_macos = require("core.keymap-macos") keymap_macos(keymap) return keymap From 5cc23348a1a7d106aaee36c0eb88b42ed2c9b725 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Wed, 8 Sep 2021 23:17:50 +0800 Subject: [PATCH 05/25] reverse the order of args in keymap.unbind --- data/core/keymap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 759362d1..8fd2b05b 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -77,7 +77,7 @@ local function remove_only(tbl, k, v) end -function keymap.unbind(cmd, key) +function keymap.unbind(key, cmd) remove_only(keymap.map, key, cmd) remove_only(keymap.reverse_map, cmd, key) end From 612818ca0564e38698b3df6779fc969b82aae0ed Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 18:22:43 -0400 Subject: [PATCH 06/25] Added in clicks to keymap. --- data/core/command.lua | 6 +++--- data/core/commands/doc.lua | 22 ++++++++++++++++++++++ data/core/docview.lua | 29 ++--------------------------- data/core/keymap.lua | 11 +++++++---- data/core/view.lua | 3 ++- 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/data/core/command.lua b/data/core/command.lua index 7915e16d..2531fb96 100644 --- a/data/core/command.lua +++ b/data/core/command.lua @@ -42,10 +42,10 @@ function command.get_all_valid() end -local function perform(name) +local function perform(name, ...) local cmd = command.map[name] - if cmd and cmd.predicate() then - cmd.perform() + if cmd and cmd.predicate(...) then + cmd.perform(...) return true end return false diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index b8ce2cb5..db2f0428 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -388,6 +388,28 @@ local commands = { os.remove(filename) core.log("Removed \"%s\"", filename) end, + + ["doc:select-to-cursor"] = function(x, y, clicks) + if clicks % 2 == 1 then + local line1, col1 = select(3, doc():get_selection()) + local line2, col2 = dv():resolve_screen_position(x, y) + doc():set_selection(line2, col2, line1, col1) + end + end, + + ["doc:set-cursor"] = function(x, y, clicks) + local line, col = dv():resolve_screen_position(x, y) + doc():set_selection(dv():mouse_selection(doc(), clicks, line, col, line, col)) + dv().mouse_selecting = { line, col, clicks = clicks } + core.blink_reset() + end, + + ["doc:split-cursor"] = function(x, y, clicks) + local line, col = dv():resolve_screen_position(x, y) + doc():add_selection(dv():mouse_selection(doc(), clicks, line, col, line, col)) + dv().mouse_selecting = { line, col, clicks = clicks } + core.blink_reset() + end, ["doc:create-cursor-previous-line"] = function() split_cursor(-1) diff --git a/data/core/docview.lua b/data/core/docview.lua index 4e95c359..1c041a27 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -225,7 +225,7 @@ function DocView:scroll_to_make_visible(line, col) end -local function mouse_selection(doc, clicks, line1, col1, line2, col2) +function DocView:mouse_selection(doc, clicks, line1, col1, line2, col2) local swap = line2 < line1 or line2 == line1 and col2 <= col1 if swap then line1, col1, line2, col2 = line2, col2, line1, col1 @@ -245,31 +245,6 @@ local function mouse_selection(doc, clicks, line1, col1, line2, col2) return line1, col1, line2, col2 end - -function DocView:on_mouse_pressed(button, x, y, clicks) - local caught = DocView.super.on_mouse_pressed(self, button, x, y, clicks) - if caught then - return - end - if keymap.modkeys["shift"] then - if clicks % 2 == 1 then - local line1, col1 = select(3, self.doc:get_selection()) - local line2, col2 = self:resolve_screen_position(x, y) - self.doc:set_selection(line2, col2, line1, col1) - end - else - local line, col = self:resolve_screen_position(x, y) - if keymap.modkeys["ctrl"] then - self.doc:add_selection(mouse_selection(self.doc, clicks, line, col, line, col)) - else - self.doc:set_selection(mouse_selection(self.doc, clicks, line, col, line, col)) - end - self.mouse_selecting = { line, col, clicks = clicks } - end - core.blink_reset() -end - - function DocView:on_mouse_moved(x, y, ...) DocView.super.on_mouse_moved(self, x, y, ...) @@ -290,7 +265,7 @@ function DocView:on_mouse_moved(x, y, ...) self.doc:set_selections(i - l1 + 1, i, math.min(c1, #self.doc.lines[i]), i, math.min(c2, #self.doc.lines[i])) end else - self.doc:set_selection(mouse_selection(self.doc, clicks, l1, c1, l2, c2)) + self.doc:set_selection(self:mouse_selection(self.doc, clicks, l1, c1, l2, c2)) end end end diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 7f7c0fe2..3b8a756e 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -63,7 +63,7 @@ function keymap.get_binding(cmd) end -function keymap.on_key_pressed(k) +function keymap.on_key_pressed(k, ...) local mk = modkey_map[k] if mk then keymap.modkeys[mk] = true @@ -73,13 +73,13 @@ function keymap.on_key_pressed(k) end else local stroke = key_to_stroke(k) - local commands = keymap.map[stroke] + local commands, performed = keymap.map[stroke] if commands then for _, cmd in ipairs(commands) do - local performed = command.perform(cmd) + performed = command.perform(cmd, ...) if performed then break end end - return true + return performed end end return false @@ -193,6 +193,9 @@ keymap.add_direct { ["pageup"] = "doc:move-to-previous-page", ["pagedown"] = "doc:move-to-next-page", + ["shift+lclick"] = "doc:select-to-cursor", + ["ctrl+lclick"] = "doc:split-cursor", + ["lclick"] = "doc:set-cursor", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", diff --git a/data/core/view.lua b/data/core/view.lua index d1374ee4..7b4f2e46 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -3,7 +3,7 @@ local config = require "core.config" local style = require "core.style" local common = require "core.common" local Object = require "core.object" - +local keymap = require "core.keymap" local View = Object:extend() @@ -81,6 +81,7 @@ function View:on_mouse_pressed(button, x, y, clicks) self.dragging_scrollbar = true return true end + return keymap.on_key_pressed(button:sub(1,1) .. "click", x, y, clicks) end From 4a0d390a7cd06d4d4e23637e0b599f97db1bd793 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 18:29:00 -0400 Subject: [PATCH 07/25] Added in macos keys. --- data/core/keymap-macos.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index 53a20468..bc69aaaa 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -93,6 +93,9 @@ local function keymap_macos(keymap) ["pageup"] = "doc:move-to-previous-page", ["pagedown"] = "doc:move-to-next-page", + ["shift+lclick"] = "doc:select-to-cursor", + ["ctrl+lclick"] = "doc:split-cursor", + ["lclick"] = "doc:set-cursor", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", From 6f53ee1b69c6f23aba2a425130975b9d707f8274 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 19:20:06 -0400 Subject: [PATCH 08/25] Added in double, and triple clicking. --- data/core/commands/doc.lua | 18 +++--------------- data/core/docview.lua | 26 +++++++------------------- data/core/keymap.lua | 2 ++ data/core/view.lua | 3 ++- 4 files changed, 14 insertions(+), 35 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index db2f0428..ee6f8680 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -388,27 +388,15 @@ local commands = { os.remove(filename) core.log("Removed \"%s\"", filename) end, - - ["doc:select-to-cursor"] = function(x, y, clicks) - if clicks % 2 == 1 then - local line1, col1 = select(3, doc():get_selection()) - local line2, col2 = dv():resolve_screen_position(x, y) - doc():set_selection(line2, col2, line1, col1) - end - end, - + ["doc:set-cursor"] = function(x, y, clicks) local line, col = dv():resolve_screen_position(x, y) - doc():set_selection(dv():mouse_selection(doc(), clicks, line, col, line, col)) - dv().mouse_selecting = { line, col, clicks = clicks } - core.blink_reset() + doc():set_selection(line, col, line, col) end, ["doc:split-cursor"] = function(x, y, clicks) local line, col = dv():resolve_screen_position(x, y) - doc():add_selection(dv():mouse_selection(doc(), clicks, line, col, line, col)) - dv().mouse_selecting = { line, col, clicks = clicks } - core.blink_reset() + doc():add_selection(line, col, line, col) end, ["doc:create-cursor-previous-line"] = function() diff --git a/data/core/docview.lua b/data/core/docview.lua index 1c041a27..fe440274 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -224,25 +224,13 @@ function DocView:scroll_to_make_visible(line, col) end end - -function DocView:mouse_selection(doc, clicks, line1, col1, line2, col2) - local swap = line2 < line1 or line2 == line1 and col2 <= col1 - if swap then - line1, col1, line2, col2 = line2, col2, line1, col1 +function DocView:on_mouse_pressed(button, x, y, clicks) + local line, col = self:resolve_screen_position(x, y) + self.mouse_selecting = { line, col, clicks = clicks } + if DocView.super.on_mouse_pressed(self, button, x, y, clicks) then + return end - if clicks % 4 == 2 then - line1, col1 = translate.start_of_word(doc, line1, col1) - line2, col2 = translate.end_of_word(doc, line2, col2) - elseif clicks % 4 == 3 then - if line2 == #doc.lines and doc.lines[#doc.lines] ~= "\n" then - doc:insert(math.huge, math.huge, "\n") - end - line1, col1, line2, col2 = line1, 1, line2 + 1, 1 - end - if swap then - return line2, col2, line1, col1 - end - return line1, col1, line2, col2 + core.blink_reset() end function DocView:on_mouse_moved(x, y, ...) @@ -265,7 +253,7 @@ function DocView:on_mouse_moved(x, y, ...) self.doc:set_selections(i - l1 + 1, i, math.min(c1, #self.doc.lines[i]), i, math.min(c2, #self.doc.lines[i])) end else - self.doc:set_selection(self:mouse_selection(self.doc, clicks, l1, c1, l2, c2)) + self.doc:set_selection(l1, c1, l2, c2) end end end diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 3b8a756e..f7261ab6 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -196,6 +196,8 @@ keymap.add_direct { ["shift+lclick"] = "doc:select-to-cursor", ["ctrl+lclick"] = "doc:split-cursor", ["lclick"] = "doc:set-cursor", + ["dlclick"] = "doc:select-word", + ["tlclick"] = "doc:select-lines", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", diff --git a/data/core/view.lua b/data/core/view.lua index 7b4f2e46..d418d5f9 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -76,12 +76,13 @@ function View:scrollbar_overlaps_point(x, y) end +local click_prefixes = { "", "d", "t" } function View:on_mouse_pressed(button, x, y, clicks) if self:scrollbar_overlaps_point(x, y) then self.dragging_scrollbar = true return true end - return keymap.on_key_pressed(button:sub(1,1) .. "click", x, y, clicks) + return keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) end From ce2ec9f4424c2d479064d706ee1e2b741ef53fce Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 19:42:04 -0400 Subject: [PATCH 09/25] Moved commands out to the outer event loop. --- data/core/commands/doc.lua | 6 ++++++ data/core/init.lua | 4 +++- data/core/keymap-macos.lua | 2 ++ data/core/keymap.lua | 4 ++++ data/core/view.lua | 4 +--- src/api/system.c | 8 +++++--- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index ee6f8680..b7677d99 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -389,6 +389,12 @@ local commands = { core.log("Removed \"%s\"", filename) end, + ["doc:select-to-cursor"] = function(x, y, clicks) + local line1, col1 = select(3, doc():get_selection()) + local line2, col2 = dv():resolve_screen_position(x, y) + doc():set_selection(line2, col2, line1, col1) + end, + ["doc:set-cursor"] = function(x, y, clicks) local line, col = dv():resolve_screen_position(x, y) doc():set_selection(line, col, line, col) diff --git a/data/core/init.lua b/data/core/init.lua index 13d0907b..a8aa0645 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -922,7 +922,9 @@ function core.on_event(type, ...) elseif type == "mousemoved" then core.root_view:on_mouse_moved(...) elseif type == "mousepressed" then - core.root_view:on_mouse_pressed(...) + if not core.root_view:on_mouse_pressed(...) then + did_keymap = keymap.on_mouse_pressed(...) + end elseif type == "mousereleased" then core.root_view:on_mouse_released(...) elseif type == "mousewheel" then diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index bc69aaaa..aa4cccec 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -96,6 +96,8 @@ local function keymap_macos(keymap) ["shift+lclick"] = "doc:select-to-cursor", ["ctrl+lclick"] = "doc:split-cursor", ["lclick"] = "doc:set-cursor", + ["dlclick"] = "doc:select-word", + ["tlclick"] = "doc:select-lines", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", diff --git a/data/core/keymap.lua b/data/core/keymap.lua index f7261ab6..517a83ef 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -85,6 +85,10 @@ function keymap.on_key_pressed(k, ...) return false end +local click_prefixes = { "", "d", "t" } +function keymap.on_mouse_pressed(button, x, y, clicks) + return keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) +end function keymap.on_key_released(k) local mk = modkey_map[k] diff --git a/data/core/view.lua b/data/core/view.lua index d418d5f9..d1374ee4 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -3,7 +3,7 @@ local config = require "core.config" local style = require "core.style" local common = require "core.common" local Object = require "core.object" -local keymap = require "core.keymap" + local View = Object:extend() @@ -76,13 +76,11 @@ function View:scrollbar_overlaps_point(x, y) end -local click_prefixes = { "", "d", "t" } function View:on_mouse_pressed(button, x, y, clicks) if self:scrollbar_overlaps_point(x, y) then self.dragging_scrollbar = true return true end - return keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) end diff --git a/src/api/system.c b/src/api/system.c index c998fa05..4901404d 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -18,9 +18,11 @@ extern SDL_Window *window; static const char* button_name(int button) { switch (button) { - case 1 : return "left"; - case 2 : return "middle"; - case 3 : return "right"; + case SDL_BUTTON_LEFT : return "left"; + case SDL_BUTTON_MIDDLE : return "middle"; + case SDL_BUTTON_RIGHT : return "right"; + case SDL_BUTTON_X1 : return "x1"; + case SDL_BUTTON_X2 : return "x2"; default : return "?"; } } From 4e313d9fc57a9b838761b3b088f6b087d56cf9cb Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 20:00:06 -0400 Subject: [PATCH 10/25] Propogated mouse clicks correctly. --- data/core/rootview.lua | 2 +- data/plugins/projectsearch.lua | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 0d219474..d8f78024 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -877,7 +877,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks) 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 - node.active_view:on_mouse_pressed(button, x, y, clicks) + return node.active_view:on_mouse_pressed(button, x, y, clicks) end end end diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index dda3a2d0..d0d75d7f 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -92,7 +92,7 @@ end function ResultsView:on_mouse_pressed(...) local caught = ResultsView.super.on_mouse_pressed(self, ...) if not caught then - self:open_selected_result() + return self:open_selected_result() end end @@ -108,6 +108,7 @@ function ResultsView:open_selected_result() dv.doc:set_selection(res.line, res.col) dv:scroll_to_line(res.line, false, true) end) + return true end From 7905ddd26f91f546debdc95d919451a64fe129fc Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 20:02:55 -0400 Subject: [PATCH 11/25] Fixed propogation again. --- data/core/rootview.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index d8f78024..ad47ffd4 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -857,17 +857,18 @@ function RootView:on_mouse_pressed(button, x, y, clicks) local div = self.root_node:get_divider_overlapping_point(x, y) if div then self.dragged_divider = div - return + 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 + return true end local idx = node:get_tab_overlapping_point(x, y) if idx then if button == "middle" or node.hovered_close == idx then node:close_view(self.root_node, node.views[idx]) + return true else if button == "left" then self.dragged_node = { node = node, idx = idx, dragging = false, drag_start_x = x, drag_start_y = y} From 6bdcfc824d9beabfa18f61e0c99eff1c49ec9ac8 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 22:07:23 -0400 Subject: [PATCH 12/25] Rearranged things to make a bit more sense. --- data/core/commands/doc.lua | 15 +++++++++++++++ data/core/docview.lua | 10 ---------- data/core/keymap.lua | 4 ++-- data/core/rootview.lua | 1 + 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index b7677d99..90e0eee9 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -392,12 +392,27 @@ local commands = { ["doc:select-to-cursor"] = function(x, y, clicks) local line1, col1 = select(3, doc():get_selection()) local line2, col2 = dv():resolve_screen_position(x, y) + dv().mouse_selecting = { line1, col1 } doc():set_selection(line2, col2, line1, col1) end, ["doc:set-cursor"] = function(x, y, clicks) local line, col = dv():resolve_screen_position(x, y) doc():set_selection(line, col, line, col) + dv().mouse_selecting = { line, col } + core.blink_reset() + end, + + ["doc:set-cursor-word"] = function(x, y, clicks) + local line, col = dv():resolve_screen_position(x, y) + command.perform("doc:select-word") + dv().mouse_selecting = { line, col } + end, + + ["doc:set-cursor-line"] = function(x, y, clicks) + local line, col = dv():resolve_screen_position(x, y) + command.perform("doc:select-lines") + dv().mouse_selecting = { line, col } end, ["doc:split-cursor"] = function(x, y, clicks) diff --git a/data/core/docview.lua b/data/core/docview.lua index fe440274..eac5f835 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -224,15 +224,6 @@ function DocView:scroll_to_make_visible(line, col) end end -function DocView:on_mouse_pressed(button, x, y, clicks) - local line, col = self:resolve_screen_position(x, y) - self.mouse_selecting = { line, col, clicks = clicks } - if DocView.super.on_mouse_pressed(self, button, x, y, clicks) then - return - end - core.blink_reset() -end - function DocView:on_mouse_moved(x, y, ...) DocView.super.on_mouse_moved(self, x, y, ...) @@ -245,7 +236,6 @@ function DocView:on_mouse_moved(x, y, ...) if self.mouse_selecting then local l1, c1 = self:resolve_screen_position(x, y) local l2, c2 = table.unpack(self.mouse_selecting) - local clicks = self.mouse_selecting.clicks if keymap.modkeys["ctrl"] then if l1 > l2 then l1, l2 = l2, l1 end self.doc.selections = { } diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 517a83ef..3ecdd589 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -200,8 +200,8 @@ keymap.add_direct { ["shift+lclick"] = "doc:select-to-cursor", ["ctrl+lclick"] = "doc:split-cursor", ["lclick"] = "doc:set-cursor", - ["dlclick"] = "doc:select-word", - ["tlclick"] = "doc:select-lines", + ["dlclick"] = "doc:set-cursor-word", + ["tlclick"] = "doc:set-cursor-line", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", diff --git a/data/core/rootview.lua b/data/core/rootview.lua index ad47ffd4..6c3d1d2d 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -874,6 +874,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks) self.dragged_node = { node = node, idx = idx, dragging = false, drag_start_x = x, drag_start_y = y} end node:set_active_view(node.views[idx]) + return true end elseif not self.dragged_node then -- avoid sending on_mouse_pressed events when dragging tabs core.set_active_view(node.active_view) From 1968d31b7c06bfb06c1c06e844fa3f038ceaec0e Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 22:09:54 -0400 Subject: [PATCH 13/25] Keymap. --- data/core/commands/doc.lua | 2 ++ data/core/keymap-macos.lua | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 90e0eee9..a564c6f6 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -405,12 +405,14 @@ local commands = { ["doc:set-cursor-word"] = function(x, y, clicks) local line, col = dv():resolve_screen_position(x, y) + doc():set_selection(line, col, line, col) command.perform("doc:select-word") dv().mouse_selecting = { line, col } end, ["doc:set-cursor-line"] = function(x, y, clicks) local line, col = dv():resolve_screen_position(x, y) + doc():set_selection(line, col, line, col) command.perform("doc:select-lines") dv().mouse_selecting = { line, col } end, diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index aa4cccec..8d23e050 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -96,8 +96,8 @@ local function keymap_macos(keymap) ["shift+lclick"] = "doc:select-to-cursor", ["ctrl+lclick"] = "doc:split-cursor", ["lclick"] = "doc:set-cursor", - ["dlclick"] = "doc:select-word", - ["tlclick"] = "doc:select-lines", + ["dlclick"] = "doc:set-cursor-word", + ["tlclick"] = "doc:set-cursor-line", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", From c04dc648ded0cd2c21a4c5895f3b6e951783c0dc Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 22:13:16 -0400 Subject: [PATCH 14/25] Refactored things out. --- data/core/commands/doc.lua | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index a564c6f6..ba3d1f0c 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -82,6 +82,16 @@ local function split_cursor(direction) core.blink_reset() end +local function set_cursor(x, y, type) + local line, col = dv():resolve_screen_position(x, y) + doc():set_selection(line, col, line, col) + if type == "word" or type == "lines" then + command.perform("doc:select-" .. type) + end + dv().mouse_selecting = { line, col } + core.blink_reset() +end + local commands = { ["doc:undo"] = function() doc():undo() @@ -396,25 +406,16 @@ local commands = { doc():set_selection(line2, col2, line1, col1) end, - ["doc:set-cursor"] = function(x, y, clicks) - local line, col = dv():resolve_screen_position(x, y) - doc():set_selection(line, col, line, col) - dv().mouse_selecting = { line, col } - core.blink_reset() + ["doc:set-cursor"] = function(x, y) + set_cursor(x, y, "set") end, - ["doc:set-cursor-word"] = function(x, y, clicks) - local line, col = dv():resolve_screen_position(x, y) - doc():set_selection(line, col, line, col) - command.perform("doc:select-word") - dv().mouse_selecting = { line, col } - end, + ["doc:set-cursor-word"] = function(x, y) + set_cursor(x, y, "word") + end, ["doc:set-cursor-line"] = function(x, y, clicks) - local line, col = dv():resolve_screen_position(x, y) - doc():set_selection(line, col, line, col) - command.perform("doc:select-lines") - dv().mouse_selecting = { line, col } + set_cursor(x, y, "lines") end, ["doc:split-cursor"] = function(x, y, clicks) From 7a3e8ed86a5a3608cd0de0d3e9a4099d5cbbfdae Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 7 Nov 2021 14:31:15 -0500 Subject: [PATCH 15/25] Added in mousewheel as part of this. --- data/core/init.lua | 4 +++- data/core/keymap.lua | 5 +++++ data/plugins/scale.lua | 13 ++----------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index a8aa0645..d07f1cbc 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -928,7 +928,9 @@ function core.on_event(type, ...) elseif type == "mousereleased" then core.root_view:on_mouse_released(...) elseif type == "mousewheel" then - core.root_view:on_mouse_wheel(...) + if not core.root_view:on_mouse_wheel(...) then + did_keymap = keymap.on_mouse_wheel(...) + end elseif type == "resized" then core.window_mode = system.get_window_mode() elseif type == "minimized" or type == "maximized" or type == "restored" then diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 3ecdd589..ef8c03ee 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -85,6 +85,11 @@ function keymap.on_key_pressed(k, ...) return false end +function keymap.on_mouse_wheel(delta, ...) + return not keymap.on_key_pressed("wheel" .. (delta > 0 and "up" or "down"), delta, ...) + and keymap.on_key_pressed("wheel", delta, ...) +end + local click_prefixes = { "", "d", "t" } function keymap.on_mouse_pressed(button, x, y, clicks) return keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) diff --git a/data/plugins/scale.lua b/data/plugins/scale.lua index b8384609..56eabbb0 100644 --- a/data/plugins/scale.lua +++ b/data/plugins/scale.lua @@ -67,17 +67,6 @@ local function get_scale() return current_scale end -local on_mouse_wheel = RootView.on_mouse_wheel - -function RootView:on_mouse_wheel(d, ...) - if keymap.modkeys["ctrl"] and config.plugins.scale.use_mousewheel then - if d < 0 then command.perform "scale:decrease" end - if d > 0 then command.perform "scale:increase" end - else - return on_mouse_wheel(self, d, ...) - end -end - local function res_scale() set_scale(default_scale) end @@ -101,6 +90,8 @@ keymap.add { ["ctrl+0"] = "scale:reset", ["ctrl+-"] = "scale:decrease", ["ctrl+="] = "scale:increase", + ["ctrl+wheelup"] = "scale:increase", + ["ctrl+wheeldown"] = "scale:decrease" } return { From 7babed1e6b3b45d5c169a3178cd09256fd0e7c45 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 7 Nov 2021 14:38:05 -0500 Subject: [PATCH 16/25] Added in more broad strokes for clicking to match wheel. 's' is single, 'd' is double, 't' is triple, and no prefix will always take any amount of clicks. --- data/core/keymap-macos.lua | 6 +++--- data/core/keymap.lua | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index 8d23e050..d9abf876 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -93,9 +93,9 @@ local function keymap_macos(keymap) ["pageup"] = "doc:move-to-previous-page", ["pagedown"] = "doc:move-to-next-page", - ["shift+lclick"] = "doc:select-to-cursor", - ["ctrl+lclick"] = "doc:split-cursor", - ["lclick"] = "doc:set-cursor", + ["shift+slclick"] = "doc:select-to-cursor", + ["ctrl+slclick"] = "doc:split-cursor", + ["slclick"] = "doc:set-cursor", ["dlclick"] = "doc:set-cursor-word", ["tlclick"] = "doc:set-cursor-line", ["shift+left"] = "doc:select-to-previous-char", diff --git a/data/core/keymap.lua b/data/core/keymap.lua index ef8c03ee..e3fe15a4 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -90,9 +90,10 @@ function keymap.on_mouse_wheel(delta, ...) and keymap.on_key_pressed("wheel", delta, ...) end -local click_prefixes = { "", "d", "t" } +local click_prefixes = { "s", "d", "t" } function keymap.on_mouse_pressed(button, x, y, clicks) - return keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) + return not keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) + keymap.on_key_pressed(button:sub(1,1) .. "click", x, y, clicks) end function keymap.on_key_released(k) @@ -202,9 +203,9 @@ keymap.add_direct { ["pageup"] = "doc:move-to-previous-page", ["pagedown"] = "doc:move-to-next-page", - ["shift+lclick"] = "doc:select-to-cursor", - ["ctrl+lclick"] = "doc:split-cursor", - ["lclick"] = "doc:set-cursor", + ["shift+slclick"] = "doc:select-to-cursor", + ["ctrl+slclick"] = "doc:split-cursor", + ["slclick"] = "doc:set-cursor", ["dlclick"] = "doc:set-cursor-word", ["tlclick"] = "doc:set-cursor-line", ["shift+left"] = "doc:select-to-previous-char", From 50c06594455f5797ea876a83be31c4e3afbffaf2 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 7 Nov 2021 15:42:03 -0500 Subject: [PATCH 17/25] Also changed docview mousewheel into a scroll command. --- data/core/commands/root.lua | 9 +++++++++ data/core/keymap.lua | 3 ++- data/core/view.lua | 6 +----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/data/core/commands/root.lua b/data/core/commands/root.lua index e41c723d..7ebb0e60 100644 --- a/data/core/commands/root.lua +++ b/data/core/commands/root.lua @@ -3,6 +3,7 @@ local style = require "core.style" local DocView = require "core.docview" local command = require "core.command" local common = require "core.common" +local config = require "core.config" local t = { @@ -77,6 +78,14 @@ local t = { local n = (parent.a == node) and 0.1 or -0.1 parent.divider = common.clamp(parent.divider + n, 0.1, 0.9) end, + + ["root:scroll"] = function(delta) + if core.active_view and core.active_view.scrollable then + core.active_view.scroll.to.y = core.active_view.scroll.to.y + delta * -config.mouse_wheel_scroll + return true + end + return false + end } diff --git a/data/core/keymap.lua b/data/core/keymap.lua index e3fe15a4..2c60f8d9 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -92,7 +92,7 @@ end local click_prefixes = { "s", "d", "t" } function keymap.on_mouse_pressed(button, x, y, clicks) - return not keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) + return not keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) and keymap.on_key_pressed(button:sub(1,1) .. "click", x, y, clicks) end @@ -143,6 +143,7 @@ keymap.add_direct { ["alt+7"] = "root:switch-to-tab-7", ["alt+8"] = "root:switch-to-tab-8", ["alt+9"] = "root:switch-to-tab-9", + ["wheel"] = "root:scroll", ["ctrl+f"] = "find-replace:find", ["ctrl+r"] = "find-replace:replace", diff --git a/data/core/view.lua b/data/core/view.lua index d1374ee4..d6d1bcbc 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -102,13 +102,9 @@ function View:on_text_input(text) -- no-op end - function View:on_mouse_wheel(y) - if self.scrollable then - self.scroll.to.y = self.scroll.to.y + y * -config.mouse_wheel_scroll - end -end +end function View:get_content_bounds() local x = self.scroll.x From 2931bdeb68409c7d3110f63cc39db09da2ff15ee Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 7 Nov 2021 15:43:40 -0500 Subject: [PATCH 18/25] Can't forget mac. --- data/core/keymap-macos.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index d9abf876..c6564310 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -32,6 +32,8 @@ local function keymap_macos(keymap) ["cmd+7"] = "root:switch-to-tab-7", ["cmd+8"] = "root:switch-to-tab-8", ["cmd+9"] = "root:switch-to-tab-9", + ["wheel"] = "root:scroll", + ["cmd+f"] = "find-replace:find", ["cmd+r"] = "find-replace:replace", ["f3"] = "find-replace:repeat-find", From d8473a3e00cece41bc66c3bb75d1d63e897f2383 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 14 Nov 2021 15:44:54 -0500 Subject: [PATCH 19/25] Changed click prefixes to be numbers, as Takase suggested. --- data/core/config.lua | 1 + data/core/keymap-macos.lua | 10 +++++----- data/core/keymap.lua | 13 ++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/data/core/config.lua b/data/core/config.lua index 7cf23925..faffc27e 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -28,6 +28,7 @@ config.disable_blink = false config.draw_whitespace = false config.borderless = false config.tab_close_button = true +config.max_clicks = 3 -- Disable plugin loading setting to false the config entry -- of the same name. diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index c6564310..b0bd41a5 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -95,11 +95,11 @@ local function keymap_macos(keymap) ["pageup"] = "doc:move-to-previous-page", ["pagedown"] = "doc:move-to-next-page", - ["shift+slclick"] = "doc:select-to-cursor", - ["ctrl+slclick"] = "doc:split-cursor", - ["slclick"] = "doc:set-cursor", - ["dlclick"] = "doc:set-cursor-word", - ["tlclick"] = "doc:set-cursor-line", + ["shift+1lclick"] = "doc:select-to-cursor", + ["ctrl+1lclick"] = "doc:split-cursor", + ["1lclick"] = "doc:set-cursor", + ["2lclick"] = "doc:set-cursor-word", + ["3lclick"] = "doc:set-cursor-line", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 2c60f8d9..d643242f 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -90,9 +90,8 @@ function keymap.on_mouse_wheel(delta, ...) and keymap.on_key_pressed("wheel", delta, ...) end -local click_prefixes = { "s", "d", "t" } function keymap.on_mouse_pressed(button, x, y, clicks) - return not keymap.on_key_pressed(click_prefixes[((clicks - 1) % 3) + 1] .. button:sub(1,1) .. "click", x, y, clicks) and + return not keymap.on_key_pressed((((clicks - 1) % config.max_clicks) + 1) .. button:sub(1,1) .. "click", x, y, clicks) and keymap.on_key_pressed(button:sub(1,1) .. "click", x, y, clicks) end @@ -204,11 +203,11 @@ keymap.add_direct { ["pageup"] = "doc:move-to-previous-page", ["pagedown"] = "doc:move-to-next-page", - ["shift+slclick"] = "doc:select-to-cursor", - ["ctrl+slclick"] = "doc:split-cursor", - ["slclick"] = "doc:set-cursor", - ["dlclick"] = "doc:set-cursor-word", - ["tlclick"] = "doc:set-cursor-line", + ["shift+1lclick"] = "doc:select-to-cursor", + ["ctrl+1lclick"] = "doc:split-cursor", + ["1lclick"] = "doc:set-cursor", + ["2lclick"] = "doc:set-cursor-word", + ["3lclick"] = "doc:set-cursor-line", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", From acc6667f575d983c3b664e34637a99fa48bda954 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 14 Nov 2021 15:45:46 -0500 Subject: [PATCH 20/25] Bug. --- data/core/keymap.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index d643242f..da819709 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -1,4 +1,5 @@ local command = require "core.command" +local config = require "core.config" local keymap = {} keymap.modkeys = {} From 6750ddca2a07f0ff1abd3a08af97c6df94458ac6 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 14 Nov 2021 15:46:33 -0500 Subject: [PATCH 21/25] Changed name of x1 and x2 to x and y. --- src/api/system.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index 4901404d..dc87b723 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -21,8 +21,8 @@ static const char* button_name(int button) { case SDL_BUTTON_LEFT : return "left"; case SDL_BUTTON_MIDDLE : return "middle"; case SDL_BUTTON_RIGHT : return "right"; - case SDL_BUTTON_X1 : return "x1"; - case SDL_BUTTON_X2 : return "x2"; + case SDL_BUTTON_X1 : return "x"; + case SDL_BUTTON_X2 : return "y"; default : return "?"; } } From 2463c5d209de483b9fb99bd8ea65f3cb2329743a Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 14 Nov 2021 15:51:27 -0500 Subject: [PATCH 22/25] Made keymap more flexible. --- data/core/keymap.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index da819709..257be283 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -92,8 +92,11 @@ function keymap.on_mouse_wheel(delta, ...) end function keymap.on_mouse_pressed(button, x, y, clicks) - return not keymap.on_key_pressed((((clicks - 1) % config.max_clicks) + 1) .. button:sub(1,1) .. "click", x, y, clicks) and - keymap.on_key_pressed(button:sub(1,1) .. "click", x, y, clicks) + local click_number = (((clicks - 1) % config.max_clicks) + 1) + return not (keymap.on_key_pressed(click_number .. button:sub(1,1) .. "click", x, y, clicks) or + keymap.on_key_pressed(button:sub(1,1) .. "click", x, y, clicks) or + keymap.on_key_pressed(click_number .. "click", x, y, clicks) or + keymap.on_key_pressed("click", x, y, clicks)) end function keymap.on_key_released(k) From 18959aebefe22e7bcfff80a2affc8ad0fda76328 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 16 Nov 2021 19:12:39 -0500 Subject: [PATCH 23/25] Fixed predicate and minor propogation issue. --- data/core/commands/root.lua | 21 ++++++++++++--------- data/core/keymap.lua | 4 ++-- data/core/rootview.lua | 13 +++++++------ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/data/core/commands/root.lua b/data/core/commands/root.lua index 7ebb0e60..8f2536b8 100644 --- a/data/core/commands/root.lua +++ b/data/core/commands/root.lua @@ -64,7 +64,7 @@ local t = { table.insert(node.views, idx + 1, core.active_view) end end, - + ["root:shrink"] = function() local node = core.root_view:get_active_node() local parent = node:get_parent_node(core.root_view.root_node) @@ -77,14 +77,6 @@ local t = { local parent = node:get_parent_node(core.root_view.root_node) local n = (parent.a == node) and 0.1 or -0.1 parent.divider = common.clamp(parent.divider + n, 0.1, 0.9) - end, - - ["root:scroll"] = function(delta) - if core.active_view and core.active_view.scrollable then - core.active_view.scroll.to.y = core.active_view.scroll.to.y + delta * -config.mouse_wheel_scroll - return true - end - return false end } @@ -131,3 +123,14 @@ command.add(function() local node = core.root_view:get_active_node() return not node:get_locked_size() end, t) + +command.add(nil, { + ["root:scroll"] = function(delta) + local view = (core.root_view.overlapping_node and core.root_view.overlapping_node.active_view) or core.active_view + if view and view.scrollable then + view.scroll.to.y = view.scroll.to.y + delta * -config.mouse_wheel_scroll + return true + end + return false + end +}) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 7ad04399..fd552f19 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -113,8 +113,8 @@ function keymap.on_key_pressed(k, ...) end function keymap.on_mouse_wheel(delta, ...) - return not keymap.on_key_pressed("wheel" .. (delta > 0 and "up" or "down"), delta, ...) - and keymap.on_key_pressed("wheel", delta, ...) + return not (keymap.on_key_pressed("wheel" .. (delta > 0 and "up" or "down"), delta, ...) + or keymap.on_key_pressed("wheel", delta, ...)) end function keymap.on_mouse_pressed(button, x, y, clicks) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 6c3d1d2d..07f8b7bf 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -1002,17 +1002,18 @@ function RootView:on_mouse_moved(x, y, dx, dy) self.root_node:on_mouse_moved(x, y, dx, dy) - local node = self.root_node:get_child_overlapping_point(x, y) + self.overlapping_node = self.root_node:get_child_overlapping_point(x, y) + local div = self.root_node:get_divider_overlapping_point(x, y) - local tab_index = node and node:get_tab_overlapping_point(x, y) - if node and node:get_scroll_button_index(x, y) then + 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 core.request_cursor(div.type == "hsplit" and "sizeh" or "sizev") elseif tab_index then core.request_cursor("arrow") - elseif node then - core.request_cursor(node.active_view.cursor) + elseif self.overlapping_node then + core.request_cursor(self.overlapping_node.active_view.cursor) end end @@ -1020,7 +1021,7 @@ end function RootView:on_mouse_wheel(...) local x, y = self.mouse.x, self.mouse.y local node = self.root_node:get_child_overlapping_point(x, y) - node.active_view:on_mouse_wheel(...) + return node.active_view:on_mouse_wheel(...) end From 6d36f2684a376a4698a62f453cf46bba74d4b9bc Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Wed, 17 Nov 2021 08:37:37 +0800 Subject: [PATCH 24/25] add polyfill for table.pack and table.unpack --- data/core/start.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data/core/start.lua b/data/core/start.lua index 71050057..2c47c902 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -19,3 +19,6 @@ package.path = DATADIR .. '/?.lua;' .. package.path package.path = DATADIR .. '/?/init.lua;' .. package.path package.path = USERDIR .. '/?.lua;' .. package.path package.path = USERDIR .. '/?/init.lua;' .. package.path + +table.pack = table.pack or pack or function(...) return {...} end +table.unpack = table.unpack or unpack From 6a7a02542fa86dce410a0dee72fd1c8b5bcdb12b Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 17 Nov 2021 02:57:14 +0100 Subject: [PATCH 25/25] Draw only visible whitespaces --- data/plugins/drawwhitespace.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/data/plugins/drawwhitespace.lua b/data/plugins/drawwhitespace.lua index da9d1b12..7b7fa011 100644 --- a/data/plugins/drawwhitespace.lua +++ b/data/plugins/drawwhitespace.lua @@ -9,24 +9,28 @@ local draw_line_text = DocView.draw_line_text function DocView:draw_line_text(idx, x, y) local font = (self:get_font() or style.syntax_fonts["comment"]) local color = style.syntax.comment - local ty, tx = y + self:get_line_text_y_offset() + local ty = y + self:get_line_text_y_offset() + local tx local text, offset, s, e = self.doc.lines[idx], 1 + local x1, _, x2, _ = self:get_content_bounds() + local _offset = self:get_x_offset_col(idx, x1) + offset = _offset while true do s, e = text:find(" +", offset) if not s then break end tx = self:get_col_x_offset(idx, s) + x renderer.draw_text(font, string.rep("·", e - s + 1), tx, ty, color) + if tx > x + x2 then break end offset = e + 1 end - offset = 1 + offset = _offset while true do s, e = text:find("\t", offset) if not s then break end tx = self:get_col_x_offset(idx, s) + x renderer.draw_text(font, "»", tx, ty, color) + if tx > x + x2 then break end offset = e + 1 end draw_line_text(self, idx, x, y) end - -