From 612818ca0564e38698b3df6779fc969b82aae0ed Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 18:22:43 -0400 Subject: [PATCH 01/17] 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 02/17] 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 03/17] 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 04/17] 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 05/17] 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 06/17] 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 07/17] 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 08/17] 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 09/17] 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 10/17] 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 11/17] 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 12/17] 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 13/17] 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 14/17] 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 15/17] 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 16/17] 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 17/17] 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)