2023-02-19 07:30:19 +00:00
|
|
|
on.keychord_press = function(chord, key)
|
2023-10-22 19:41:34 +01:00
|
|
|
print('key press', chord)
|
2023-02-19 07:30:19 +00:00
|
|
|
if chord == 'C-=' then
|
|
|
|
-- zoom in
|
|
|
|
Viewport.zoom = Viewport.zoom+0.1
|
2023-10-25 08:18:06 +01:00
|
|
|
A()
|
2023-02-19 07:30:19 +00:00
|
|
|
elseif chord == 'C--' then
|
|
|
|
-- zoom out
|
2023-10-22 19:43:58 +01:00
|
|
|
if (Viewport.zoom-0.1)*20 >= 1 then -- disallow font size of 0
|
|
|
|
Viewport.zoom = Viewport.zoom-0.1
|
2023-10-25 08:18:06 +01:00
|
|
|
A()
|
2023-10-22 19:43:58 +01:00
|
|
|
end
|
2023-02-19 07:30:19 +00:00
|
|
|
elseif chord == 'C-0' then
|
|
|
|
-- reset zoom
|
|
|
|
Viewport.zoom = 1.0
|
2023-10-25 08:18:06 +01:00
|
|
|
A()
|
2023-10-15 20:52:12 +01:00
|
|
|
elseif chord == 'C-v' then
|
|
|
|
-- load new URL
|
|
|
|
if Major_version >= 12 then -- requires LÖVE with https
|
|
|
|
-- ignore stuff in the clipboard that doesn't look like a url
|
|
|
|
local cb = App.get_clipboard()
|
|
|
|
if #cb > 300 then
|
|
|
|
print('clipboard: '..cb:sub(1,300)..'...')
|
|
|
|
else
|
|
|
|
print('clipboard: '..cb)
|
|
|
|
end
|
|
|
|
if cb:match('^%s*https://[^%s]*%s*$') then
|
|
|
|
print('clipboard contains a URL')
|
|
|
|
Url = trim(cb)
|
2023-10-16 04:18:19 +01:00
|
|
|
load_nodes_from_url()
|
|
|
|
set_cursor(ml_from_url(Url).id)
|
2023-10-15 20:52:12 +01:00
|
|
|
A()
|
2023-10-16 04:18:19 +01:00
|
|
|
ensure_cursor_node_within_viewport()
|
2023-10-15 20:52:12 +01:00
|
|
|
end
|
|
|
|
end
|
2023-02-19 07:30:19 +00:00
|
|
|
elseif chord == 'C-up' then
|
|
|
|
if Cursor_node.in_reply_to_id then
|
|
|
|
Cursor_node = Nodes[Cursor_node.in_reply_to_id]
|
|
|
|
ensure_cursor_node_within_viewport()
|
|
|
|
end
|
|
|
|
elseif chord == 'C-down' then
|
|
|
|
if Cursor_node.children and #Cursor_node.children > 0 then
|
|
|
|
Cursor_node = Nodes[Cursor_node.children[1]]
|
|
|
|
ensure_cursor_node_within_viewport()
|
|
|
|
end
|
|
|
|
elseif chord == 'C-left' then
|
|
|
|
if Cursor_node.in_reply_to_id then
|
|
|
|
local parent = Nodes[Cursor_node.in_reply_to_id]
|
|
|
|
assert(parent.children)
|
|
|
|
if #parent.children > 1 then
|
|
|
|
local idx = array.find(parent.children, Cursor_node.id)
|
|
|
|
if idx > 1 then
|
|
|
|
Cursor_node = Nodes[parent.children[idx-1]]
|
|
|
|
ensure_cursor_node_within_viewport()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif chord == 'C-right' then
|
|
|
|
if Cursor_node.in_reply_to_id then
|
|
|
|
local parent = Nodes[Cursor_node.in_reply_to_id]
|
|
|
|
assert(parent.children)
|
|
|
|
if #parent.children > 1 then
|
|
|
|
local idx = array.find(parent.children, Cursor_node.id)
|
|
|
|
if idx < #parent.children then
|
|
|
|
Cursor_node = Nodes[parent.children[idx+1]]
|
|
|
|
ensure_cursor_node_within_viewport()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-10-15 20:52:12 +01:00
|
|
|
end
|