From 6f53ee1b69c6f23aba2a425130975b9d707f8274 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 5 Oct 2021 19:20:06 -0400 Subject: [PATCH] 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