JCRUUD2SRLBSGPWZVXWOSZYJCW32JNBJKRC7PMBUHGUI6YX63W3QC
4HR3G5ZDDSRHUV4JQKUWGRP3PHIGGZIMDGEDB6TEZCNK3URVRBUQC
X43ZIKR3WHHUHTIBN76H25FLACL7SMKXXHFX7GDD552UF3V2UDPAC
KRLRRLVGMTN66AWJ3EB6P6ZLFSGVBMMGACA7I4FXCGVRNTKOYV7AC
HWTLXESCGV3A63XI62ZV4NXRE2AXTZS32P5QBWYGMSCTQDZTISPQC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
JOPVPUSAMMU6RFVDQR4NJC4GNNUFB7GPKVH7OS5FKCYS5QZ53VLQC
CUFW4EJL75OAA5BS5EXGTM5RMRNJOBBPAXUJADGZ3VLP2ZMKFOTAC
3QNOKBFMKBGXBVJIRHR2444JRRMBTABHE4674NR3DT67RRM2X6GAC
FPY4LO2WZNXUYCZ6MOQBSPGCC3M3PE7YX2TJIFRNEQLJ4ACWUPVAC
3QWK3GSA5KTVQJKXQ65OGZA2AORHFALLBXWP2A4MN6YDE7VV4PUAC
36Z442IVPXHZ7D2QI26YLN3TDDEMDRQ2GKBYQAD6NUHQZVCCY4VAC
AVTNUQYRBW7IX2YQ3KDLVQ23RGW3BAKTAE7P73ASBYNKOHMQMH5AC
QD4LOFQRYRXS5GCJLR4EKQPQBFYZA5CGRVJYVFT2U7GXZDAIUJNQC
ED4Z6ORCADLWJPSZNKQVUF63NBKLQVE7UFMBTQAQA5O47X4NLFIAC
HKV72RZVJEOF5GCHCRKEBGC3FQN7AYETY7LKEJUXVIQAB4QPEPYQC
local outfile = App.open_for_writing(App.save_dir..State.filename)
if outfile == nil then
error('failed to write to "'..State.filename..'"')
end
for _,line in ipairs(State.lines) do
local infile = App.open_for_reading(App.save_dir..State.filename)
if not infile then
infile = App.open_for_reading(App.source_dir..State.filename)
end
State.lines = load_from_file(infile)
if infile then infile:close() end
end
function load_from_file(infile)
local result = {}
if infile then
local infile_next_line = infile:lines() -- works with both Lua files and LÖVE Files (https://www.love2d.org/wiki/File)
while true do
local line = infile_next_line()
if line == nil then break end
-- the source editor supports only files in the save dir backed by the source dir
function load_from_disk(State)
local infile = App.open_for_reading(App.save_dir..filename)
if not infile then
infile = App.open_for_reading(App.source_dir..filename)
end
if infile then
infile:close()
return true
else
return false
end
end
local clipboard_data = App.get_clipboard()
for _,code in utf8.codes(clipboard_data) do
local c = utf8.char(code)
if c == '\n' then
Text.insert_return(State)
else
Text.insert_at_cursor(State, c)
end
end
if Text.cursor_out_of_screen(State) then
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
end
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
App.set_clipboard(s)
end
schedule_save(State)
elseif chord == 'C-v' then
for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll
-- We don't have a good sense of when to scroll, so we'll be conservative
-- and sometimes scroll when we didn't quite need to.
local before_line = State.cursor1.line
local before = snapshot(State, before_line)
App.set_clipboard(s)
end
elseif chord == 'C-x' then
for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll
local s = Text.cut_selection(State, State.left, State.right)
if s then
App.open_for_reading =
function(filename)
local result = nativefs.newFile(filename)
local ok, err = result:open('r')
if ok then
return result
else
return ok, err
end
App.open_for_writing =
function(filename)
local result = nativefs.newFile(filename)
local ok, err = result:open('w')
if ok then
return result
else
return ok, err
end
App.files = nativefs.getDirectoryItems
App.source_dir = love.filesystem.getSource()..'/'
App.current_dir = nativefs.getWorkingDirectory()..'/'
App.save_dir = love.filesystem.getSaveDirectory()..'/'
App.get_time = love.timer.getTime
App.get_clipboard = love.system.getClipboardText
App.set_clipboard = love.system.setClipboardText