mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
command and ctrl
This commit is contained in:
@@ -42,6 +42,10 @@ local Backend = {}
|
|||||||
|
|
||||||
Backend.sdl = sdl
|
Backend.sdl = sdl
|
||||||
|
|
||||||
|
Backend.isMac = function ()
|
||||||
|
return sdl.getPlatform() == 'Mac OS X'
|
||||||
|
end
|
||||||
|
|
||||||
local callback = {
|
local callback = {
|
||||||
draw = function () end,
|
draw = function () end,
|
||||||
resize = function () end,
|
resize = function () end,
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ local Hooker = require(ROOT .. 'hooker')
|
|||||||
|
|
||||||
local Backend = {}
|
local Backend = {}
|
||||||
|
|
||||||
|
Backend.isMac = function ()
|
||||||
|
return love.system.getOS() == 'OS X'
|
||||||
|
end
|
||||||
|
|
||||||
Backend.run = function () end
|
Backend.run = function () end
|
||||||
|
|
||||||
Backend.Cursor = love.mouse.newCursor
|
Backend.Cursor = love.mouse.newCursor
|
||||||
|
|||||||
@@ -207,6 +207,22 @@ local function insertText (self, newText)
|
|||||||
selectRange(self, index, index)
|
selectRange(self, index, index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function isShiftPressed ()
|
||||||
|
return Backend.isKeyDown('lshift', 'rshift')
|
||||||
|
end
|
||||||
|
|
||||||
|
-- "command" means the command key on Mac and the ctrl key everywhere else.
|
||||||
|
local isCommandPressed
|
||||||
|
if Backend.isMac() then
|
||||||
|
isCommandPressed = function ()
|
||||||
|
return Backend.isKeyDown('lgui', 'rgui')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
isCommandPressed = function ()
|
||||||
|
return Backend.isKeyDown('lctrl', 'rctrl')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
self.startIndex, self.endIndex = 0, 0
|
self.startIndex, self.endIndex = 0, 0
|
||||||
self.startX, self.endX = -1, -1
|
self.startX, self.endX = -1, -1
|
||||||
@@ -283,41 +299,41 @@ This color is used to indicate the selected range of text.
|
|||||||
elseif event.key == 'left' then
|
elseif event.key == 'left' then
|
||||||
|
|
||||||
if Backend.isKeyDown('lgui', 'rgui') then
|
if Backend.isKeyDown('lgui', 'rgui') then
|
||||||
jumpCaretLeft(self, Backend.isKeyDown('lshift', 'rshift'))
|
jumpCaretLeft(self, isShiftPressed())
|
||||||
else
|
else
|
||||||
moveCaretLeft(self, Backend.isKeyDown('lshift', 'rshift'))
|
moveCaretLeft(self, isShiftPressed())
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.key == 'right' then
|
elseif event.key == 'right' then
|
||||||
|
|
||||||
if Backend.isKeyDown('lgui', 'rgui') then
|
if Backend.isKeyDown('lgui', 'rgui') then
|
||||||
jumpCaretRight(self, Backend.isKeyDown('lshift', 'rshift'))
|
jumpCaretRight(self, isShiftPressed())
|
||||||
else
|
else
|
||||||
moveCaretRight(self, Backend.isKeyDown('lshift', 'rshift'))
|
moveCaretRight(self, isShiftPressed())
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.key == 'home' then
|
elseif event.key == 'home' then
|
||||||
|
|
||||||
jumpCaretLeft(self, Backend.isKeyDown('lshift', 'rshift'))
|
jumpCaretLeft(self, isShiftPressed())
|
||||||
|
|
||||||
elseif event.key == 'end' then
|
elseif event.key == 'end' then
|
||||||
|
|
||||||
jumpCaretRight(self, Backend.isKeyDown('lshift', 'rshift'))
|
jumpCaretRight(self, isShiftPressed())
|
||||||
|
|
||||||
elseif event.key == 'x' and Backend.isKeyDown('lctrl', 'rctrl', 'lgui', 'rgui') then
|
elseif event.key == 'x' and isCommandPressed() then
|
||||||
|
|
||||||
copyRangeToClipboard(self)
|
copyRangeToClipboard(self)
|
||||||
deleteRange(self)
|
deleteRange(self)
|
||||||
|
|
||||||
elseif event.key == 'c' and Backend.isKeyDown('lctrl', 'rctrl', 'lgui', 'rgui') then
|
elseif event.key == 'c' and isCommandPressed() then
|
||||||
|
|
||||||
copyRangeToClipboard(self)
|
copyRangeToClipboard(self)
|
||||||
|
|
||||||
elseif event.key == 'v' and Backend.isKeyDown('lctrl', 'rctrl', 'lgui', 'rgui') then
|
elseif event.key == 'v' and isCommandPressed() then
|
||||||
|
|
||||||
pasteFromClipboard(self)
|
pasteFromClipboard(self)
|
||||||
|
|
||||||
elseif event.key == 'a' and Backend.isKeyDown('lctrl', 'rctrl', 'lgui', 'rgui') then
|
elseif event.key == 'a' and isCommandPressed() then
|
||||||
|
|
||||||
selectRange(self, 0, #self.value)
|
selectRange(self, 0, #self.value)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user