mirror of https://github.com/LDDestroier/CC/
Optimized deleteSelections(), adde CTRL+[ and ]
This commit is contained in:
parent
7869eee78f
commit
61e41ad13b
411
eldit.lua
411
eldit.lua
|
@ -14,12 +14,12 @@ eldit.undoBuffer = {{{}}} -- stores buffers for undoing/redoing
|
||||||
eldit.allowUndo = true -- whether or not to allow undoing/redoing
|
eldit.allowUndo = true -- whether or not to allow undoing/redoing
|
||||||
eldit.maxUndo = 16 -- maximum size of the undo buffer
|
eldit.maxUndo = 16 -- maximum size of the undo buffer
|
||||||
eldit.undoPos = 1 -- current position in undo buffer
|
eldit.undoPos = 1 -- current position in undo buffer
|
||||||
eldit.undoDelay = 0.5 -- amount of time to wait after typing, before the buffer is put in the undo buffer
|
eldit.undoDelay = 0.3 -- amount of time to wait after typing, before the buffer is put in the undo buffer
|
||||||
eldit.clipboards = {} -- all clipboard entries
|
eldit.clipboards = {} -- all clipboard entries
|
||||||
eldit.selectedClipboard = 1 -- which clipboard to use
|
eldit.selectedClipboard = 1 -- which clipboard to use
|
||||||
eldit.scrollX = 0 -- horizontal scroll
|
eldit.scrollX = 0 -- horizontal scroll
|
||||||
eldit.scrollY = 0 -- vertical scroll
|
eldit.scrollY = 0 -- vertical scroll
|
||||||
eldit.selections = {}
|
eldit.selections = {} -- all selected areas
|
||||||
eldit.size = {
|
eldit.size = {
|
||||||
x = 1, -- top left corner X
|
x = 1, -- top left corner X
|
||||||
y = 1, -- top left corner Y
|
y = 1, -- top left corner Y
|
||||||
|
@ -100,6 +100,7 @@ local eClear = function()
|
||||||
term.setCursorPos(cx, cy)
|
term.setCursorPos(cx, cy)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- sorts all selections based on each of their (x,y) positions (top left first)
|
||||||
local sortSelections = function()
|
local sortSelections = function()
|
||||||
for id,sel in pairs(eldit.selections) do
|
for id,sel in pairs(eldit.selections) do
|
||||||
sortTable(sel, function(a,b)
|
sortTable(sel, function(a,b)
|
||||||
|
@ -108,6 +109,7 @@ local sortSelections = function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- sorts all cursors based on (x,y) position (top left first)
|
||||||
local sortCursors = function()
|
local sortCursors = function()
|
||||||
sortTable(eldit.cursors, function(a,b)
|
sortTable(eldit.cursors, function(a,b)
|
||||||
return (a.y * eldit.size.width) + a.x < (b.y * eldit.size.width) + b.x
|
return (a.y * eldit.size.width) + a.x < (b.y * eldit.size.width) + b.x
|
||||||
|
@ -162,6 +164,23 @@ deepCopy = function(tbl)
|
||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local choice = function(input, breakKeys, returnNumber)
|
||||||
|
local fpos = 0
|
||||||
|
repeat
|
||||||
|
event, key = os.pullEvent("char")
|
||||||
|
key = key or ""
|
||||||
|
if type(breakKeys) == "table" then
|
||||||
|
for a = 1, #breakKeys do
|
||||||
|
if key == breakKeys[a] then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
fpos = string.find(input, key)
|
||||||
|
until fpos
|
||||||
|
return returnNumber and fpos or key
|
||||||
|
end
|
||||||
|
|
||||||
prompt = function(prebuffer, precy, maxY, _eldit)
|
prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
term.setCursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
local keysDown = {} -- list of all keys being pressed
|
local keysDown = {} -- list of all keys being pressed
|
||||||
|
@ -218,6 +237,27 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
[","] = true
|
[","] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- checks if (checkX, checkY) is between (x1, y1) and (x2, y2) in terms of selection (it's not a rectangular check)
|
||||||
|
local checkWithinArea = function(checkX, checkY, x1, y1, x2, y2)
|
||||||
|
if checkY == y1 then
|
||||||
|
if y1 == y2 then
|
||||||
|
return checkX >= x1 and checkX <= x2
|
||||||
|
else
|
||||||
|
return checkX >= x1
|
||||||
|
end
|
||||||
|
elseif checkY == y2 then
|
||||||
|
if y1 == y2 then
|
||||||
|
return checkX >= x1 and checkX <= x2
|
||||||
|
else
|
||||||
|
return checkX <= x2 and checkX >= 1
|
||||||
|
end
|
||||||
|
elseif checkY > y1 and checkY < y2 then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- goes over every selection and checks if it is selected
|
-- goes over every selection and checks if it is selected
|
||||||
-- (x, y) = position on buffer
|
-- (x, y) = position on buffer
|
||||||
local checkIfSelected = function(x, y)
|
local checkIfSelected = function(x, y)
|
||||||
|
@ -227,23 +267,7 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
if x >= 1 and x <= #eldit.buffer[y] + 1 then
|
if x >= 1 and x <= #eldit.buffer[y] + 1 then
|
||||||
for id, sel in pairs(eldit.selections) do
|
for id, sel in pairs(eldit.selections) do
|
||||||
|
|
||||||
if y == sel[1].y then
|
if checkWithinArea(x, y, sel[1].x, sel[1].y, sel[2].x, sel[2].y) then
|
||||||
if sel[2].y == sel[1].y then
|
|
||||||
fin = x >= sel[1].x and x <= sel[2].x
|
|
||||||
else
|
|
||||||
fin = x >= sel[1].x
|
|
||||||
end
|
|
||||||
elseif y == sel[2].y then
|
|
||||||
if sel[2].y == sel[1].y then
|
|
||||||
fin = x >= sel[1].x and x <= sel[2].x
|
|
||||||
else
|
|
||||||
fin = x <= sel[2].x
|
|
||||||
end
|
|
||||||
elseif y > sel[1].y and y < sel[2].y then
|
|
||||||
fin = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fin then
|
|
||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -561,6 +585,62 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
return yAdj
|
return yAdj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local indentLines = function(goBackward)
|
||||||
|
sortSelections()
|
||||||
|
local safeY = {}
|
||||||
|
for id,sel in pairs(eldit.selections) do
|
||||||
|
for y = sel[1].y, sel[2].y do
|
||||||
|
if not safeY[y] then
|
||||||
|
if goBackward then
|
||||||
|
if eldit.buffer[y][1] == "\9" or eldit.buffer[y][1] == " " then
|
||||||
|
table.remove(eldit.buffer[y], 1)
|
||||||
|
if y == sel[1].y then
|
||||||
|
sel[1].x = math.max(1, -1 + sel[1].x)
|
||||||
|
elseif y == sel[2].y then
|
||||||
|
sel[2].x = math.max(1, -1 + sel[2].x)
|
||||||
|
end
|
||||||
|
for idd,cur in pairs(eldit.cursors) do
|
||||||
|
if cur.y == y and cur.x > 1 then
|
||||||
|
cur.x = -1 + cur.x
|
||||||
|
cur.lastX = cur.x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif eldit.buffer[y] then
|
||||||
|
table.insert(eldit.buffer[y], 1, "\9")
|
||||||
|
if y == sel[1].y then
|
||||||
|
sel[1].x = 1 + sel[1].x
|
||||||
|
elseif y == sel[2].y then
|
||||||
|
sel[2].x = 1 + sel[2].x
|
||||||
|
end
|
||||||
|
for idd,cur in pairs(eldit.cursors) do
|
||||||
|
if cur.y == y and cur.x < #eldit.buffer[y] then
|
||||||
|
cur.x = 1 + cur.x
|
||||||
|
cur.lastX = cur.x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
safeY[y] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for id,cur in pairs(eldit.cursors) do
|
||||||
|
if not safeY[cur.y] then
|
||||||
|
if goBackward then
|
||||||
|
if eldit.buffer[cur.y][1] == "\9" or eldit.buffer[cur.y][1] == " " then
|
||||||
|
table.remove(eldit.buffer[cur.y], 1)
|
||||||
|
cur.x = -1 + cur.x
|
||||||
|
cur.lastX = cur.x
|
||||||
|
end
|
||||||
|
else
|
||||||
|
table.insert(eldit.buffer[cur.y], 1, "\9")
|
||||||
|
cur.x = 1 + cur.x
|
||||||
|
cur.lastX = cur.x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- moves the cursor by (xmod, ymod), and fixes its position if it's set to an invalid one
|
-- moves the cursor by (xmod, ymod), and fixes its position if it's set to an invalid one
|
||||||
local adjustCursor = function(_xmod, _ymod, setLastX, mode, doNotDelSelections)
|
local adjustCursor = function(_xmod, _ymod, setLastX, mode, doNotDelSelections)
|
||||||
for id,cur in pairs(eldit.cursors) do
|
for id,cur in pairs(eldit.cursors) do
|
||||||
|
@ -625,36 +705,37 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
local yAdjusts = {}
|
local yAdjusts = {}
|
||||||
local xAdj = 0
|
local xAdj = 0
|
||||||
local yAdj = 0
|
local yAdj = 0
|
||||||
for y = 1, #eldit.buffer do
|
for id,sel in pairs(eldit.selections) do
|
||||||
xAdjusts[y] = {}
|
for y = sel[1].y, sel[2].y do
|
||||||
if checkIfSelected(#eldit.buffer[y] + 1, y) then
|
xAdjusts[y] = xAdjusts[y] or {}
|
||||||
yAdj = yAdj + 1
|
if checkWithinArea(#eldit.buffer[y] + 1, y, sel[1].x, sel[1].y, sel[2].x, sel[2].y) then
|
||||||
end
|
yAdj = yAdj + 1
|
||||||
yAdjusts[y + 1] = yAdj
|
end
|
||||||
xAdj = 0
|
yAdjusts[y + 1] = math.min(yAdjusts[y + 1] or math.huge, yAdj)
|
||||||
for x = 2, #eldit.buffer[y] do
|
for x = 2, #eldit.buffer[y] do
|
||||||
xAdjusts[y][x] = xAdj
|
xAdjusts[y][x] = math.min(xAdjusts[y][x] or math.huge, xAdj)
|
||||||
if checkIfSelected(x, y) then
|
if checkWithinArea(x, y, sel[1].x, sel[1].y, sel[2].x, sel[2].y) then
|
||||||
xAdj = xAdj + 1
|
xAdj = xAdj + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for y = #eldit.buffer, 1, -1 do
|
for id,sel in pairs(eldit.selections) do
|
||||||
for x = #eldit.buffer[y] + 1, 1, -1 do
|
for y = sel[2].y, sel[1].y, -1 do
|
||||||
|
for x = #eldit.buffer[y] + 1, 1, -1 do
|
||||||
if checkIfSelected(x, y) then
|
if checkWithinArea(x, y, sel[1].x, sel[1].y, sel[2].x, sel[2].y) then
|
||||||
if x == #eldit.buffer[y] + 1 then
|
if x == #eldit.buffer[y] + 1 then
|
||||||
if eldit.buffer[y + 1] then
|
if eldit.buffer[y + 1] then
|
||||||
for i = 1, #eldit.buffer[y + 1] do
|
for i = 1, #eldit.buffer[y + 1] do
|
||||||
table.insert(eldit.buffer[y], eldit.buffer[y + 1][i])
|
table.insert(eldit.buffer[y], eldit.buffer[y + 1][i])
|
||||||
|
end
|
||||||
|
table.remove(eldit.buffer, y + 1)
|
||||||
end
|
end
|
||||||
table.remove(eldit.buffer, y + 1)
|
else
|
||||||
|
deleteText("single", nil, x, y)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
deleteText("single", nil, x, y)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
eldit.selections = {}
|
eldit.selections = {}
|
||||||
|
@ -731,8 +812,17 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- simulate key inputs, for pre-entering text into read()
|
||||||
|
local simType = function(text)
|
||||||
|
for i = 1, #text do
|
||||||
|
os.queueEvent("key", keys[text:sub(i,i)])
|
||||||
|
os.queueEvent("char", text:sub(i,i))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- saves to file, duhh
|
-- saves to file, duhh
|
||||||
local saveFile = function()
|
local saveFile = function(preSaveAs)
|
||||||
|
keysDown, miceDown = {}, {}
|
||||||
local compiled = ""
|
local compiled = ""
|
||||||
for y = 1, #eldit.buffer do
|
for y = 1, #eldit.buffer do
|
||||||
compiled = compiled .. concatTable(eldit.buffer[y])
|
compiled = compiled .. concatTable(eldit.buffer[y])
|
||||||
|
@ -740,8 +830,11 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
compiled = compiled .. "\n"
|
compiled = compiled .. "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not eldit.filename then
|
if preSaveAs or (not eldit.filename) then
|
||||||
local cx, cy
|
local newName, cx, cy = ""
|
||||||
|
if type(preSaveAs) == "string" then
|
||||||
|
simType(preSaveAs)
|
||||||
|
end
|
||||||
repeat
|
repeat
|
||||||
render()
|
render()
|
||||||
term.setCursorPos(eldit.size.y, eldit.size.y + eldit.size.height - 1)
|
term.setCursorPos(eldit.size.y, eldit.size.y + eldit.size.height - 1)
|
||||||
|
@ -751,16 +844,46 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
cx, cy = term.getCursorPos()
|
cx, cy = term.getCursorPos()
|
||||||
term.setCursorPos(cx, cy)
|
term.setCursorPos(cx, cy)
|
||||||
eldit.filename = read()
|
newName = read()
|
||||||
|
if tab[newName:sub(-1,-1)] then
|
||||||
|
render()
|
||||||
|
term.setCursorPos(eldit.size.y, eldit.size.y + eldit.size.height - 1)
|
||||||
|
term.write("Path cannot have trailing space!")
|
||||||
|
sleep(0.5)
|
||||||
|
simType(newName)
|
||||||
|
elseif fs.exists(newName) and newName ~= "" then
|
||||||
|
render()
|
||||||
|
term.setCursorPos(eldit.size.y, eldit.size.y + eldit.size.height - 1)
|
||||||
|
eClearLine()
|
||||||
|
if fs.isDir(newName) then
|
||||||
|
term.write("Cannot overwrite a directory!")
|
||||||
|
sleep(0.5)
|
||||||
|
simType(newName)
|
||||||
|
else
|
||||||
|
term.write("Overwrite? (Y/N)")
|
||||||
|
if choice("yn", nil, false) == "n" then
|
||||||
|
barmsg = "Cancelled save."
|
||||||
|
barlife = defaultBarLife
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
until (
|
until (
|
||||||
(not fs.isDir(eldit.filename)) and
|
(not fs.isDir(newName) or newName == "") and
|
||||||
#eldit.filename:gsub(" ", "") > 0
|
(#newName:gsub(" ", "") > 0 or newName == "") and
|
||||||
|
not tab[newName:sub(-1,-1)]
|
||||||
)
|
)
|
||||||
|
if newName == "" then
|
||||||
|
barmsg = "Cancelled save."
|
||||||
|
barlife = defaultBarLife
|
||||||
|
return
|
||||||
|
else
|
||||||
|
eldit.filename = newName
|
||||||
|
end
|
||||||
end
|
end
|
||||||
writeFile(eldit.filename, compiled)
|
writeFile(eldit.filename, compiled)
|
||||||
barmsg = "Saved to '" .. eldit.filename .. "'."
|
barmsg = "Saved to '" .. eldit.filename .. "'."
|
||||||
barlife = defaultBarLife
|
barlife = defaultBarLife
|
||||||
keysDown, miceDown = {}, {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local evt
|
local evt
|
||||||
|
@ -926,6 +1049,13 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
barlife = defaultBarLife
|
barlife = defaultBarLife
|
||||||
end
|
end
|
||||||
doRender = true
|
doRender = true
|
||||||
|
|
||||||
|
elseif evt[2] == keys.s then
|
||||||
|
saveFile(eldit.filename)
|
||||||
|
tID = os.startTimer(0.4)
|
||||||
|
bartID = os.startTimer(0.1)
|
||||||
|
doRender = true
|
||||||
|
|
||||||
end
|
end
|
||||||
-- In-editor pasting is done with the "paste" event!
|
-- In-editor pasting is done with the "paste" event!
|
||||||
else
|
else
|
||||||
|
@ -933,7 +1063,16 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
eldit.selectedClipboard = numToKey[evt[2]]
|
eldit.selectedClipboard = numToKey[evt[2]]
|
||||||
barmsg = "Selected clipboard " .. eldit.selectedClipboard .. "."
|
barmsg = "Selected clipboard " .. eldit.selectedClipboard .. "."
|
||||||
barlife = defaultBarLife
|
barlife = defaultBarLife
|
||||||
|
doRender = true
|
||||||
|
|
||||||
|
elseif evt[2] == keys.rightBracket then
|
||||||
|
indentLines(false)
|
||||||
|
doRender, isCursorBlink = true, true
|
||||||
|
|
||||||
|
elseif evt[2] == keys.leftBracket then
|
||||||
|
indentLines(true)
|
||||||
|
doRender, isCursorBlink = true, true
|
||||||
|
|
||||||
elseif evt[2] == keys.backspace then
|
elseif evt[2] == keys.backspace then
|
||||||
if #eldit.selections > 0 then
|
if #eldit.selections > 0 then
|
||||||
deleteSelections()
|
deleteSelections()
|
||||||
|
@ -956,7 +1095,7 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
return "exit"
|
return "exit"
|
||||||
|
|
||||||
elseif evt[2] == keys.s then
|
elseif evt[2] == keys.s then
|
||||||
saveFile()
|
saveFile(false)
|
||||||
tID = os.startTimer(0.4)
|
tID = os.startTimer(0.4)
|
||||||
bartID = os.startTimer(0.1)
|
bartID = os.startTimer(0.1)
|
||||||
doRender = true
|
doRender = true
|
||||||
|
@ -1021,35 +1160,10 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
else
|
else
|
||||||
|
|
||||||
if evt[2] == keys.tab then
|
if evt[2] == keys.tab then
|
||||||
if #eldit.selections > 0 then
|
if keysDown[keys.leftShift] then
|
||||||
sortSelections()
|
indentLines(true)
|
||||||
local safeY = {}
|
elseif #eldit.selections > 0 then
|
||||||
for id,sel in pairs(eldit.selections) do
|
indentLines(false)
|
||||||
for y = sel[1].y, sel[2].y do
|
|
||||||
if not safeY[y] then
|
|
||||||
if keysDown[keys.leftShift] then
|
|
||||||
if eldit.buffer[y][1] == "\9" or eldit.buffer[y][1] == " " then
|
|
||||||
table.remove(eldit.buffer[y], 1)
|
|
||||||
for idd,cur in pairs(eldit.cursors) do
|
|
||||||
if cur.y == y and cur.x > 1 then
|
|
||||||
cur.x = cur.x - 1
|
|
||||||
cur.lastX = cur.x
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif eldit.buffer[y] then
|
|
||||||
table.insert(eldit.buffer[y], 1, "\9")
|
|
||||||
for idd,cur in pairs(eldit.cursors) do
|
|
||||||
if cur.y == y and cur.x < #eldit.buffer[y] then
|
|
||||||
cur.x = cur.x + 1
|
|
||||||
cur.lastX = cur.x
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
safeY[y] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
placeText("\9")
|
placeText("\9")
|
||||||
end
|
end
|
||||||
|
@ -1063,7 +1177,7 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
elseif evt[2] == keys.enter then
|
elseif evt[2] == keys.enter then
|
||||||
deleteSelections()
|
deleteSelections()
|
||||||
makeNewLine()
|
makeNewLine()
|
||||||
doRender, isCursorBlink = true, false
|
doRender, isCursorBlink = true, true
|
||||||
if eldit.allowUndo then undotID = os.startTimer(eldit.undoDelay) end
|
if eldit.allowUndo then undotID = os.startTimer(eldit.undoDelay) end
|
||||||
|
|
||||||
elseif evt[2] == keys.home then
|
elseif evt[2] == keys.home then
|
||||||
|
@ -1141,67 +1255,96 @@ prompt = function(prebuffer, precy, maxY, _eldit)
|
||||||
elseif evt[1] == "mouse_click" then
|
elseif evt[1] == "mouse_click" then
|
||||||
local lineNoLen = getLineNoLen()
|
local lineNoLen = getLineNoLen()
|
||||||
miceDown[evt[2]] = {x = evt[3], y = evt[4]}
|
miceDown[evt[2]] = {x = evt[3], y = evt[4]}
|
||||||
if keysDown[keys.leftCtrl] then
|
if evt[4] == -1 + eldit.size.y + eldit.size.height then
|
||||||
table.insert(eldit.cursors, {
|
|
||||||
x = evt[3] + eldit.scrollX - lineNoLen,
|
|
||||||
y = evt[4] + eldit.scrollY,
|
|
||||||
lastX = evt[3] + eldit.scrollX - lineNoLen
|
|
||||||
})
|
|
||||||
else
|
else
|
||||||
eldit.cursors = {{
|
if keysDown[keys.leftCtrl] then
|
||||||
x = evt[3] + eldit.scrollX - lineNoLen,
|
table.insert(eldit.cursors, {
|
||||||
y = evt[4] + eldit.scrollY,
|
x = evt[3] + eldit.scrollX - lineNoLen,
|
||||||
lastX = evt[3] + eldit.scrollX - lineNoLen
|
y = evt[4] + eldit.scrollY,
|
||||||
}}
|
lastX = evt[3] + eldit.scrollX - lineNoLen
|
||||||
eldit.selections = {}
|
})
|
||||||
end
|
|
||||||
lastMouse = {
|
|
||||||
x = evt[3],
|
|
||||||
y = evt[4],
|
|
||||||
scrollX = eldit.scrollX,
|
|
||||||
scrollY = eldit.scrollY,
|
|
||||||
lineNoLen = lineNoLen,
|
|
||||||
ctrl = keysDown[keys.leftCtrl],
|
|
||||||
curID = #eldit.cursors,
|
|
||||||
}
|
|
||||||
sortSelections()
|
|
||||||
adjustCursor(0, 0, true)
|
|
||||||
eldit.undoBuffer[eldit.undoPos].selections = eldit.selections
|
|
||||||
eldit.undoBuffer[eldit.undoPos].cursors = eldit.cursors
|
|
||||||
doRender = true
|
|
||||||
elseif evt[1] == "mouse_drag" then
|
|
||||||
local lineNoLen = getLineNoLen()
|
|
||||||
miceDown[evt[2]] = {x = evt[3], y = evt[4]}
|
|
||||||
if lastMouse.x and lastMouse.y and lastMouse.curID then
|
|
||||||
local adjMX, adjMY = lastMouse.x + lastMouse.scrollX, lastMouse.y + lastMouse.scrollY
|
|
||||||
local adjEX, adjEY = evt[3] + eldit.scrollX, evt[4] + eldit.scrollY
|
|
||||||
local selID
|
|
||||||
if (lastMouse.ctrl and not isSelecting) or #eldit.selections == 0 then
|
|
||||||
selID = 1 + #eldit.selections
|
|
||||||
else
|
else
|
||||||
selID = #eldit.selections
|
eldit.cursors = {{
|
||||||
|
x = evt[3] + eldit.scrollX - lineNoLen,
|
||||||
|
y = evt[4] + eldit.scrollY,
|
||||||
|
lastX = evt[3] + eldit.scrollX - lineNoLen
|
||||||
|
}}
|
||||||
|
eldit.selections = {}
|
||||||
end
|
end
|
||||||
eldit.selections[selID] = {
|
lastMouse = {
|
||||||
{
|
x = evt[3],
|
||||||
x = math.min(adjMX, #(eldit.buffer[adjMY] or "") + lineNoLen) - lineNoLen,
|
y = evt[4],
|
||||||
y = adjMY
|
scrollX = eldit.scrollX,
|
||||||
},
|
scrollY = eldit.scrollY,
|
||||||
{
|
lineNoLen = lineNoLen,
|
||||||
x = math.min(adjEX, #(eldit.buffer[adjEY] or "") + lineNoLen) - lineNoLen,
|
ctrl = keysDown[keys.leftCtrl],
|
||||||
y = adjEY
|
curID = #eldit.cursors,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sortSelections()
|
sortSelections()
|
||||||
eldit.cursors[lastMouse.curID] = {
|
adjustCursor(0, 0, true)
|
||||||
x = eldit.selections[selID][1].x,
|
|
||||||
y = eldit.selections[selID][1].y,
|
|
||||||
lastX = eldit.selections[selID][1].x
|
|
||||||
}
|
|
||||||
|
|
||||||
isSelecting = true
|
|
||||||
adjustCursor(0, 0)
|
|
||||||
eldit.undoBuffer[eldit.undoPos].selections = eldit.selections
|
eldit.undoBuffer[eldit.undoPos].selections = eldit.selections
|
||||||
eldit.undoBuffer[eldit.undoPos].cursors = eldit.cursors
|
eldit.undoBuffer[eldit.undoPos].cursors = eldit.cursors
|
||||||
|
end
|
||||||
|
doRender = true
|
||||||
|
elseif evt[1] == "mouse_drag" then
|
||||||
|
if evt[4] == -1 + eldit.size.y + eldit.size.height then
|
||||||
|
|
||||||
|
else
|
||||||
|
local lineNoLen = getLineNoLen()
|
||||||
|
local lastMX, lastMY
|
||||||
|
if miceDown[evt[2]] then
|
||||||
|
lastMX, lastMY = miceDown[evt[2]].x, miceDown[evt[2]].y
|
||||||
|
else
|
||||||
|
lastMX, lastMY = evt[3], evt[4]
|
||||||
|
end
|
||||||
|
miceDown[evt[2]] = {x = evt[3], y = evt[4]}
|
||||||
|
if lastMouse.x and lastMouse.y and lastMouse.curID then
|
||||||
|
local adjMY = lastMouse.y + lastMouse.scrollY
|
||||||
|
local adjMX = math.min(lastMouse.x + lastMouse.scrollX, #eldit.buffer[adjMY] + 1)
|
||||||
|
local adjEY = evt[4] + eldit.scrollY
|
||||||
|
local adjEX = math.min(evt[3] + eldit.scrollX, #eldit.buffer[adjEY] + 1)
|
||||||
|
local selID
|
||||||
|
local cSelID = checkIfSelected(adjMX, adjMY)
|
||||||
|
if (lastMouse.ctrl and not isSelecting) or #eldit.selections == 0 then
|
||||||
|
selID = cSelID or (1 + #eldit.selections)
|
||||||
|
else
|
||||||
|
selID = #eldit.selections
|
||||||
|
end
|
||||||
|
if cSelID and not (eldit.selections[cSelID][1].x == adjMX and eldit.selections[cSelID][1].y == adjMY) then
|
||||||
|
for id,cur in pairs(eldit.cursors) do
|
||||||
|
if cur.x == eldit.selections[cSelID][1].x and cur.y == eldit.selections[cSelID][1].y then
|
||||||
|
table.remove(eldit.cursors, id)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
eldit.selections[cSelID][1] = {
|
||||||
|
x = math.min(adjMX, #(eldit.buffer[adjMY] or "") + lineNoLen) - lineNoLen,
|
||||||
|
y = adjMY
|
||||||
|
}
|
||||||
|
end
|
||||||
|
eldit.selections[selID] = {
|
||||||
|
{
|
||||||
|
x = math.min(adjMX, #(eldit.buffer[adjMY] or "") + lineNoLen) - lineNoLen,
|
||||||
|
y = adjMY
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x = math.min(adjEX, #(eldit.buffer[adjEY] or "") + lineNoLen) - lineNoLen,
|
||||||
|
y = adjEY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sortSelections()
|
||||||
|
eldit.cursors[lastMouse.curID] = {
|
||||||
|
x = eldit.selections[selID][1].x,
|
||||||
|
y = eldit.selections[selID][1].y,
|
||||||
|
lastX = eldit.selections[selID][1].x
|
||||||
|
}
|
||||||
|
|
||||||
|
isSelecting = true
|
||||||
|
adjustCursor(0, 0)
|
||||||
|
eldit.undoBuffer[eldit.undoPos].selections = eldit.selections
|
||||||
|
eldit.undoBuffer[eldit.undoPos].cursors = eldit.cursors
|
||||||
|
end
|
||||||
doRender = true
|
doRender = true
|
||||||
end
|
end
|
||||||
elseif evt[1] == "mouse_up" then
|
elseif evt[1] == "mouse_up" then
|
||||||
|
|
Loading…
Reference in New Issue