Merge pull request #886 from adamharrison/fix-left-click-issues

Fixed a bunch of problems relating to multicursor.
This commit is contained in:
Jefferson González 2022-03-17 21:00:51 -04:00 committed by GitHub
commit 0e323f4a35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -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,18 @@ 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
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 +593,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)

View File

@ -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)

View File

@ -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, ...)