mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
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.
This commit is contained in:
@@ -26,9 +26,21 @@ local wrapInputBox = function(inputbox)
|
||||
if inputbox._wrapped == nil then
|
||||
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)
|
||||
obj["_" .. name] = obj[name]
|
||||
table.insert(copied_names, name)
|
||||
end
|
||||
|
||||
-- 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, "onHoldTextBox")
|
||||
wrap_touch_event_func_with_hghelper_reset(inputbox, "onSwipeTextBox")
|
||||
|
||||
return function() -- return unwrap function
|
||||
restore_func_references(inputbox)
|
||||
inputbox._wrapped = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -666,6 +666,10 @@ local VirtualKeyboard = FocusManager:new{
|
||||
}
|
||||
|
||||
function VirtualKeyboard:init()
|
||||
if self.uwrap_func then
|
||||
self.uwrap_func()
|
||||
self.uwrap_func = nil
|
||||
end
|
||||
local lang = self:getKeyboardLayout()
|
||||
local keyboard_layout = self.lang_to_keyboard_layout[lang] or self.lang_to_keyboard_layout["en"]
|
||||
local keyboard = require("ui/data/keyboardlayouts/" .. keyboard_layout)
|
||||
@@ -685,7 +689,7 @@ function VirtualKeyboard:init()
|
||||
self.key_events.Close = { {"Back"}, doc = "close keyboard" }
|
||||
end
|
||||
if keyboard.wrapInputBox then
|
||||
keyboard.wrapInputBox(self.inputbox)
|
||||
self.uwrap_func = keyboard.wrapInputBox(self.inputbox) or self.uwrap_func
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user