Korean keyboard: unwrap InputText on layout change

The korean keyboard wraps InputText and overrides some
of its methods to process input in some specific way.
When switching to another keyboard layout, the original
methods need to be restored.
pull/5647/head
poire-z 5 years ago
parent 7b4b06f557
commit 13fa6d962c

@ -26,9 +26,21 @@ local wrapInputBox = function(inputbox)
if inputbox._wrapped == nil then if inputbox._wrapped == nil then
inputbox._wrapped = true inputbox._wrapped = true
-- helper function -- helper functions
local copied_names = {}
local function restore_func_references(obj)
for __, name in ipairs(copied_names) do
local orig_name = "_" .. name
if obj[orig_name] then
obj[name] = obj[orig_name]
obj[orig_name] = nil
end
end
end
local function copy_func_reference(obj, name) local function copy_func_reference(obj, name)
obj["_" .. name] = obj[name] obj["_" .. name] = obj[name]
table.insert(copied_names, name)
end end
-- override original implementations with helper object -- override original implementations with helper object
@ -82,6 +94,11 @@ local wrapInputBox = function(inputbox)
wrap_touch_event_func_with_hghelper_reset(inputbox, "onTapTextBox") wrap_touch_event_func_with_hghelper_reset(inputbox, "onTapTextBox")
wrap_touch_event_func_with_hghelper_reset(inputbox, "onHoldTextBox") wrap_touch_event_func_with_hghelper_reset(inputbox, "onHoldTextBox")
wrap_touch_event_func_with_hghelper_reset(inputbox, "onSwipeTextBox") wrap_touch_event_func_with_hghelper_reset(inputbox, "onSwipeTextBox")
return function() -- return unwrap function
restore_func_references(inputbox)
inputbox._wrapped = nil
end
end end
end end

@ -666,6 +666,10 @@ local VirtualKeyboard = FocusManager:new{
} }
function VirtualKeyboard:init() function VirtualKeyboard:init()
if self.uwrap_func then
self.uwrap_func()
self.uwrap_func = nil
end
local lang = self:getKeyboardLayout() local lang = self:getKeyboardLayout()
local keyboard_layout = self.lang_to_keyboard_layout[lang] or self.lang_to_keyboard_layout["en"] local keyboard_layout = self.lang_to_keyboard_layout[lang] or self.lang_to_keyboard_layout["en"]
local keyboard = require("ui/data/keyboardlayouts/" .. keyboard_layout) local keyboard = require("ui/data/keyboardlayouts/" .. keyboard_layout)
@ -685,7 +689,7 @@ function VirtualKeyboard:init()
self.key_events.Close = { {"Back"}, doc = "close keyboard" } self.key_events.Close = { {"Back"}, doc = "close keyboard" }
end end
if keyboard.wrapInputBox then if keyboard.wrapInputBox then
keyboard.wrapInputBox(self.inputbox) self.uwrap_func = keyboard.wrapInputBox(self.inputbox) or self.uwrap_func
end end
end end

Loading…
Cancel
Save