BJ5X5O4ACBBJ56LRBBSTCW6IBQP4HAEOOOPNH3SKTA4F66YTOIDAC
PWHZPJJM7UZW2VILT5TZBDZHIXXXBASVSBQB3A5EEMOFJTI6ADYAC
2INHXC3KRJVZTX2BQ63ZQLHIC5SWPUG4PQKCMLC7SQKN5R7LJZ6QC
62ST7SV3GF5CLNWDRGYGN5BOIUHSMSPH26VIWO3Q2A6P2U7B2TRQC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
QCQHLMSTHTRNIKC5CJU3CAYMMWPTGITALRJNLFMGQWN2ZYMDSAWAC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
5T2E3PDVSLMZSSIIQRNKIKQVV77XQTHP473OP7XBTTMSZHIQID5AC
VVXVV2D2F5Y6D6N5VVPUPK3N6GMDTG2YCYPQDYTYEKVKBYHRRYEAC
XX7G2FFJ4QCGQGD4REAW5QFHVYAKCFUPGZCK7L6DFGS5ISVBYBQQC
6PUNJS5BSLTYMYMN4JFD7YDEGVQLM5PGAT7PQIG5NIAKLTM5T4PQC
GVOFXXITWK6UHAPI3VMGSDGV3RUHQSXZ3OVAM7ZPKYOGAX5FZQUAC
IYW7X3WLOPYLSNO5IQNSULUNO4XFEM24DJ2VB5HPBUKWUYFPRCGQC
3CS5KKCIZQ6J4SBILINYZSOM6V3U2LE7YIXOZVKXXNBROF6Z6JWAC
3D5RFWHVIHCJGN7HLEP5ZMC6WNIG7GXISJRJXOA4K5MBJFJYPIIQC
file load:
cursor_line = 1
first line is a drawing -> cursor_line = 2
create drawing -> cursor bumps down below drawing
backspace
cursor_pos == 0, previous line is a drawing -> delete drawing, cursor still visible at start of line
cursor_pos == 0, previous line is text -> join lines, cursor still at same character
if cursor_line > 1 and lines[cursor_line].data == '' then
table.remove(lines, cursor_line)
cursor_line = cursor_line-1
if lines[cursor_line].mode == 'text' then
cursor_pos = #lines[cursor_line].data+1
if cursor_pos > 1 then
local byte_start = utf8.offset(lines[cursor_line].data, cursor_pos-1)
local byte_end = utf8.offset(lines[cursor_line].data, cursor_pos)
if byte_start then
if byte_end then
lines[cursor_line].data = string.sub(lines[cursor_line].data, 1, byte_start-1)..string.sub(lines[cursor_line].data, byte_end)
else
lines[cursor_line].data = string.sub(lines[cursor_line].data, 1, byte_start-1)
end
cursor_pos = cursor_pos-1
end
elseif cursor_line > 1 then
if lines[cursor_line-1].mode == 'drawing' then
table.remove(lines, cursor_line-1)
if lines[cursor_line].mode == 'text' then
cursor_pos = #lines[cursor_line].data+1
else
cursor_pos = 1
end
else
if cursor_pos > 1 then
local byte_start = utf8.offset(lines[cursor_line].data, cursor_pos-1)
local byte_end = utf8.offset(lines[cursor_line].data, cursor_pos)
if byte_start then
if byte_end then
lines[cursor_line].data = string.sub(lines[cursor_line].data, 1, byte_start-1)..string.sub(lines[cursor_line].data, byte_end)
else
lines[cursor_line].data = string.sub(lines[cursor_line].data, 1, byte_start-1)
end
cursor_pos = cursor_pos-1
end
end
if cursor_line > 1 then
if lines[cursor_line].mode == 'text' and lines[cursor_line-1].mode == 'text' then
local old_x = cursor_x(lines[cursor_line].data, cursor_pos)
cursor_line = cursor_line-1
assert(lines[cursor_line].mode == 'text')
local new_cursor_line = cursor_line
while new_cursor_line > 1 do
new_cursor_line = new_cursor_line-1
if lines[new_cursor_line].mode == 'text' then
local old_x = cursor_x(lines[new_cursor_line].data, cursor_pos)
cursor_line = new_cursor_line
if cursor_line < #lines then
if lines[cursor_line].mode == 'text' and lines[cursor_line+1].mode == 'text' then
local old_x = cursor_x(lines[cursor_line].data, cursor_pos)
cursor_line = cursor_line+1
assert(lines[cursor_line].mode == 'text')
local new_cursor_line = cursor_line
while new_cursor_line < #lines do
new_cursor_line = new_cursor_line+1
if lines[new_cursor_line].mode == 'text' then
local old_x = cursor_x(lines[new_cursor_line].data, cursor_pos)
cursor_line = new_cursor_line