The culprit is an ambiguously named helper. put_cursor_on_next_text_line is not supposed to move to next line if the current line is text.
ZLWFFQHIJHV4TE3JA27NK3CBNOMQU3UMMN6HVNQN7L2NMJMI43SAC
if State.lines[line].mode == 'text' then
State.cursor1.line = line
State.cursor1.pos = 1
break
end
end
if line <= #State.lines and State.lines[line].mode == 'text' then
State.cursor1.line = line
State.cursor1.pos = 1
if State.lines[line].mode == 'text' then
State.cursor1.line = line
State.cursor1.pos = 1
break
end
end
if line <= #State.lines and State.lines[line].mode == 'text' then
State.cursor1.line = line
State.cursor1.pos = 1