snap.love/0023-on.keychord_press
Kartik K. Agaram 2f34ef4eb8 snapshot: a new debug tool
I might have finally hit on the right approach: a hotkey that dumps
information. Doesn't swamp me with data, and also doesn't perturb
anything.

y_of_schema1 returns consistent results as I pan around.
I'm just not actually printing the lines at that y. I'm printing it at
that y/Viewport.zoom.

What might be confusing here is that I started out with a simple mental
model:
  * perform computations in surface coordinates (sx,sy)
  * render in viewport coordinates (vx,vy)

But for text quality reasons I need to perform many computations in
"scaled surface" coordinates.

Viewport coordinates are both offset and scaled relative to surface
coordinates. Scaled surface = just scaled relative to surface, not
offset.

I don't have a clear mental model here for when to use this.

I did already use it in one place with my simple mental model: you have
to scale distances like rect.w and rect.h but it's incorrect to offset
them. Maybe I'm getting this wrong somehow.
2023-10-25 11:02:03 -07:00

59 lines
1.7 KiB
Plaintext

on.keychord_press = function(chord, key)
print('key press', chord)
if 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 chord == 'C-z' then
dump_state()
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)
if not eq(Cursor_node.editor.screen_top1, old_top) then
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
end
A()
else
if chord == 'up' then
Viewport.y = Viewport.y - scale(20)
B()
elseif chord == 'down' then
Viewport.y = Viewport.y + scale(20)
B()
elseif chord == 'left' then
Viewport.x = Viewport.x - scale(50)
B()
elseif chord == 'right' then
Viewport.x = Viewport.x + scale(50)
B()
elseif chord == 'pageup' then
Viewport.y = Viewport.y - App.screen.height/Viewport.zoom
B()
elseif chord == 'S-up' then
Viewport.y = Viewport.y - App.screen.height/Viewport.zoom
B()
elseif chord == 'pagedown' then
Viewport.y = Viewport.y + App.screen.height/Viewport.zoom
B()
elseif chord == 'S-down' then
Viewport.y = Viewport.y + App.screen.height/Viewport.zoom
B()
elseif chord == 'S-left' then
Viewport.x = Viewport.x - App.screen.width/Viewport.zoom
B()
elseif chord == 'S-right' then
Viewport.x = Viewport.x + App.screen.width/Viewport.zoom
B()
end
end
end