From db48031c7c19fbaa9ba2fa210e14dc3cc1c922f1 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Wed, 13 Nov 2019 15:17:23 -0700 Subject: [PATCH] funnel all events through emit --- sys/modules/opus/entry.lua | 14 ++++++++------ sys/modules/opus/ui.lua | 27 ++++++++++----------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/sys/modules/opus/entry.lua b/sys/modules/opus/entry.lua index 7deb36f..aa2397f 100644 --- a/sys/modules/opus/entry.lua +++ b/sys/modules/opus/entry.lua @@ -62,13 +62,15 @@ function Entry:copyText(cx, ex) end function Entry:insertText(x, text) - text = tostring(self.transform(text)) or '' - local value = _val(self.value) - if #value + #text > self.limit then - text = text:sub(1, self.limit-#value) + text = tostring(self.transform(text) or '') + if #text > 0 then + local value = _val(self.value) + if #value + #text > self.limit then + text = text:sub(1, self.limit-#value) + end + self.value = self.transform(value:sub(1, x) .. text .. value:sub(x + 1)) + self.pos = self.pos + #text end - self.value = self.transform(value:sub(1, x) .. text .. value:sub(x + 1)) - self.pos = self.pos + #text end function Entry:deleteText(sx, ex) diff --git a/sys/modules/opus/ui.lua b/sys/modules/opus/ui.lua index 9e9a4c5..2ab507d 100644 --- a/sys/modules/opus/ui.lua +++ b/sys/modules/opus/ui.lua @@ -248,23 +248,8 @@ function Manager:emitEvent(event) end end -function Manager:inputEvent(parent, event) - while parent do - if parent.accelerators then - local acc = parent.accelerators[event.key] - if acc then - if parent:emit({ type = acc, element = parent }) then - return true - end - end - end - if parent.eventHandler then - if parent:eventHandler(event) then - return true - end - end - parent = parent.parent - end +function Manager:inputEvent(parent, event) -- deprecate ? + return parent and parent:emit(event) end function Manager:click(target, code, button, x, y) @@ -927,6 +912,14 @@ end function UI.Window:emit(event) local parent = self while parent do + if parent.accelerators and event.key then -- not ideal + -- could be [event.key or event.type] to support accelerators + -- for non-input type events + local acc = parent.accelerators[event.key] + if acc and parent:emit({ type = acc, element = parent }) then + return true + end + end if parent.eventHandler then if parent:eventHandler(event) then return true