From 82325b6a08bfcf3243308a5ca3df1d397d5fbe33 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 17 Mar 2022 16:55:52 -0400 Subject: [PATCH 1/2] Fixed a bunch of problems. Fixed left+click not allowing for square selections, fixed esc not exiting multicursor mode, and allowed cntrl+click to remove a cursor. --- data/core/commands/doc.lua | 25 ++++++++++++++++--------- data/core/doc/init.lua | 6 ++++++ data/core/docview.lua | 1 - 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 01d85f27..81592b66 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -175,14 +175,12 @@ local function block_comment(comment, line1, col1, line2, col2) end end -local selection_commands = { +local commands = { ["doc:select-none"] = function() local line, col = doc():get_selection() doc():set_selection(line, col) - end -} - -local commands = { + end, + ["doc:cut"] = function() cut_or_copy(true) end, @@ -523,7 +521,19 @@ local commands = { ["doc:split-cursor"] = function(x, y, clicks) local line, col = dv():resolve_screen_position(x, y) - doc():add_selection(line, col, line, col) + local removal_target = nil + for idx, line1, col1 in doc():get_selections(true) do + if line1 == line and col1 == col and #doc().selections > 4 then + removal_target = idx + end + end + end + if removal_target then + doc():remove_selection(removal_target) + else + doc():add_selection(line, col, line, col) + end + dv().mouse_selecting = { line, col, "set" } end, ["doc:create-cursor-previous-line"] = function() @@ -584,6 +594,3 @@ commands["doc:move-to-next-char"] = function() end command.add("core.docview", commands) -command.add(function() - return core.active_view:is(DocView) and core.active_view.doc:has_any_selection() -end ,selection_commands) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index ab4b18a0..0a0756a8 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -198,6 +198,12 @@ function Doc:add_selection(line1, col1, line2, col2, swap) self:set_selections(target, line1, col1, line2, col2, swap, 0) end + +function Doc:remove_selection(idx) + common.splice(self.selections, (idx - 1) * 4 + 1, 4) +end + + function Doc:set_selection(line1, col1, line2, col2, swap) self.selections = {} self:set_selections(1, line1, col1, line2, col2, swap) diff --git a/data/core/docview.lua b/data/core/docview.lua index 70403e68..397b455e 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -224,7 +224,6 @@ function DocView:scroll_to_make_visible(line, col) end end - function DocView:on_mouse_moved(x, y, ...) DocView.super.on_mouse_moved(self, x, y, ...) From ba5289dc75b6ffa0f99b08a08af32cfade0b0462 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 17 Mar 2022 16:57:18 -0400 Subject: [PATCH 2/2] Typo. --- data/core/commands/doc.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 81592b66..d80c4641 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -522,10 +522,9 @@ local commands = { ["doc:split-cursor"] = function(x, y, clicks) local line, col = dv():resolve_screen_position(x, y) local removal_target = nil - for idx, line1, col1 in doc():get_selections(true) do - if line1 == line and col1 == col and #doc().selections > 4 then - removal_target = idx - end + for idx, line1, col1 in doc():get_selections(true) do + if line1 == line and col1 == col and #doc().selections > 4 then + removal_target = idx end end if removal_target then