Added in clicks to keymap.
This commit is contained in:
parent
09bf8bab2f
commit
612818ca05
|
@ -42,10 +42,10 @@ function command.get_all_valid()
|
|||
end
|
||||
|
||||
|
||||
local function perform(name)
|
||||
local function perform(name, ...)
|
||||
local cmd = command.map[name]
|
||||
if cmd and cmd.predicate() then
|
||||
cmd.perform()
|
||||
if cmd and cmd.predicate(...) then
|
||||
cmd.perform(...)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
|
|
@ -388,6 +388,28 @@ local commands = {
|
|||
os.remove(filename)
|
||||
core.log("Removed \"%s\"", filename)
|
||||
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)
|
||||
local line, col = dv():resolve_screen_position(x, y)
|
||||
doc():set_selection(dv():mouse_selection(doc(), clicks, line, col, line, col))
|
||||
dv().mouse_selecting = { line, col, clicks = clicks }
|
||||
core.blink_reset()
|
||||
end,
|
||||
|
||||
["doc:split-cursor"] = function(x, y, clicks)
|
||||
local line, col = dv():resolve_screen_position(x, y)
|
||||
doc():add_selection(dv():mouse_selection(doc(), clicks, line, col, line, col))
|
||||
dv().mouse_selecting = { line, col, clicks = clicks }
|
||||
core.blink_reset()
|
||||
end,
|
||||
|
||||
["doc:create-cursor-previous-line"] = function()
|
||||
split_cursor(-1)
|
||||
|
|
|
@ -225,7 +225,7 @@ function DocView:scroll_to_make_visible(line, col)
|
|||
end
|
||||
|
||||
|
||||
local function mouse_selection(doc, clicks, line1, col1, line2, col2)
|
||||
function DocView:mouse_selection(doc, clicks, line1, col1, line2, col2)
|
||||
local swap = line2 < line1 or line2 == line1 and col2 <= col1
|
||||
if swap then
|
||||
line1, col1, line2, col2 = line2, col2, line1, col1
|
||||
|
@ -245,31 +245,6 @@ local function mouse_selection(doc, clicks, line1, col1, line2, col2)
|
|||
return line1, col1, line2, col2
|
||||
end
|
||||
|
||||
|
||||
function DocView:on_mouse_pressed(button, x, y, clicks)
|
||||
local caught = DocView.super.on_mouse_pressed(self, button, x, y, clicks)
|
||||
if caught then
|
||||
return
|
||||
end
|
||||
if keymap.modkeys["shift"] then
|
||||
if clicks % 2 == 1 then
|
||||
local line1, col1 = select(3, self.doc:get_selection())
|
||||
local line2, col2 = self:resolve_screen_position(x, y)
|
||||
self.doc:set_selection(line2, col2, line1, col1)
|
||||
end
|
||||
else
|
||||
local line, col = self:resolve_screen_position(x, y)
|
||||
if keymap.modkeys["ctrl"] then
|
||||
self.doc:add_selection(mouse_selection(self.doc, clicks, line, col, line, col))
|
||||
else
|
||||
self.doc:set_selection(mouse_selection(self.doc, clicks, line, col, line, col))
|
||||
end
|
||||
self.mouse_selecting = { line, col, clicks = clicks }
|
||||
end
|
||||
core.blink_reset()
|
||||
end
|
||||
|
||||
|
||||
function DocView:on_mouse_moved(x, y, ...)
|
||||
DocView.super.on_mouse_moved(self, x, y, ...)
|
||||
|
||||
|
@ -290,7 +265,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]))
|
||||
end
|
||||
else
|
||||
self.doc:set_selection(mouse_selection(self.doc, clicks, l1, c1, l2, c2))
|
||||
self.doc:set_selection(self:mouse_selection(self.doc, clicks, l1, c1, l2, c2))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -63,7 +63,7 @@ function keymap.get_binding(cmd)
|
|||
end
|
||||
|
||||
|
||||
function keymap.on_key_pressed(k)
|
||||
function keymap.on_key_pressed(k, ...)
|
||||
local mk = modkey_map[k]
|
||||
if mk then
|
||||
keymap.modkeys[mk] = true
|
||||
|
@ -73,13 +73,13 @@ function keymap.on_key_pressed(k)
|
|||
end
|
||||
else
|
||||
local stroke = key_to_stroke(k)
|
||||
local commands = keymap.map[stroke]
|
||||
local commands, performed = keymap.map[stroke]
|
||||
if commands then
|
||||
for _, cmd in ipairs(commands) do
|
||||
local performed = command.perform(cmd)
|
||||
performed = command.perform(cmd, ...)
|
||||
if performed then break end
|
||||
end
|
||||
return true
|
||||
return performed
|
||||
end
|
||||
end
|
||||
return false
|
||||
|
@ -193,6 +193,9 @@ keymap.add_direct {
|
|||
["pageup"] = "doc:move-to-previous-page",
|
||||
["pagedown"] = "doc:move-to-next-page",
|
||||
|
||||
["shift+lclick"] = "doc:select-to-cursor",
|
||||
["ctrl+lclick"] = "doc:split-cursor",
|
||||
["lclick"] = "doc:set-cursor",
|
||||
["shift+left"] = "doc:select-to-previous-char",
|
||||
["shift+right"] = "doc:select-to-next-char",
|
||||
["shift+up"] = "doc:select-to-previous-line",
|
||||
|
|
|
@ -3,7 +3,7 @@ local config = require "core.config"
|
|||
local style = require "core.style"
|
||||
local common = require "core.common"
|
||||
local Object = require "core.object"
|
||||
|
||||
local keymap = require "core.keymap"
|
||||
|
||||
local View = Object:extend()
|
||||
|
||||
|
@ -81,6 +81,7 @@ function View:on_mouse_pressed(button, x, y, clicks)
|
|||
self.dragging_scrollbar = true
|
||||
return true
|
||||
end
|
||||
return keymap.on_key_pressed(button:sub(1,1) .. "click", x, y, clicks)
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue