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AXV2HG4NMAHAWGWD35V5PXULNORCBEKY65UQT37XNYXCSB7TWEAC
--? print(Editor_state.screen_top1.line, Editor_state.screen_top1.pos, Editor_state.cursor1.line, Editor_state.cursor1.pos)
assert(Text.le1(Editor_state.screen_top1, Editor_state.cursor1))
Editor_state.cursor_y = -1
local y = Editor_state.margin_top
--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
assert(Text.le1(State.screen_top1, State.cursor1))
State.cursor_y = -1
local y = State.margin_top
table.insert(Editor_state.lines, line_index, {mode='drawing', y=y, h=256/2, points={}, shapes={}, pending={}})
if Editor_state.cursor1.line >= line_index then
Editor_state.cursor1.line = Editor_state.cursor1.line+1
table.insert(State.lines, line_index, {mode='drawing', y=y, h=256/2, points={}, shapes={}, pending={}})
if State.cursor1.line >= line_index then
State.cursor1.line = State.cursor1.line+1
y, Editor_state.screen_bottom1.pos = Text.draw(line, line_index, line.starty, Editor_state.margin_left, App.screen.width-Editor_state.margin_right)
y = y + Editor_state.line_height
y, State.screen_bottom1.pos = Text.draw(line, line_index, line.starty, State.margin_left, App.screen.width-State.margin_right)
y = y + State.line_height
--? print('screen bottom: '..tostring(Editor_state.screen_bottom1.pos)..' in '..tostring(Editor_state.lines[Editor_state.screen_bottom1.line].data))
if Editor_state.search_term then
--? print('screen bottom: '..tostring(State.screen_bottom1.pos)..' in '..tostring(State.lines[State.screen_bottom1.line].data))
if State.search_term then
if Editor_state.next_save and Editor_state.next_save < App.getTime() then
save_to_disk(Editor_state.lines, Editor_state.filename)
Editor_state.next_save = nil
if State.next_save and State.next_save < App.getTime() then
save_to_disk(State.lines, State.filename)
State.next_save = nil
function edit.mouse_pressed(x,y, mouse_button)
if Editor_state.search_term then return end
--? print('press', Editor_state.selection1.line, Editor_state.selection1.pos)
function edit.mouse_pressed(State, x,y, mouse_button)
if State.search_term then return end
--? print('press', State.selection1.line, State.selection1.pos)
Editor_state.old_cursor1 = Editor_state.cursor1
Editor_state.old_selection1 = Editor_state.selection1
Editor_state.mousepress_shift = App.shift_down()
Editor_state.selection1 = {
State.old_cursor1 = State.cursor1
State.old_selection1 = State.selection1
State.mousepress_shift = App.shift_down()
State.selection1 = {
--? print('cursor', Editor_state.cursor1.line, Editor_state.cursor1.pos)
if Editor_state.mousepress_shift then
if Editor_state.old_selection1.line == nil then
Editor_state.selection1 = Editor_state.old_cursor1
--? print('cursor', State.cursor1.line, State.cursor1.pos)
if State.mousepress_shift then
if State.old_selection1.line == nil then
State.selection1 = State.old_cursor1
Editor_state.old_cursor1, Editor_state.old_selection1, Editor_state.mousepress_shift = nil
if eq(Editor_state.cursor1, Editor_state.selection1) then
Editor_state.selection1 = {}
State.old_cursor1, State.old_selection1, State.mousepress_shift = nil
if eq(State.cursor1, State.selection1) then
State.selection1 = {}
function edit.textinput(t)
for _,line in ipairs(Editor_state.lines) do line.y = nil end -- just in case we scroll
if Editor_state.search_term then
Editor_state.search_term = Editor_state.search_term..t
Editor_state.search_text = nil
function edit.textinput(State, t)
for _,line in ipairs(State.lines) do line.y = nil end -- just in case we scroll
if State.search_term then
State.search_term = State.search_term..t
State.search_text = nil
elseif Editor_state.current_drawing_mode == 'name' then
local before = snapshot(Editor_state.lines.current_drawing_index)
local drawing = Editor_state.lines.current_drawing
elseif State.current_drawing_mode == 'name' then
local before = snapshot(State.lines.current_drawing_index)
local drawing = State.lines.current_drawing
function edit.keychord_pressed(chord, key)
if Editor_state.selection1.line and
not Editor_state.lines.current_drawing and
function edit.keychord_pressed(State, chord, key)
if State.selection1.line and
not State.lines.current_drawing and
Editor_state.search_term = nil
Editor_state.search_text = nil
Editor_state.cursor1 = Editor_state.search_backup.cursor
Editor_state.screen_top1 = Editor_state.search_backup.screen_top
Editor_state.search_backup = nil
State.search_term = nil
State.search_text = nil
State.cursor1 = State.search_backup.cursor
State.screen_top1 = State.search_backup.screen_top
State.search_backup = nil
local len = utf8.len(Editor_state.search_term)
local byte_offset = Text.offset(Editor_state.search_term, len)
Editor_state.search_term = string.sub(Editor_state.search_term, 1, byte_offset-1)
Editor_state.search_text = nil
local len = utf8.len(State.search_term)
local byte_offset = Text.offset(State.search_term, len)
State.search_term = string.sub(State.search_term, 1, byte_offset-1)
State.search_text = nil
Editor_state.search_term = ''
Editor_state.search_backup = {cursor={line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}, screen_top={line=Editor_state.screen_top1.line, pos=Editor_state.screen_top1.pos}}
assert(Editor_state.search_text == nil)
State.search_term = ''
State.search_backup = {cursor={line=State.cursor1.line, pos=State.cursor1.pos}, screen_top={line=State.screen_top1.line, pos=State.screen_top1.pos}}
assert(State.search_text == nil)
Editor_state.screen_top1 = deepcopy(src.screen_top)
Editor_state.cursor1 = deepcopy(src.cursor)
Editor_state.selection1 = deepcopy(src.selection)
patch(Editor_state.lines, event.after, event.before)
State.screen_top1 = deepcopy(src.screen_top)
State.cursor1 = deepcopy(src.cursor)
State.selection1 = deepcopy(src.selection)
patch(State.lines, event.after, event.before)
Editor_state.screen_top1 = deepcopy(src.screen_top)
Editor_state.cursor1 = deepcopy(src.cursor)
Editor_state.selection1 = deepcopy(src.selection)
patch(Editor_state.lines, event.before, event.after)
State.screen_top1 = deepcopy(src.screen_top)
State.cursor1 = deepcopy(src.cursor)
State.selection1 = deepcopy(src.selection)
patch(State.lines, event.before, event.after)
for _,line in ipairs(Editor_state.lines) do line.y = nil end -- just in case we scroll
local s = Text.cut_selection(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)
for _,line in ipairs(State.lines) do line.y = nil end -- just in case we scroll
local s = Text.cut_selection(State.margin_left, App.screen.width-State.margin_right)