From 9d1db0343f0b10adfee91d5e38308ea530e35f29 Mon Sep 17 00:00:00 2001 From: Robert Burke Date: Tue, 3 Dec 2013 13:56:33 -0800 Subject: [PATCH 1/2] Add ctrl+x to cut in textinput Use cmd to do ctrl-ish things on macs --- objects/columnlist.lua | 2 +- objects/internal/columnlist/columnlistrow.lua | 2 +- objects/textinput.lua | 17 +++++++++++------ util.lua | 13 +++++++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/objects/columnlist.lua b/objects/columnlist.lua index 3e7a55e..e27e250 100644 --- a/objects/columnlist.lua +++ b/objects/columnlist.lua @@ -514,7 +514,7 @@ function newobject:SelectRow(row, ctrl) end end elseif v ~= row then - if (not multiselect and ctrl) or (not multiselect and not ctrl) or (multiselect and not ctrl) then + if not (multiselect and ctrl) then v.selected = false end end diff --git a/objects/internal/columnlist/columnlistrow.lua b/objects/internal/columnlist/columnlistrow.lua index 52471a1..17b180e 100644 --- a/objects/internal/columnlist/columnlistrow.lua +++ b/objects/internal/columnlist/columnlistrow.lua @@ -118,7 +118,7 @@ function newobject:mousepressed(x, y, button) end local parent1 = self:GetParent() local parent2 = parent1:GetParent() - local ctrldown = love.keyboard.isDown("lctrl") + local ctrldown = loveframes.util.IsCtrlDown() parent2:SelectRow(self, ctrldown) end diff --git a/objects/textinput.lua b/objects/textinput.lua index bba4d40..e145553 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -135,10 +135,8 @@ function newobject:update(dt) -- keydown check if keydown ~= "none" then - local lctrl = love.keyboard.isDown("lctrl") - local rctrl = love.keyboard.isDown("rctrl") if time > delay then - if (lctrl or rctrl) and keydown == "v" then + if (loveframes.util.IsCtrlDown()) and keydown == "v" then self:Paste() else self:RunKey(keydown, unicode, true) @@ -475,8 +473,6 @@ function newobject:keypressed(key, unicode) end local time = love.timer.getTime() - local lctrl = love.keyboard.isDown("lctrl") - local rctrl = love.keyboard.isDown("rctrl") local focus = self.focus local repeatdelay = self.repeatdelay local alltextselected = self.alltextselected @@ -486,7 +482,7 @@ function newobject:keypressed(key, unicode) self.delay = time + repeatdelay self.keydown = key - if (lctrl or rctrl) and focus then + if (loveframes.util.IsCtrlDown()) and focus then if key == "a" then self.alltextselected = true elseif key == "c" and alltextselected and version == "0.9.0" then @@ -496,6 +492,15 @@ function newobject:keypressed(key, unicode) if oncopy then oncopy(self, text) end + elseif key == "x" and alltextselected and version == "0.9.0" then + local text = self:GetText() + local oncut = self.OnCut + love.system.setClipboardText(text) + if oncut then + oncut(self, text) + else + self:SetText("") + end elseif key == "v" and version == "0.9.0" and editable then self:Paste() end diff --git a/util.lua b/util.lua index 62f497a..fde2229 100644 --- a/util.lua +++ b/util.lua @@ -360,4 +360,17 @@ function loveframes.util.GetHoverObject() return loveframes.hoverobject +end + +--[[--------------------------------------------------------- + - func: loveframes.util.IsCtrlDown() + - desc: checks for ctrl, for use with multiselect, copy, + paste, and such. On OS X it actually looks for cmd. +--]]--------------------------------------------------------- +function loveframes.util.IsCtrlDown() + if love._os == "OS X" then + return love.keyboard.isDown("lmeta") or love.keyboard.isDown("rmeta") or + love.keyboard.isDown("lgui") or love.keyboard.isDown("rgui") + end + return love.keyboard.isDown("lctrl") or love.keyboard.isDown("rctrl") end \ No newline at end of file From 9b556f4c519ae2cd8f81cec0dd84993ac5bc1def Mon Sep 17 00:00:00 2001 From: Robert Burke Date: Tue, 3 Dec 2013 14:16:26 -0800 Subject: [PATCH 2/2] Cutting uneditable text is not allowed --- objects/textinput.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objects/textinput.lua b/objects/textinput.lua index e145553..aa41f45 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -492,7 +492,7 @@ function newobject:keypressed(key, unicode) if oncopy then oncopy(self, text) end - elseif key == "x" and alltextselected and version == "0.9.0" then + elseif key == "x" and alltextselected and version == "0.9.0" and editable then local text = self:GetText() local oncut = self.OnCut love.system.setClipboardText(text)