Edit.lua v1.1.1 - Fixed some bugs with typing and scrolling - the editor is actually usable again.
This commit is contained in:
+1
-1
@@ -76,7 +76,7 @@ local agcfg = {
|
|||||||
},
|
},
|
||||||
["edit"] = {
|
["edit"] = {
|
||||||
["maindir"] = "",
|
["maindir"] = "",
|
||||||
["version"] = "1.1.0",
|
["version"] = "1.1.1",
|
||||||
["description"] = "The default text editor for Halyde.",
|
["description"] = "The default text editor for Halyde.",
|
||||||
["files"] = {
|
["files"] = {
|
||||||
"halyde/apps/edit.lua",
|
"halyde/apps/edit.lua",
|
||||||
|
|||||||
+24
-23
@@ -10,7 +10,7 @@ local cursorWhite = true
|
|||||||
local changesMade = false
|
local changesMade = false
|
||||||
local renderBuffer = gpu.allocateBuffer()
|
local renderBuffer = gpu.allocateBuffer()
|
||||||
local scrollSpeed = 5
|
local scrollSpeed = 5
|
||||||
--local ocelot = component.proxy(component.list("ocelot")())
|
local ocelot = component.ocelot
|
||||||
|
|
||||||
local function rawset(x, y, text)
|
local function rawset(x, y, text)
|
||||||
termlib.cursorPosX = x
|
termlib.cursorPosX = x
|
||||||
@@ -54,11 +54,12 @@ end
|
|||||||
local function render()
|
local function render()
|
||||||
gpu.setActiveBuffer(renderBuffer)
|
gpu.setActiveBuffer(renderBuffer)
|
||||||
clear()
|
clear()
|
||||||
local realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2)
|
ocelot.log(tostring(scrollPosY))
|
||||||
|
local realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2)
|
||||||
if realCursorX < 1 then
|
if realCursorX < 1 then
|
||||||
scrollPosX = scrollPosX + realCursorX - 1
|
scrollPosX = scrollPosX + realCursorX - 1
|
||||||
cursorPosX = 1
|
cursorPosX = 1
|
||||||
realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2)
|
realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2)
|
||||||
end
|
end
|
||||||
for i = scrollPosY, height + scrollPosY - 3 do
|
for i = scrollPosY, height + scrollPosY - 3 do
|
||||||
rawset(1, i - scrollPosY + 1, (tmpdata[i] or ""):sub(scrollPosX))
|
rawset(1, i - scrollPosY + 1, (tmpdata[i] or ""):sub(scrollPosX))
|
||||||
@@ -90,7 +91,7 @@ local function scrollUp()
|
|||||||
renderFlag = false
|
renderFlag = false
|
||||||
scrollPosY = 1
|
scrollPosY = 1
|
||||||
end
|
end
|
||||||
if math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2) < 1 then
|
if math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2) < 1 then
|
||||||
renderFlag = true
|
renderFlag = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -108,7 +109,7 @@ local function scrollDown()
|
|||||||
scrollPosY = scrollPosY + 1
|
scrollPosY = scrollPosY + 1
|
||||||
cursorPosY = height - 2
|
cursorPosY = height - 2
|
||||||
end
|
end
|
||||||
if math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2) < 1 then
|
if math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2) < 1 then
|
||||||
renderFlag = true
|
renderFlag = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -117,16 +118,16 @@ local function scrollLeft()
|
|||||||
cursorRenderFlag = true
|
cursorRenderFlag = true
|
||||||
cursorWhite = true
|
cursorWhite = true
|
||||||
if cursorPosX > 1 then
|
if cursorPosX > 1 then
|
||||||
if cursorPosX <= unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2 then
|
if cursorPosX <= unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2 then
|
||||||
cursorPosX = cursorPosX - 1
|
cursorPosX = cursorPosX - 1
|
||||||
elseif unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 1 > 1 then
|
elseif unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 1 > 1 then
|
||||||
cursorPosX = unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 1
|
cursorPosX = unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 1
|
||||||
end
|
end
|
||||||
elseif scrollPosX > 1 then
|
elseif scrollPosX > 1 then
|
||||||
scrollPosX = scrollPosX - 1
|
scrollPosX = scrollPosX - 1
|
||||||
renderFlag = true
|
renderFlag = true
|
||||||
end
|
end
|
||||||
if math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2) < 1 then
|
if math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2) < 1 then
|
||||||
renderFlag = true
|
renderFlag = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -134,7 +135,7 @@ end
|
|||||||
local function scrollRight()
|
local function scrollRight()
|
||||||
cursorRenderFlag = true
|
cursorRenderFlag = true
|
||||||
cursorWhite = true
|
cursorWhite = true
|
||||||
if cursorPosX <= unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 1 then
|
if cursorPosX <= unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 1 then
|
||||||
cursorPosX = cursorPosX + 1
|
cursorPosX = cursorPosX + 1
|
||||||
end
|
end
|
||||||
if cursorPosX > width then
|
if cursorPosX > width then
|
||||||
@@ -168,8 +169,8 @@ local function processEvent(args)
|
|||||||
changesMade = true
|
changesMade = true
|
||||||
renderFlag = true
|
renderFlag = true
|
||||||
cursorWhite = true
|
cursorWhite = true
|
||||||
table.insert(tmpdata, cursorPosY + 1, tmpdata[cursorPosY]:sub(cursorPosX))
|
table.insert(tmpdata, cursorPosY + 1, tmpdata[cursorPosY + scrollPosY - 1]:sub(cursorPosX))
|
||||||
tmpdata[cursorPosY] = tmpdata[cursorPosY]:sub(1, cursorPosX - 1)
|
tmpdata[cursorPosY + scrollPosY - 1] = tmpdata[cursorPosY + scrollPosY - 1]:sub(1, cursorPosX - 1)
|
||||||
cursorPosX = 1
|
cursorPosX = 1
|
||||||
cursorPosY = cursorPosY + 1
|
cursorPosY = cursorPosY + 1
|
||||||
scrollPosX = 1
|
scrollPosX = 1
|
||||||
@@ -191,23 +192,23 @@ local function processEvent(args)
|
|||||||
if scrollPosY < 1 then
|
if scrollPosY < 1 then
|
||||||
scrollPosY = 1
|
scrollPosY = 1
|
||||||
end
|
end
|
||||||
cursorPosX = unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2
|
cursorPosX = unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2
|
||||||
if cursorPosX > width then
|
if cursorPosX > width then
|
||||||
scrollPosX = cursorPosX - width + 1
|
scrollPosX = cursorPosX - width + 1
|
||||||
cursorPosX = width
|
cursorPosX = width
|
||||||
end
|
end
|
||||||
tmpdata[cursorPosY] = tmpdata[cursorPosY] .. tmpdata[cursorPosY + 1]
|
tmpdata[cursorPosY + scrollPosY - 1] = tmpdata[cursorPosY + scrollPosY - 1] .. tmpdata[cursorPosY + 1]
|
||||||
table.remove(tmpdata, cursorPosY + 1)
|
table.remove(tmpdata, cursorPosY + 1)
|
||||||
renderFlag = true
|
renderFlag = true
|
||||||
else
|
else
|
||||||
tmpdata[cursorPosY] = tmpdata[cursorPosY]:sub(1, cursorPosX + scrollPosX - 3) .. tmpdata[cursorPosY]:sub(cursorPosX + scrollPosX - 1)
|
tmpdata[cursorPosY + scrollPosY - 1] = tmpdata[cursorPosY + scrollPosY - 1]:sub(1, cursorPosX + scrollPosX - 3) .. tmpdata[cursorPosY + scrollPosY - 1]:sub(cursorPosX + scrollPosX - 1)
|
||||||
cursorPosX = math.min(cursorPosX - 1, unicode.wlen(tmpdata[cursorPosY]) + 1)
|
cursorPosX = math.min(cursorPosX - 1, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) + 1)
|
||||||
if cursorPosX < 1 then
|
if cursorPosX < 1 then
|
||||||
cursorPosX = 1
|
cursorPosX = 1
|
||||||
scrollPosX = scrollPosX - 1
|
scrollPosX = scrollPosX - 1
|
||||||
renderFlag = true
|
renderFlag = true
|
||||||
else
|
else
|
||||||
rawset(1, cursorPosY - scrollPosY + 1, tmpdata[cursorPosY]:sub(scrollPosX) .. " ")
|
rawset(1, cursorPosY, tmpdata[cursorPosY + scrollPosY - 1]:sub(scrollPosX) .. " ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -215,15 +216,15 @@ local function processEvent(args)
|
|||||||
changesMade = true
|
changesMade = true
|
||||||
cursorRenderFlag = true
|
cursorRenderFlag = true
|
||||||
cursorWhite = true
|
cursorWhite = true
|
||||||
tmpdata[cursorPosY] = tmpdata[cursorPosY]:sub(1, cursorPosX + scrollPosX - 2) .. unicode.char(args[3]) .. tmpdata[cursorPosY]:sub(cursorPosX + scrollPosX - 1)
|
tmpdata[cursorPosY + scrollPosY - 1] = tmpdata[cursorPosY + scrollPosY - 1]:sub(1, cursorPosX + scrollPosX - 2) .. unicode.char(args[3]) .. tmpdata[cursorPosY + scrollPosY - 1]:sub(cursorPosX + scrollPosX - 1)
|
||||||
cursorPosX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY])) + 1
|
cursorPosX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1])) + 1
|
||||||
--ocelot.log(tostring(cursorPosX))
|
--ocelot.log(tostring(cursorPosX))
|
||||||
if cursorPosX > width then
|
if cursorPosX > width then
|
||||||
cursorPosX = width
|
cursorPosX = width
|
||||||
scrollPosX = scrollPosX + 1
|
scrollPosX = scrollPosX + 1
|
||||||
renderFlag = true
|
renderFlag = true
|
||||||
else
|
else
|
||||||
rawset(1, cursorPosY - scrollPosY + 1, tmpdata[cursorPosY]:sub(scrollPosX))
|
rawset(1, cursorPosY, tmpdata[cursorPosY + scrollPosY - 1]:sub(scrollPosX))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif args[1] == "scroll" then
|
elseif args[1] == "scroll" then
|
||||||
@@ -272,7 +273,7 @@ render()
|
|||||||
while true do
|
while true do
|
||||||
local args = {event.pull(0.5)}
|
local args = {event.pull(0.5)}
|
||||||
local renderFlag, cursorRenderFlag, specialKey = false, false, nil
|
local renderFlag, cursorRenderFlag, specialKey = false, false, nil
|
||||||
local previousCursorX, previousCursorY = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2), cursorPosY
|
local previousCursorX, previousCursorY = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2), cursorPosY
|
||||||
if args and args[1] then
|
if args and args[1] then
|
||||||
cursorWhite = true
|
cursorWhite = true
|
||||||
renderFlag, cursorRenderFlag, specialKey = processEvent(args)
|
renderFlag, cursorRenderFlag, specialKey = processEvent(args)
|
||||||
@@ -305,11 +306,11 @@ while true do
|
|||||||
if cursorRenderFlag then
|
if cursorRenderFlag then
|
||||||
local char = gpu.get(previousCursorX, previousCursorY)
|
local char = gpu.get(previousCursorX, previousCursorY)
|
||||||
rawset(previousCursorX, previousCursorY, char)
|
rawset(previousCursorX, previousCursorY, char)
|
||||||
local realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2)
|
local realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2)
|
||||||
if realCursorX < 1 then
|
if realCursorX < 1 then
|
||||||
scrollPosX = scrollPosX + realCursorX - 1
|
scrollPosX = scrollPosX + realCursorX - 1
|
||||||
cursorPosX = 1
|
cursorPosX = 1
|
||||||
realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY]) - scrollPosX + 2)
|
realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2)
|
||||||
end
|
end
|
||||||
local char = gpu.get(realCursorX, cursorPosY)
|
local char = gpu.get(realCursorX, cursorPosY)
|
||||||
if cursorWhite then
|
if cursorWhite then
|
||||||
|
|||||||
Reference in New Issue
Block a user