pothi.love/0023-on.keychord_press

77 lines
2.3 KiB
Plaintext

on.keychord_press = function(chord, key)
print('key press', chord)
if Global_state.thread and chord == 'C-o' then
quit_all_editors(Global_state.thread)
Global_state.thread = nil
reset_viewport()
A()
elseif chord == 'C-=' then
-- zoom in
Viewport.zoom = Viewport.zoom+0.1
A()
elseif chord == 'C--' then
-- zoom out
if (Viewport.zoom-0.1)*20 >= 1 then -- disallow font size of 0
Viewport.zoom = Viewport.zoom-0.1
A()
end
elseif chord == 'C-0' then
-- reset zoom
Viewport.zoom = 1.0
A()
elseif Cursor_node and Cursor_node.editor.cursor_x then
local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}
edit.keychord_press(Cursor_node.editor, chord, key)
pan_viewport_to_contain_cursor(Cursor_node)
if chord == 'return' then
A()
else
B()
end
else
if chord == 'up' then
Viewport.y = math.max(
Viewport_bounds.ymin,
Viewport.y - scale(20))
B()
elseif chord == 'down' then
Viewport.y = math.min(
math.max(
Viewport_bounds.ymin,
Viewport_bounds.ymax - App.screen.width/2/Viewport.zoom), -- conservative; unclear why removing the '/2' makes the bottom inaccessible
Viewport.y + scale(20))
B()
elseif chord == 'left' then
Viewport.x = math.max(
Viewport_bounds.xmin,
Viewport.x - scale(50))
B()
elseif chord == 'right' then
Viewport.x = math.min(
math.max(Viewport_bounds.xmin, Viewport_bounds.xmax - App.screen.width/Viewport.zoom),
Viewport.x + scale(50))
B()
elseif chord == 'pageup' or chord == 'S-up' then
Viewport.y = math.max(Viewport_bounds.ymin, Viewport.y - App.screen.height/Viewport.zoom)
B()
elseif chord == 'pagedown' or chord == 'S-down' then
Viewport.y = math.min(
math.max(
Viewport_bounds.ymin,
Viewport_bounds.ymax - App.screen.width/2/Viewport.zoom), -- conservative; unclear why removing the '/2' makes the bottom inaccessible
Viewport.y + App.screen.height/Viewport.zoom)
B()
elseif chord == 'S-left' then
Viewport.x = math.max(Viewport_bounds.xmin, Viewport.x - App.screen.width/Viewport.zoom)
B()
elseif chord == 'S-right' then
Viewport.x = math.min(
math.max(
Viewport_bounds.xmin,
Viewport_bounds.xmax - App.screen.width/Viewport.zoom),
Viewport.x + App.screen.width/Viewport.zoom)
B()
end
end
end