Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
Bugs:
- Scrolling after autocomplete understanding
- Errors are now correctly displayed when running programs
- Behavior of the cursor during CTRL+[L/R]-ARROW revised
- Editor crashes when editing empty files without lines
  • Loading branch information
SammyForReal authored Mar 23, 2022
1 parent a52ab82 commit 68c68fc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cosu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ local sGithub = {
["api"]="https://api.github.com/repos/1turtle/consult/releases/latest",
["latest"]="https://github.com/1Turtle/consult/releases/latest/download/cosu.lua"
}
local sVersion = "1.1.1"
local sVersion = "1.1.2"
local sPath = ""
local tAutoCompleteList = { }
local tContent = { }
Expand Down Expand Up @@ -498,9 +498,17 @@ function file(event, ...)
local sDir = '/'..fs.getDir(shell.getRunningProgram())..'/'
local f = fs.open(sDir..".tmp"..multishell.getCurrent(), 'w')
f.flush()
f.write("local c=[[")
for _,sLine in pairs(tContent) do
f.writeLine(sLine)
end
f.writeLine("]]local o,f,e=false,loadstring(c)")
f.writeLine("if type(f)~=\"nil\" then o,e=pcall(f) end")
f.writeLine("if not o then")
f.writeLine("local x=e:reverse():find(\":[%d]+:\")")
f.writeLine("printError(\"ERROR:\"..e:sub(#e-x))")
f.writeLine("print(\"Press any key to exit.\")")
f.writeLine("os.pullEvent(\"char\") end")
f.close()
local nID = multishell.launch(_ENV, sDir..".tmp"..multishell.getCurrent(), ...)
multishell.setTitle(nID, "[run]-cosu")
Expand Down Expand Up @@ -1186,7 +1194,7 @@ function input.insert.cursorHorizontal(sWay, bJump)
if tCursor.x-tScroll.x+1 < 1 then
tScroll.x = tScroll.x - 1
end
until not bJump or tCursor.x <= 1 or tContent[tCursor.y]:sub(tCursor.x-1,tCursor.x-1)==' '
until not bJump or tCursor.x <= 1 or tContent[tCursor.y]:sub(tCursor.x-1,tCursor.x-1):match('[ %(%)%.]')
elseif tCursor.x == 1 and tCursor.y ~= 1 then
tCursor.y = tCursor.y - 1
tCursor.x = #tContent[tCursor.y] + 1
Expand All @@ -1204,7 +1212,7 @@ function input.insert.cursorHorizontal(sWay, bJump)
if tCursor.x-tScroll.x+1 >= w then
tScroll.x = tScroll.x + 1
end
until not bJump or tCursor.x >= #tContent[tCursor.y] or tContent[tCursor.y]:sub(tCursor.x,tCursor.x)==' '
until not bJump or tCursor.x >= #tContent[tCursor.y] or tContent[tCursor.y]:sub(tCursor.x-1,tCursor.x-1):match('[ %(%)%.]')
elseif tCursor.y < #tContent then
tCursor.x = 1
tCursor.lastX = tCursor.x
Expand Down Expand Up @@ -1240,6 +1248,7 @@ function input.insert.char(sChar,bCloseBrackets)
if sChar == "\000" then
sChar = '?'
end
if type(tContent[tCursor.y])=="nil" then tContent[tCursor.y]="" end
tContent[tCursor.y] = string.sub(sLine, 1, tCursor.x - 1) .. sChar .. string.sub(sLine, tCursor.x)
for i=1,#sChar do
input.insert.cursorHorizontal("right")
Expand Down Expand Up @@ -1553,13 +1562,13 @@ function input.insertAuto.cursorVertical(sWay)
if tCursor.autoListY > 0 then
tCursor.autoListY = tCursor.autoListY - 1
else
input.insert.mouseScroll(-1)
input.insert.cursorVertical("up")
end
elseif sWay == "down" then
if tCursor.autoListY < #tAutoCompleteList-1 then
tCursor.autoListY = tCursor.autoListY + 1
else
input.insert.mouseScroll(1)
input.insert.cursorVertical("down")
end
end
end
Expand Down

0 comments on commit 68c68fc

Please sign in to comment.