mastodon-unfurl.love/0039-ensure_cursor_node_wit...

29 lines
740 B
Plaintext

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