From ce2ec9f4424c2d479064d706ee1e2b741ef53fce Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 19:42:04 -0400 Subject: [PATCH] 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 "?"; } }