2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/frontend/ui/data/keyboardlayouts/ko_KR_keyboard.lua
poire-z 13fa6d962c 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.
2019-11-26 21:14:06 +01:00

187 lines
6.3 KiB
Lua

local logger = require("logger")
--------
-- # Korean 2-beolsik Keyboard layout
--------
local HgHelper = require("ui/data/keyboardlayouts/ko_KR_helper")
--------
-- UI handler implementation for communicating with text input box widget
--------
function HgHelper.UIHandler:put_char(char)
HgHelper.UIHandler.inputbox:_addChars(char)
end
function HgHelper.UIHandler:del_char(char)
HgHelper.UIHandler.inputbox:_delChar()
end
HgHelper.HgFSM:init(HgHelper.UIHandler)
--------
-- Custom key event handlers with Hangul support
--------
local wrapInputBox = function(inputbox)
HgHelper.HgFSM.clean_state() -- reset helper
if inputbox._wrapped == nil then
inputbox._wrapped = true
-- 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
copy_func_reference(inputbox, "addChars")
copy_func_reference(inputbox, "delChar")
function inputbox:addChars(key)
logger.dbg("ko_KR_kbd:addChar(", key, ")")
HgHelper.UIHandler.inputbox = self
HgHelper.HgFSM:process_char(key)
end
function inputbox:delChar()
logger.dbg("ko_KR_kbd:delChar()")
HgHelper.UIHandler.inputbox = self
HgHelper.HgFSM:process_bsp()
end
-- override implementations: reset helper if we have to stop combining current syllable
---- helper function
local function wrap_func_with_hghelper_reset(obj, name)
copy_func_reference(obj, name)
obj[name] = function(self)
HgHelper.HgFSM.clean_state()
self["_" .. name](self)
end
end
---- delete text
wrap_func_with_hghelper_reset(inputbox, "delToStartOfLine")
wrap_func_with_hghelper_reset(inputbox, "clear")
---- move cursor
wrap_func_with_hghelper_reset(inputbox, "leftChar")
wrap_func_with_hghelper_reset(inputbox, "rightChar")
wrap_func_with_hghelper_reset(inputbox, "upLine")
wrap_func_with_hghelper_reset(inputbox, "downLine")
---- unfocus: move to other inputbox
wrap_func_with_hghelper_reset(inputbox, "unfocus")
---- tap/hold/swipe: move cursor
------ helper function
local function wrap_touch_event_func_with_hghelper_reset(obj, name)
copy_func_reference(obj, name)
obj[name] = function(self, arg, ges)
HgHelper.HgFSM.clean_state()
return self["_" .. name](self, arg, ges)
end
end
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
-- Belows are just same as the English keyboard popup
local en_popup = require("ui/data/keyboardlayouts/keypopup/en_popup")
local com = en_popup.com -- comma (,)
local prd = en_popup.prd -- period (.)
local _at = en_popup._at
local _eq = en_popup._eq -- equals sign (=)
return {
min_layer = 1,
max_layer = 4,
shiftmode_keys = {[""] = true},
symbolmode_keys = {["Sym"] = true, ["ABC"] = true},
utf8mode_keys = {["🌐"] = true},
umlautmode_keys = {["Äéß"] = false}, -- Disabled 'umlaut' keys
keys = {
-- [shift, unshift, symbol-shift, symbol-unshift]
-- first row
{ -- 1 2 3 4
{ "", "", "", "0", },
{ "", "", "!", "1", },
{ "", "", _at, "2", },
{ "", "", "#", "3", },
{ "", "", "+", _eq, },
{ "", "", "", "(", },
{ "", "", "", ")", },
{ "", "", "", "\\", },
{ "", "", "", "/", },
{ "", "", "", "`", },
},
-- second row
{ -- 1 2 3 4
{ "", "", "", "@", },
{ "", "", "$", "4", },
{ "", "", "%", "5", },
{ "", "", "^", "6", },
{ "", "", ":", "'", },
{ "", "", "", "\"", },
{ "", "", "", "[", },
{ "", "", "", "]", },
{ "", "", "", "-", },
},
-- third row
{ -- 1 2 3 4
{ label = "",
width = 1.5
},
{ "", "", "", "7", },
{ "", "", "", "8", },
{ "", "", "*", "9", },
{ "", "", "", com, },
{ "", "", "&", prd, },
{ "", "", "", "", },
{ "", "", "", "", },
{ label = "",
width = 1.5,
bold = false
},
},
-- fourth row
{
{ "Sym", "Sym", "ABC", "ABC",
width = 1.5},
{ label = "🌐",
width = 2,
},
-- { "Äéß", "Äéß", "Äéß", "Äéß",},
{ label = "간격",
" ", " ", " ", " ",
width = 3.0},
{ com, com, "", "", },
{ prd, prd, "", "", },
{ label = "",
"\n", "\n", "\n", "\n",
width = 1.5,
bold = true
},
},
},
-- wrap InputBox for hooking events to the helper
wrapInputBox = wrapInputBox,
}