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AC
AYE2VEGJ63AWWX76SFQZLOTBIZOQRWBG4AZMIOSVOI2WZVRQJXYAC
LXTTOB33N2HCUZFIUDRQGGBVHK2HODRG4NBLH6RXRQZDCHF27BSAC
Z4XRNDTRTGSZHNB65WNHOVUBFW4QWQABLVSK4RM3QJHGK33DMRJAC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
BYG5CEMVXANDTBI2ORNVMEY6K3EBRIHZHS4QBK27VONJC5537COQC
local byte_offset
if Cursor1.pos > 1 then
byte_offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos)
else
byte_offset = 1
end
if byte_offset == nil then
print(Cursor1.line, Cursor1.pos, byte_offset, Lines[Cursor1.line].data)
assert(false)
end
local byte_offset = Text.offset(Lines[Cursor1.line].data, Cursor1.pos)
local byte_offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos)
--? print(Cursor1.line, Cursor1.pos, #Lines[Cursor1.line].data)
--? print(Lines[Cursor1.line].data)
assert(byte_offset)
local byte_offset = Text.offset(Lines[Cursor1.line].data, Cursor1.pos)
local new_screen_line_starting_byte_offset = utf8.offset(Lines[Cursor1.line].data, new_screen_line_starting_pos)
assert(new_screen_line_starting_byte_offset)
local new_screen_line_starting_byte_offset = Text.offset(Lines[Cursor1.line].data, new_screen_line_starting_pos)
local new_screen_line_starting_byte_offset = utf8.offset(Lines[Cursor1.line].data, new_screen_line_starting_pos)
assert(new_screen_line_starting_byte_offset)
local new_screen_line_starting_byte_offset = Text.offset(Lines[Cursor1.line].data, new_screen_line_starting_pos)
local lo_offset = utf8.offset(line.data, lo)
local hi_offset = utf8.offset(line.data, hi)
local pos_offset = utf8.offset(line.data, pos)
local lo_offset = Text.offset(line.data, lo)
local hi_offset = Text.offset(line.data, hi)
local pos_offset = Text.offset(line.data, pos)