fixed edit writing an additional newline after the last line; fixed editor erroring when opening existing but empty files, fixes #39 and closes #43

This commit is contained in:
Florian Nücke 2013-12-31 19:17:11 +01:00
parent 77d3c1bd1e
commit d3538a55bc

View File

@ -262,8 +262,10 @@ local function onKeyDown(char, code)
if f then if f then
local chars = 0 local chars = 0
for _, line in ipairs(buffer) do for _, line in ipairs(buffer) do
if chars > 0 then
line = line .. "\n"
end
f:write(line) f:write(line)
f:write("\n")
chars = chars + unicode.len(line) chars = chars + unicode.len(line)
end end
f:close() f:close()
@ -330,6 +332,9 @@ do
end end
end end
f:close() f:close()
if #buffer == 0 then
table.insert(buffer, "")
end
local format local format
if readonly then if readonly then
format = [["%s" [readonly] %dL,%dC]] format = [["%s" [readonly] %dL,%dC]]