mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
text widget: handle "delete" key
This commit is contained in:
@@ -146,6 +146,24 @@ local function deleteCharacterLeft (self)
|
|||||||
selectRange(self, index, index)
|
selectRange(self, index, index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function deleteCharacterRight (self)
|
||||||
|
trimRange(self)
|
||||||
|
local text = self.value
|
||||||
|
local first, last = getRange(self)
|
||||||
|
|
||||||
|
-- if cursor is at end, do nothing
|
||||||
|
if first == #text then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- delete character to the right
|
||||||
|
local offset = utf8.offset(text, 2, last + 1) or 0
|
||||||
|
local left = text:sub(1, first)
|
||||||
|
local index = #left
|
||||||
|
self.value = left .. text:sub(offset)
|
||||||
|
selectRange(self, index, index)
|
||||||
|
end
|
||||||
|
|
||||||
local function copyRangeToClipboard (self)
|
local function copyRangeToClipboard (self)
|
||||||
trimRange(self)
|
trimRange(self)
|
||||||
local text = self.value
|
local text = self.value
|
||||||
@@ -226,23 +244,29 @@ This color is used to indicate the selected range of text.
|
|||||||
|
|
||||||
-- ignore tabs (keyboard navigation)
|
-- ignore tabs (keyboard navigation)
|
||||||
if event.key == 'tab' then
|
if event.key == 'tab' then
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
|
||||||
|
|
||||||
-- focus next widget on enter (keyboard navigation)
|
-- focus next widget on enter (keyboard navigation)
|
||||||
if event.key == 'return' then
|
elseif event.key == 'return' then
|
||||||
|
|
||||||
self.layout:focusNextWidget()
|
self.layout:focusNextWidget()
|
||||||
-- if the next widget is a button, allow the event to propagate
|
-- if the next widget is a button, allow the event to propagate
|
||||||
-- so that the button is pressed (TODO: is this a good idea?)
|
-- so that the button is pressed (TODO: is this a good idea?)
|
||||||
return self.layout.focusedWidget.type ~= 'button' or nil
|
return self.layout.focusedWidget.type ~= 'button' or nil
|
||||||
end
|
|
||||||
|
|
||||||
if event.key == 'backspace' then
|
elseif event.key == 'backspace' then
|
||||||
|
|
||||||
if not deleteRange(self) then
|
if not deleteRange(self) then
|
||||||
deleteCharacterLeft(self)
|
deleteCharacterLeft(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif event.key == 'delete' then
|
||||||
|
|
||||||
|
if not deleteRange(self) then
|
||||||
|
deleteCharacterRight(self)
|
||||||
|
end
|
||||||
|
|
||||||
elseif event.key == 'left' then
|
elseif event.key == 'left' then
|
||||||
|
|
||||||
moveCaretLeft(self, Backend.isKeyDown('lshift', 'rshift'))
|
moveCaretLeft(self, Backend.isKeyDown('lshift', 'rshift'))
|
||||||
|
|||||||
Reference in New Issue
Block a user