Skip to content

Commit

Permalink
fix: num key not work, show shift label when alt/meta/ctrl on
Browse files Browse the repository at this point in the history
  • Loading branch information
tumuyan authored and Bambooin committed Aug 5, 2022
1 parent 57188bc commit 5b48bc2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/ime/keyboard/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public String getLabel() {
if (!AppPrefs.defaultInstance().getKeyboard().getHookShiftSymbol())
return adjustCase(shiftLabel);
}
} else if ((mKeyboard.getModifer() | mask & KeyEvent.META_SHIFT_ON) != 0) {
} else if (((mKeyboard.getModifer() | mask) & KeyEvent.META_SHIFT_ON) != 0) {
return adjustCase(shiftLabel);
}

Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -429,20 +429,23 @@ class TextInputManager private constructor() :
// 优先由librime处理按键事件
if (trime.handleKey(keyEventCode, metaState)) return

// 如果没有修饰键,或者只有shift修饰键,可以直接commit字符
val shiftState = metaState or KeyEvent.META_SHIFT_ON
if (shiftState == KeyEvent.META_SHIFT_ON || shiftState == 0) {
val text = Keycode.getDisplayLabel(keyEventCode, metaState)
if (text!!.length == 1) {
needSendUpRimeKey = false
needSendUpRimeKey = false

// 如果没有修饰键,或者只有shift修饰键,针对非Android标准按键,可以直接commit字符
if ((metaState == KeyEvent.META_SHIFT_ON || metaState == 0) && keyEventCode >= Keycode.A.ordinal) {
val text = Keycode.getSymbolLabell(Keycode.valueOf(keyEventCode))
if (text.length == 1) {
activeEditorInstance.commitText(text)
return
}
}

// 小键盘自动增加锁定
if (keyEventCode >= KeyEvent.KEYCODE_NUMPAD_0 && keyEventCode <= KeyEvent.KEYCODE_NUMPAD_EQUALS) {
activeEditorInstance.sendDownUpKeyEvent(keyEventCode, metaState or KeyEvent.META_NUM_LOCK_ON)
return
}
// 大写字母和部分符号转换为Shift+Android keyevent
val event = toStdKeyEvent(keyEventCode, metaState)
needSendUpRimeKey = false
activeEditorInstance.sendDownUpKeyEvent(event[0], event[1])
}

Expand Down

0 comments on commit 5b48bc2

Please sign in to comment.