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() core.blink_reset()
end 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 = { local commands = {
["doc:undo"] = function() ["doc:undo"] = function()
doc():undo() doc():undo()
@ -396,25 +406,16 @@ local commands = {
doc():set_selection(line2, col2, line1, col1) doc():set_selection(line2, col2, line1, col1)
end, end,
["doc:set-cursor"] = function(x, y, clicks) ["doc:set-cursor"] = function(x, y)
local line, col = dv():resolve_screen_position(x, y) set_cursor(x, y, "set")
doc():set_selection(line, col, line, col)
dv().mouse_selecting = { line, col }
core.blink_reset()
end, end,
["doc:set-cursor-word"] = function(x, y, clicks) ["doc:set-cursor-word"] = function(x, y)
local line, col = dv():resolve_screen_position(x, y) set_cursor(x, y, "word")
doc():set_selection(line, col, line, col)
command.perform("doc:select-word")
dv().mouse_selecting = { line, col }
end, end,
["doc:set-cursor-line"] = function(x, y, clicks) ["doc:set-cursor-line"] = function(x, y, clicks)
local line, col = dv():resolve_screen_position(x, y) set_cursor(x, y, "lines")
doc():set_selection(line, col, line, col)
command.perform("doc:select-lines")
dv().mouse_selecting = { line, col }
end, end,
["doc:split-cursor"] = function(x, y, clicks) ["doc:split-cursor"] = function(x, y, clicks)