mirror of
https://github.com/LDDestroier/CC/
synced 2025-01-31 19:29:11 +00:00
Update eldit.lua
This commit is contained in:
parent
e9520031d2
commit
962a1d3c0c
74
eldit.lua
74
eldit.lua
@ -185,16 +185,18 @@ prompt = function(prebuffer)
|
|||||||
for y = 1, eldit.size.height - 1 do -- minus one because it reserves space for the bar
|
for y = 1, eldit.size.height - 1 do -- minus one because it reserves space for the bar
|
||||||
cy = y + eldit.scrollY
|
cy = y + eldit.scrollY
|
||||||
-- find text
|
-- find text
|
||||||
for x = 1, #eldit.buffer[cy] do
|
if eldit.buffer[cy] then
|
||||||
if (not tab[eldit.buffer[cy][x]]) and eldit.buffer[cy][x] then
|
for x = 1, #eldit.buffer[cy] do
|
||||||
textPoses[1] = x
|
if (not tab[eldit.buffer[cy][x]]) and eldit.buffer[cy][x] then
|
||||||
break
|
textPoses[1] = x
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
for x = #eldit.buffer[cy], 1, -1 do
|
||||||
for x = #eldit.buffer[cy], 1, -1 do
|
if (not tab[eldit.buffer[cy][x]]) and eldit.buffer[cy][x] then
|
||||||
if (not tab[eldit.buffer[cy][x]]) and eldit.buffer[cy][x] then
|
textPoses[2] = x
|
||||||
textPoses[2] = x
|
break
|
||||||
break
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local isHighlighted = false
|
local isHighlighted = false
|
||||||
@ -213,18 +215,21 @@ prompt = function(prebuffer)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
term.setCursorPos(eldit.size.x, eldit.size.y + y - 1)
|
term.setCursorPos(eldit.size.x, eldit.size.y + y - 1)
|
||||||
if isHighlighted then
|
if cy <= #eldit.buffer then
|
||||||
term.setBackgroundColor(colors.gray)
|
if isHighlighted then
|
||||||
term.setTextColor(colors.white)
|
term.setBackgroundColor(colors.gray)
|
||||||
|
term.setTextColor(colors.white)
|
||||||
|
else
|
||||||
|
term.setBackgroundColor(colors.black)
|
||||||
|
term.setTextColor(colors.lightGray)
|
||||||
|
end
|
||||||
|
term.write(cy .. (" "):rep(lineNoLen - #tostring(y)))
|
||||||
else
|
else
|
||||||
term.setBackgroundColor(colors.black)
|
term.write(" ")
|
||||||
term.setTextColor(colors.lightGray)
|
|
||||||
end
|
end
|
||||||
term.write(cy .. (" "):rep(lineNoLen - #tostring(y)))
|
|
||||||
for x = lineNoLen + 1, eldit.size.width do
|
for x = lineNoLen + 1, eldit.size.width do
|
||||||
term.setCursorPos(eldit.size.x + x - 1, eldit.size.y + y - 1)
|
term.setCursorPos(eldit.size.x + x - 1, eldit.size.y + y - 1)
|
||||||
cx = x + eldit.scrollX - lineNoLen
|
cx = x + eldit.scrollX - lineNoLen
|
||||||
cy = y + eldit.scrollY
|
|
||||||
|
|
||||||
if checkIfSelected(cx, cy) then
|
if checkIfSelected(cx, cy) then
|
||||||
term.setBackgroundColor(colors.blue)
|
term.setBackgroundColor(colors.blue)
|
||||||
@ -243,12 +248,16 @@ prompt = function(prebuffer)
|
|||||||
else
|
else
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
end
|
end
|
||||||
if cx < textPoses[1] and eldit.buffer[cy][cx] then
|
if textPoses[1] and textPoses[2] and eldit.buffer[cy] then
|
||||||
term.setTextColor(colors.gray)
|
if cx < textPoses[1] and eldit.buffer[cy][cx] then
|
||||||
term.write("|")
|
term.setTextColor(colors.gray)
|
||||||
elseif (cx > textPoses[2] and eldit.buffer[cy][cx]) then
|
term.write("|")
|
||||||
term.setTextColor(colors.gray)
|
elseif (cx > textPoses[2] and eldit.buffer[cy][cx]) then
|
||||||
term.write("-")
|
term.setTextColor(colors.gray)
|
||||||
|
term.write("-")
|
||||||
|
else
|
||||||
|
term.write(getChar(cx, cy) or " ")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
term.write(getChar(cx, cy) or " ")
|
term.write(getChar(cx, cy) or " ")
|
||||||
end
|
end
|
||||||
@ -352,7 +361,7 @@ prompt = function(prebuffer)
|
|||||||
if cx < #eldit.buffer[cy] then
|
if cx < #eldit.buffer[cy] then
|
||||||
xAdjList[cy] = (xAdjList[cy] or 0) + 1
|
xAdjList[cy] = (xAdjList[cy] or 0) + 1
|
||||||
table.remove(eldit.buffer[cy], cx)
|
table.remove(eldit.buffer[cy], cx)
|
||||||
else
|
elseif cy < #eldit.buffer then
|
||||||
for i = 1, #eldit.buffer[cy + 1] do
|
for i = 1, #eldit.buffer[cy + 1] do
|
||||||
table.insert(eldit.buffer[cy], eldit.buffer[cy + 1][i])
|
table.insert(eldit.buffer[cy], eldit.buffer[cy + 1][i])
|
||||||
end
|
end
|
||||||
@ -485,6 +494,12 @@ prompt = function(prebuffer)
|
|||||||
cur.x = cur.x - ((xAdjusts[cur.y] or {})[cur.x] or 0) + (xAdjList[cur.y] or 0)
|
cur.x = cur.x - ((xAdjusts[cur.y] or {})[cur.x] or 0) + (xAdjList[cur.y] or 0)
|
||||||
for i = 1, #text do
|
for i = 1, #text do
|
||||||
if isInsert then
|
if isInsert then
|
||||||
|
if cur.x == #eldit.buffer[cur.y] + 1 then
|
||||||
|
for i = 1, #eldit.buffer[cur.y + 1] do
|
||||||
|
table.insert(eldit.buffer[cur.y], eldit.buffer[cur.y + 1][i])
|
||||||
|
end
|
||||||
|
table.remove(eldit.buffer, cur.y + 1)
|
||||||
|
end
|
||||||
eldit.buffer[cur.y][cur.x + i - 1] = text:sub(i,i)
|
eldit.buffer[cur.y][cur.x + i - 1] = text:sub(i,i)
|
||||||
else
|
else
|
||||||
table.insert(eldit.buffer[cur.y], cur.x, text:sub(i,i))
|
table.insert(eldit.buffer[cur.y], cur.x, text:sub(i,i))
|
||||||
@ -614,6 +629,7 @@ prompt = function(prebuffer)
|
|||||||
doRender = true
|
doRender = true
|
||||||
elseif evt[1] == "key" then
|
elseif evt[1] == "key" then
|
||||||
keysDown[evt[2]] = true
|
keysDown[evt[2]] = true
|
||||||
|
-- KEYBOARD SHORTCUTS
|
||||||
if keysDown[keys.leftCtrl] or keysDown[keys.leftCtrl] then
|
if keysDown[keys.leftCtrl] or keysDown[keys.leftCtrl] then
|
||||||
|
|
||||||
if evt[2] == keys.backspace then
|
if evt[2] == keys.backspace then
|
||||||
@ -630,6 +646,18 @@ prompt = function(prebuffer)
|
|||||||
elseif evt[2] == keys.s then
|
elseif evt[2] == keys.s then
|
||||||
saveFile()
|
saveFile()
|
||||||
|
|
||||||
|
elseif evt[2] == keys.a then
|
||||||
|
eldit.selections = {{
|
||||||
|
{
|
||||||
|
x = 1,
|
||||||
|
y = 1
|
||||||
|
},{
|
||||||
|
x = #eldit.buffer[#eldit.buffer],
|
||||||
|
y = #eldit.buffer
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
doRender = true
|
||||||
|
|
||||||
elseif evt[2] == keys.left then
|
elseif evt[2] == keys.left then
|
||||||
adjustCursor(-1, 0, true, "word")
|
adjustCursor(-1, 0, true, "word")
|
||||||
doRender, isCursorBlink = true, true
|
doRender, isCursorBlink = true, true
|
||||||
|
Loading…
Reference in New Issue
Block a user