Added in clicks to keymap.
This commit is contained in:
parent
09bf8bab2f
commit
612818ca05
|
@ -42,10 +42,10 @@ function command.get_all_valid()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function perform(name)
|
local function perform(name, ...)
|
||||||
local cmd = command.map[name]
|
local cmd = command.map[name]
|
||||||
if cmd and cmd.predicate() then
|
if cmd and cmd.predicate(...) then
|
||||||
cmd.perform()
|
cmd.perform(...)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -388,6 +388,28 @@ 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)
|
||||||
|
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()
|
["doc:create-cursor-previous-line"] = function()
|
||||||
split_cursor(-1)
|
split_cursor(-1)
|
||||||
|
|
|
@ -225,7 +225,7 @@ function DocView:scroll_to_make_visible(line, col)
|
||||||
end
|
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
|
local swap = line2 < line1 or line2 == line1 and col2 <= col1
|
||||||
if swap then
|
if swap then
|
||||||
line1, col1, line2, col2 = line2, col2, line1, col1
|
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
|
return line1, col1, line2, col2
|
||||||
end
|
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, ...)
|
function DocView:on_mouse_moved(x, y, ...)
|
||||||
DocView.super.on_mouse_moved(self, 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]))
|
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(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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,7 +63,7 @@ function keymap.get_binding(cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function keymap.on_key_pressed(k)
|
function keymap.on_key_pressed(k, ...)
|
||||||
local mk = modkey_map[k]
|
local mk = modkey_map[k]
|
||||||
if mk then
|
if mk then
|
||||||
keymap.modkeys[mk] = true
|
keymap.modkeys[mk] = true
|
||||||
|
@ -73,13 +73,13 @@ function keymap.on_key_pressed(k)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local stroke = key_to_stroke(k)
|
local stroke = key_to_stroke(k)
|
||||||
local commands = keymap.map[stroke]
|
local commands, performed = keymap.map[stroke]
|
||||||
if commands then
|
if commands then
|
||||||
for _, cmd in ipairs(commands) do
|
for _, cmd in ipairs(commands) do
|
||||||
local performed = command.perform(cmd)
|
performed = command.perform(cmd, ...)
|
||||||
if performed then break end
|
if performed then break end
|
||||||
end
|
end
|
||||||
return true
|
return performed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
@ -193,6 +193,9 @@ keymap.add_direct {
|
||||||
["pageup"] = "doc:move-to-previous-page",
|
["pageup"] = "doc:move-to-previous-page",
|
||||||
["pagedown"] = "doc:move-to-next-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+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",
|
||||||
|
|
|
@ -3,7 +3,7 @@ local config = require "core.config"
|
||||||
local style = require "core.style"
|
local style = require "core.style"
|
||||||
local common = require "core.common"
|
local common = require "core.common"
|
||||||
local Object = require "core.object"
|
local Object = require "core.object"
|
||||||
|
local keymap = require "core.keymap"
|
||||||
|
|
||||||
local View = Object:extend()
|
local View = Object:extend()
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ function View:on_mouse_pressed(button, x, y, clicks)
|
||||||
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue