NEKDLX527DBB62P6OYFMSYAMTLRHNBRDNXNEVFT6UR4JLNOJXWKQC
on.keychord_press = function(chord, key)
if chord == 'C-=' then
-- zoom in
Viewport.zoom = Viewport.zoom+0.1
B()
elseif chord == 'C--' then
-- zoom out
Viewport.zoom = Viewport.zoom-0.1
B()
elseif chord == 'C-0' then
-- reset zoom
Viewport.zoom = 1.0
B()
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
end
{"Surface":588,"vy":8,"on.draw":632,"Nodes":593,"add_node":590,"Viewport":303,"on.mouse_release":586,"on.initialize":446,"Input_filename":436,"on":1,"dehtml":456,"line_height":365,"ensure_cursor_node_within_viewport":643,"load_from_iterator":463,"add_edge":575,"compute_ntracks":598,"compute_layout":619,"render_thread_to_surface":626,"copy_shape":396,"on.keychord_press":644,"render_node_and_descendants":633,"Cursor_node":172,"add_thick_line":400,"ntracks":600,"update_editor_box":430,"scale":7,"y_of_schema1":364,"on.text_input":587,"on.update":368,"fw_parent":643,"initialize_editor":338,"schema1_of_y":366,"to_text":180,"box_height":345,"A":582,"font":353,"to_node":611,"fw_app":"mastodon-unfurl","on.code_change":578,"split_lines":469,"B":379,"on.mouse_press":618,"vx":5}
{"Surface":588,"vy":8,"on.draw":632,"Nodes":593,"add_node":590,"Viewport":303,"on.mouse_release":586,"on.initialize":446,"Input_filename":436,"on":1,"dehtml":456,"line_height":365,"ensure_cursor_node_within_viewport":643,"load_from_iterator":463,"add_edge":575,"compute_ntracks":598,"compute_layout":619,"render_thread_to_surface":626,"copy_shape":396,"on.keychord_press":642,"render_node_and_descendants":633,"Cursor_node":172,"add_thick_line":400,"ntracks":600,"update_editor_box":430,"scale":7,"y_of_schema1":364,"on.text_input":587,"on.update":368,"fw_parent":642,"initialize_editor":338,"schema1_of_y":366,"to_text":180,"box_height":345,"A":582,"font":353,"to_node":611,"fw_app":"mastodon-unfurl","on.code_change":578,"split_lines":469,"B":379,"on.mouse_press":618,"vx":5}
ensure_cursor_node_within_viewport = function()
local snode = Cursor_node.surface_node
local dirty
-- check Viewport.y
if snode.y < Viewport.y then
Viewport.y = snode.y - 50
dirty = true
end
local limit = snode.y + box_height(snode)
if Viewport.y < limit - App.screen.height/Viewport.zoom then
Viewport.y = limit - (App.screen.height-50)/Viewport.zoom
dirty = true
end
-- check Viewport.x
if Cursor_node.surface_node.x < Viewport.x then
Viewport.x = Cursor_node.surface_node.x - 50
dirty = true
end
limit = snode.x + 600
if Viewport.x < limit - App.screen.width/Viewport.zoom then
Viewport.x = limit - (App.screen.width-50)/Viewport.zoom
dirty = true
end
-- refresh if necessary
if dirty then
B()
end
end