diff --git a/Applications/MineCode IDE.app/Main.lua b/Applications/MineCode IDE.app/Main.lua index 76f02855..22332be0 100755 --- a/Applications/MineCode IDE.app/Main.lua +++ b/Applications/MineCode IDE.app/Main.lua @@ -77,7 +77,7 @@ local currentScriptDirectory = filesystem.path(system.getCurrentScript()) local configPath = paths.user.applicationData .. "MineCode IDE/Config9.cfg" local localization = system.getLocalization(currentScriptDirectory .. "Localizations/") local findStartFrom -local clipboard +local clipboard = require('Clipboard') local breakpointLines local lastErrorLine local autocompleteDatabase @@ -974,13 +974,13 @@ end local function copy() if codeView.selections[1] then if codeView.selections[1].to.line == codeView.selections[1].from.line then - clipboard = { unicode.sub(lines[codeView.selections[1].from.line], codeView.selections[1].from.symbol, codeView.selections[1].to.symbol) } + clipboard.copy({ unicode.sub(lines[codeView.selections[1].from.line], codeView.selections[1].from.symbol, codeView.selections[1].to.symbol) }) else - clipboard = { unicode.sub(lines[codeView.selections[1].from.line], codeView.selections[1].from.symbol, -1) } + clipboard.copy({ unicode.sub(lines[codeView.selections[1].from.line], codeView.selections[1].from.symbol, -1) }) for line = codeView.selections[1].from.line + 1, codeView.selections[1].to.line - 1 do - table.insert(clipboard, lines[line]) + table.insert(clipboard.history[1], lines[line]) end - table.insert(clipboard, unicode.sub(lines[codeView.selections[1].to.line], 1, codeView.selections[1].to.symbol)) + table.insert(clipboard.history[1], unicode.sub(lines[codeView.selections[1].to.line], 1, codeView.selections[1].to.symbol)) end end end @@ -1320,8 +1320,8 @@ local function createEditOrRightClickMenu(menu) copy() end - menu:addItem("⇲", localization.paste, not clipboard, "^V").onTouch = function() - paste(clipboard) + menu:addItem("⇲", localization.paste, not clipboard.history[1], "^V").onTouch = function() + paste(clipboard.paste()) end menu:addSeparator() @@ -1453,8 +1453,8 @@ codeView.eventHandler = function(workspace, object, e1, e2, e3, e4, e5) copy() end -- V - elseif e4 == 47 and clipboard then - paste(clipboard) + elseif e4 == 47 and clipboard.paste() then + paste(clipboard.paste()) -- X elseif e4 == 45 then if codeView.selections[1] then diff --git a/Libraries/Clipboard.lua b/Libraries/Clipboard.lua new file mode 100644 index 00000000..cc890144 --- /dev/null +++ b/Libraries/Clipboard.lua @@ -0,0 +1,22 @@ +local Clipboard = { + maxHistory = 2, + history = {} +} + +function Clipboard.copy(content) + table.insert(Clipboard.history,1,content) + while #Clipboard.history > Clipboard.maxHistory do + table.remove(Clipboard.history, Clipboard.maxHistory + 1) + end +end + +function Clipboard.paste() + return Clipboard.history[1] +end + +function Clipboard.clear() + Clipboard.history = {} + return true +end + +return Clipboard diff --git a/Libraries/GUI.lua b/Libraries/GUI.lua index a569e2cf..5793c2ee 100755 --- a/Libraries/GUI.lua +++ b/Libraries/GUI.lua @@ -7,6 +7,7 @@ local screen = require("Screen") local paths = require("Paths") local text = require("Text") local number = require("Number") +local clipboard = require("Clipboard") ----------------------------------------------------------------------------------------- @@ -3061,7 +3062,13 @@ local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6, ...) -- End elseif e4 == 207 then input:setCursorPosition(unicode.len(input.text) + 1) - + + -- V + elseif e4 == 47 and type(clipboard.paste()) ~= "table" and clipboard.paste() ~= nil then + local startPos = input.cursorPosition + local toPaste = tostring(clipboard.paste()) + input.text = unicode.sub(input.text, 1,startPos) .. toPaste .. unicode.sub(input.text, startPos, unicode.len(input.text)) + input:setCursorPosition(startPos + unicode.len(toPaste)+1) else local char = unicode.char(e3)