There can be many frames between a keypress and key release event.
I ran into this a couple of months ago.
keypress and textinput still happen on the same frame. Hmm. I should just track when an event actually does any work, and only plan_draw then. That way if keypress and textinput have disjoint cases of activation there'll be no duplication.
VPCPK52KMU4MZUXP4SUSJJDEHDR4C3KJ45HLMUQUK32FMY6OCQ4QC
B3DXRFR34ASOJPIYXNKV27XXLRW2METE7TDN3IWLPE7AOSWVSXAAC
JMUE7GSN6QDQZ6NDRB55MRJMKJN6LBD6MVQPKROYPDOIXM7I3XNQC
KKMFQDR43ZWVCDRHQLWWX3FCWCFA3ZSXYOBRJNPHUQZR2XPKWULAC
GO534NHJW3FC4FNJXTA5QZYZJ5A7UHVTGPNB7G73GA2YJRX4D54AC
3IBO5P7DVWMJM42VZL5HIFAJH55FK77K2IKPGMNI55GRXDXT4WUQC
IUS4EW7KL6ZJR2LN5VG7SW6DI7TTPVYYRFOLPHEON36HHVS4YWZQC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
JCSLDGAH2F6AIY4Z6XM6K4LOMW7EFY3E4NF5YXLMHLTYTX3A4Z3QC
end
if body_sy < Display_settings.y then
pane.screen_top1, y_offset = schema1_of_y(pane, Display_settings.y - body_sy)
else
pane.screen_top1 = {line=1, pos=1}
end
if body_sy < Display_settings.y then
pane.top = Margin_above
else
pane.top = body_sy - Display_settings.y + Margin_above
if should_update_screen_top(column_index, pane_index, pane, options) then
pane.top = Header_height + pane.top - y_offset
--? print('bounds: =>', pane.top)
pane.left = sx - Display_settings.x
pane.right = pane.left + Display_settings.column_width
pane.width = pane.right - pane.left
else
-- clear bounds to catch issues early
pane.top = nil
--? print('bounds: =>', pane.top)
end
sy = sy + Margin_above + height(pane) + Margin_below + Padding_vertical
end
else
-- clear bounds to catch issues early
for _, pane in ipairs(column) do
pane.top = nil
end
end
sx = sx + Margin_right + Display_settings.column_width + Padding_horizontal + Margin_left
end
end
-- keep the structure of this function sync'd with refresh_pane_height
function plan_draw_maybe_updating_screen_top_in_cursor_pane(update_screen_top_in_cursor_pane)
--? print('update pane bounds')
--? print(#Surface, 'columns;', num_panes(), 'panes')
Panes_to_draw = {}
local sx = Padding_horizontal + Margin_left
for column_index, column in ipairs(Surface) do
if should_show_column(sx) then
local sy = Padding_vertical
for pane_index, pane in ipairs(column) do
if sy > Display_settings.y + App.screen.height - Header_height then
break
end
--? print('bounds:', column_index, pane_index, sx,sy)
if should_show_pane(pane, sy) then
table.insert(Panes_to_draw, pane)
-- stash some short-lived variables
pane.column_index = column_index
pane.pane_index = pane_index
local y_offset = 0
local body_sy = sy
if column[pane_index].title then
body_sy = body_sy + 5+Line_height+5
end
if should_update_screen_top(column_index, pane_index, update_screen_top_in_cursor_pane) then
-- update the cursor pane either if it's not editable, or
-- if it was explicitly requested
if not pane.editable then return true end
if options == nil then return true end
if not options.ignore_editable_cursor_pane then return true end
if not Editable_cursor_pane_updated_screen_top then return true end
return false
return including_cursor_pane
keychord_pressed_on_editable_pane(pane, chord, key)
if chord == 'C-e' then
command.exit_editing()
elseif pane.cursor_x == nil then
-- ignore if cursor is not visible on screen
assert(pane.cursor_y == nil)
panning_keychord_pressed(chord, key)
plan_draw()
else
local old_top = {line=pane.screen_top1.line, pos=pane.screen_top1.pos}
edit.keychord_pressed(pane, chord, key)
local cursor_pane_updated_screen_top = maybe_update_screen_top_of_cursor_pane(pane, old_top)
pane._height = nil
plan_draw_maybe_updating_screen_top_in_cursor_pane(not cursor_pane_updated_screen_top)
end
function keychord_pressed_on_editable_pane(pane, chord, key)
if chord == 'C-e' then
command.exit_editing()
elseif pane.cursor_x == nil then
-- ignore if cursor is not visible on screen
assert(pane.cursor_y == nil)
panning_keychord_pressed(chord, key)
else
--? print(('%s pressed in editor pane'):format(chord))
--? print(pane.cursor_x, pane.cursor_y)
local old_top = {line=pane.screen_top1.line, pos=pane.screen_top1.pos}
edit.keychord_pressed(pane, chord, key)
maybe_update_screen_top_of_cursor_pane(pane, old_top)
pane._height = nil
end
end