Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions code/Editor.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local lexLua = require "code.lexers.lexLua"
local clipboard = require "code.clipboard"
local Highlighter = require "code.Highlighter"

---@class Point
Expand Down Expand Up @@ -686,17 +687,29 @@ end

---TODO
function Editor:cut()
-- TODO
self:copy()
end

---TODO
function Editor:copy()
-- TODO
local selectedText = self:selectedText()
if selectedText then
clipboard.set(selectedText, false)
else
-- local x, y =
-- clipboard.set(self:(), true)
end
end

---TODO
function Editor:paste()
-- TODO
local text, fullLine = clipboard.get()
if fullLine then
local x, y = self:getCursor()
self:replaceLines(y, y - 1, text, x, y) -- TODO: Where to put cursor? Same x next line?
else
self:insert(text)
end
end

---TODO
Expand Down
23 changes: 23 additions & 0 deletions code/clipboard.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local clipboard = {}

local filename = ".code-clipboard"

---Returns the current content of the clipboard.
---@return string text, boolean fullLine
function clipboard.get()
local file = fs.open(filename, "rb")
local data = file.readAll()
file.close()
return data:sub(2), data:sub(1, 1) == "\1"
end

---Sets the content of the clipboard with the given values.
---@param text string
---@param fullLine boolean?
function clipboard.set(text, fullLine)
local file = fs.open(filename, "wb")
file.write((fullLine and "\1" or "\0") .. text)
file.close()
end

return clipboard
1 change: 1 addition & 0 deletions code/update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local githubPossseidon = "https://raw.githubusercontent.com/Possseidon/"
addRequests(githubPossseidon .. "cc-code/main", "", {
"code/highlighter/vscode.lua",
"code/class.lua",
"code/clipboard.lua",
"code/Code.lua",
"code/Editor.lua",
"code/Highlighter.lua",
Expand Down