mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
text widget: try to determine whether keypresses are related to text input, fix #40
This commit is contained in:
@@ -269,9 +269,6 @@ local function createDefaultKeyActions (self)
|
|||||||
return {
|
return {
|
||||||
-- let tab press propagate
|
-- let tab press propagate
|
||||||
['tab'] = function () return true end,
|
['tab'] = function () return true end,
|
||||||
-- dummy functions to trap events
|
|
||||||
['return'] = function () end,
|
|
||||||
['space'] = function () end,
|
|
||||||
['backspace'] = function ()
|
['backspace'] = function ()
|
||||||
if not deleteRange(self) then
|
if not deleteRange(self) then
|
||||||
deleteCharacterLeft(self)
|
deleteCharacterLeft(self)
|
||||||
@@ -330,6 +327,24 @@ local function createDefaultKeyActions (self)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local textInputKeys = {
|
||||||
|
['space'] = true,
|
||||||
|
['return'] = true,
|
||||||
|
['kp00'] = true,
|
||||||
|
['kp000'] = true,
|
||||||
|
['kp&&'] = true,
|
||||||
|
['kp||'] = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function isKeyTextInput (key)
|
||||||
|
if textInputKeys[key] or #key == 1
|
||||||
|
or (#key == 3 and key:sub(1, 2) == "kp") then
|
||||||
|
return not Backend.isKeyDown(
|
||||||
|
'lalt', 'ralt', 'lctrl', 'rctrl', 'lgui', 'rgui')
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
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
|
||||||
@@ -378,11 +393,12 @@ This color is used to indicate the selected range of text.
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
self:onKeyPress(function (event)
|
self:onKeyPress(function (event)
|
||||||
local act = self.keyActions[event.key]
|
local key = event.key
|
||||||
|
local act = self.keyActions[key]
|
||||||
if act then
|
if act then
|
||||||
if act() then return end
|
if act() then return end
|
||||||
end
|
end
|
||||||
return false
|
return isKeyTextInput(key) or nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
self:onDisplay(function (event)
|
self:onDisplay(function (event)
|
||||||
|
|||||||
Reference in New Issue
Block a user