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.

This commit is contained in:
Adam Harrison 2022-03-17 16:55:52 -04:00
parent 120c769e7e
commit 82325b6a08
3 changed files with 22 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,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)

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