Skip to content

Commit 7972858

Browse files
author
if-can
committed
feat: add switch to not reset shift state for arrow keys
1 parent 19203e3 commit 7972858

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

app/src/main/java/com/osfans/trime/data/prefs/AppPrefs.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class AppPrefs(
123123
const val HOOK_SHIFT_SPACE = "keyboard__hook_shift_space"
124124
const val HOOK_SHIFT_NUM = "keyboard__hook_shift_num"
125125
const val HOOK_SHIFT_SYMBOL = "keyboard__hook_shift_symbol"
126+
const val HOOK_SHIFT_ARROW = "keyboard__hook_shift_arrow"
126127

127128
const val SOUND_ENABLED = "keyboard__key_sound"
128129
const val SOUND_VOLUME = "keyboard__key_sound_volume"
@@ -165,6 +166,7 @@ class AppPrefs(
165166
val hookShiftSpace by bool(HOOK_SHIFT_SPACE, false)
166167
val hookShiftNum by bool(HOOK_SHIFT_NUM, false)
167168
val hookShiftSymbol by bool(HOOK_SHIFT_SYMBOL, false)
169+
val hookShiftArrow by bool(HOOK_SHIFT_ARROW, true)
168170

169171
val soundEnabled by bool(SOUND_ENABLED, false)
170172
var customSoundEnabled by bool(CUSTOM_SOUND_ENABLED, false)

app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import android.graphics.drawable.StateListDrawable
1919
import android.os.SystemClock
2020
import android.view.GestureDetector
2121
import android.view.GestureDetector.SimpleOnGestureListener
22+
import android.view.KeyEvent
2223
import android.view.MotionEvent
2324
import android.view.View
2425
import androidx.lifecycle.findViewTreeLifecycleOwner
@@ -681,6 +682,18 @@ class KeyboardView(
681682
}
682683
}
683684

685+
private val hookShiftArrow get() = AppPrefs.defaultInstance().keyboard.hookShiftArrow
686+
687+
fun isHookShiftArrow(keyCode: Int): Boolean {
688+
if (!hookShiftArrow) return false
689+
690+
return when (keyCode) {
691+
in KeyEvent.KEYCODE_DPAD_UP..KeyEvent.KEYCODE_DPAD_RIGHT -> true
692+
KeyEvent.KEYCODE_MOVE_HOME, KeyEvent.KEYCODE_MOVE_END -> true
693+
else -> false
694+
}
695+
}
696+
684697
private fun detectAndSendKey(
685698
index: Int,
686699
x: Int,
@@ -707,7 +720,9 @@ class KeyboardView(
707720
key.getAction(behavior)?.let { keyboardActionListener?.onAction(it) }
708721
releaseKey(code)
709722
Timber.d("detectAndSendKey: refreshModifier")
710-
refreshModifier()
723+
if (!isHookShiftArrow(code)) {
724+
refreshModifier()
725+
}
711726
}
712727
mLastSentIndex = index
713728
mLastTapTime = eventTime
@@ -802,7 +817,9 @@ class KeyboardView(
802817
mAbortKey = true
803818
keyboardActionListener?.onAction(it)
804819
releaseKey(it.code)
805-
refreshModifier()
820+
if (!isHookShiftArrow(it.code)) {
821+
refreshModifier()
822+
}
806823
return true
807824
}
808825
Timber.w("only set isShifted, no others modifierkey")

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
136136
<string name="keyboard__hook_shift_space">点击空格时,忽略Shift的锁定状态</string>
137137
<string name="keyboard__hook_shift_num">点击0-9时,忽略Shift的锁定状态</string>
138138
<string name="keyboard__hook_shift_symbol">点击符号键时,忽略Shift的锁定状态</string>
139+
<string name="keyboard__hook_shift_arrow">点击方向键时,不重置Shift的锁定状态</string>
139140
<string name="toolkit">工具箱</string>
140141
<string name="export">导出</string>
141142
<string name="scroll_to_bottom">跳到最后</string>

app/src/main/res/values-zh-rTW/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
139139
<string name="keyboard__hook_shift_space">點擊空格時,忽略Shift的鎖定狀態</string>
140140
<string name="keyboard__hook_shift_num">點擊0-9時,忽略Shift的鎖定狀態</string>
141141
<string name="keyboard__hook_shift_symbol">點擊符號鍵時,忽略Shift的鎖定狀態</string>
142+
<string name="keyboard__hook_shift_arrow">點選方向鍵時,不重置Shift的鎖定狀態</string>
142143
<string name="export">匯出</string>
143144
<string name="scroll_to_bottom">跳到最後</string>
144145
<string name="app_crash_message">抱歉,但我們為您帶來了一些紀錄檔以供調查。</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
141141
<string name="keyboard__hook_shift_space">Ignore Shift locked for Space</string>
142142
<string name="keyboard__hook_shift_num">Ignore Shift locked for 0-9</string>
143143
<string name="keyboard__hook_shift_symbol">Ignore Shift locked for Symbol keys</string>
144+
<string name="keyboard__hook_shift_arrow">Not reset Shift state for arrow keys</string>
144145
<string name="exception_logcat_created">Logcat process is already created</string>
145146
<string name="app_crash">Application crashed</string>
146147
<string name="app_crash_message">Sorry, but we bring you some logs to investigate.</string>

app/src/main/res/xml/keyboard_preference.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
122122
android:title="@string/keyboard__hook_shift_symbol"
123123
app:iconSpaceReserved="false" />
124124

125+
<SwitchPreferenceCompat
126+
android:key="keyboard__hook_shift_arrow"
127+
android:title="@string/keyboard__hook_shift_arrow"
128+
android:defaultValue="true"
129+
app:iconSpaceReserved="false" />
125130
</PreferenceCategory>
126131

127132
<PreferenceCategory

0 commit comments

Comments
 (0)