Refactored things out.

This commit is contained in:
Adam Harrison 2021-10-05 22:13:16 -04:00
parent 1968d31b7c
commit c04dc648de
1 changed files with 16 additions and 15 deletions

View File

@ -82,6 +82,16 @@ local function split_cursor(direction)
core.blink_reset()
end
local function set_cursor(x, y, type)
local line, col = dv():resolve_screen_position(x, y)
doc():set_selection(line, col, line, col)
if type == "word" or type == "lines" then
command.perform("doc:select-" .. type)
end
dv().mouse_selecting = { line, col }
core.blink_reset()
end
local commands = {
["doc:undo"] = function()
doc():undo()
@ -396,25 +406,16 @@ local commands = {
doc():set_selection(line2, col2, line1, col1)
end,
["doc:set-cursor"] = function(x, y, clicks)
local line, col = dv():resolve_screen_position(x, y)
doc():set_selection(line, col, line, col)
dv().mouse_selecting = { line, col }
core.blink_reset()
["doc:set-cursor"] = function(x, y)
set_cursor(x, y, "set")
end,
["doc:set-cursor-word"] = function(x, y, clicks)
local line, col = dv():resolve_screen_position(x, y)
doc():set_selection(line, col, line, col)
command.perform("doc:select-word")
dv().mouse_selecting = { line, col }
end,
["doc:set-cursor-word"] = function(x, y)
set_cursor(x, y, "word")
end,
["doc:set-cursor-line"] = function(x, y, clicks)
local line, col = dv():resolve_screen_position(x, y)
doc():set_selection(line, col, line, col)
command.perform("doc:select-lines")
dv().mouse_selecting = { line, col }
set_cursor(x, y, "lines")
end,
["doc:split-cursor"] = function(x, y, clicks)