Added in double, and triple clicking.

This commit is contained in:
Adam Harrison 2021-10-05 19:20:06 -04:00
parent 4a0d390a7c
commit 6f53ee1b69
4 changed files with 14 additions and 35 deletions

View File

@ -388,27 +388,15 @@ local commands = {
os.remove(filename) os.remove(filename)
core.log("Removed \"%s\"", filename) core.log("Removed \"%s\"", filename)
end, 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) ["doc:set-cursor"] = function(x, y, clicks)
local line, col = dv():resolve_screen_position(x, y) local line, col = dv():resolve_screen_position(x, y)
doc():set_selection(dv():mouse_selection(doc(), clicks, line, col, line, col)) doc():set_selection(line, col, line, col)
dv().mouse_selecting = { line, col, clicks = clicks }
core.blink_reset()
end, end,
["doc:split-cursor"] = function(x, y, clicks) ["doc:split-cursor"] = function(x, y, clicks)
local line, col = dv():resolve_screen_position(x, y) local line, col = dv():resolve_screen_position(x, y)
doc():add_selection(dv():mouse_selection(doc(), clicks, line, col, line, col)) doc():add_selection(line, col, line, col)
dv().mouse_selecting = { line, col, clicks = clicks }
core.blink_reset()
end, end,
["doc:create-cursor-previous-line"] = function() ["doc:create-cursor-previous-line"] = function()

View File

@ -224,25 +224,13 @@ function DocView:scroll_to_make_visible(line, col)
end end
end end
function DocView:on_mouse_pressed(button, x, y, clicks)
function DocView:mouse_selection(doc, clicks, line1, col1, line2, col2) local line, col = self:resolve_screen_position(x, y)
local swap = line2 < line1 or line2 == line1 and col2 <= col1 self.mouse_selecting = { line, col, clicks = clicks }
if swap then if DocView.super.on_mouse_pressed(self, button, x, y, clicks) then
line1, col1, line2, col2 = line2, col2, line1, col1 return
end end
if clicks % 4 == 2 then core.blink_reset()
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
end end
function DocView:on_mouse_moved(x, y, ...) 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])) self.doc:set_selections(i - l1 + 1, i, math.min(c1, #self.doc.lines[i]), i, math.min(c2, #self.doc.lines[i]))
end end
else 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 end
end end

View File

@ -196,6 +196,8 @@ keymap.add_direct {
["shift+lclick"] = "doc:select-to-cursor", ["shift+lclick"] = "doc:select-to-cursor",
["ctrl+lclick"] = "doc:split-cursor", ["ctrl+lclick"] = "doc:split-cursor",
["lclick"] = "doc:set-cursor", ["lclick"] = "doc:set-cursor",
["dlclick"] = "doc:select-word",
["tlclick"] = "doc:select-lines",
["shift+left"] = "doc:select-to-previous-char", ["shift+left"] = "doc:select-to-previous-char",
["shift+right"] = "doc:select-to-next-char", ["shift+right"] = "doc:select-to-next-char",
["shift+up"] = "doc:select-to-previous-line", ["shift+up"] = "doc:select-to-previous-line",

View File

@ -76,12 +76,13 @@ function View:scrollbar_overlaps_point(x, y)
end end
local click_prefixes = { "", "d", "t" }
function View:on_mouse_pressed(button, x, y, clicks) function View:on_mouse_pressed(button, x, y, clicks)
if self:scrollbar_overlaps_point(x, y) then if self:scrollbar_overlaps_point(x, y) then
self.dragging_scrollbar = true self.dragging_scrollbar = true
return true return true
end 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 end