Skip to content

Commit

Permalink
feature: text selection and shift state reset after Copy/Paste
Browse files Browse the repository at this point in the history
  • Loading branch information
if-can committed Jan 8, 2025
1 parent 3aaff87 commit 96e8288
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.osfans.trime.ime.broadcast.IntentReceiver
import com.osfans.trime.ime.composition.ComposingPopupWindow
import com.osfans.trime.ime.keyboard.InitializationUi
import com.osfans.trime.ime.keyboard.InputFeedbackManager
import com.osfans.trime.ime.keyboard.KeyboardSwitcher
import com.osfans.trime.util.findSectionFrom
import com.osfans.trime.util.forceShowSelf
import com.osfans.trime.util.isNightMode
Expand Down Expand Up @@ -250,12 +251,17 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
return
}

it.modifiers.shift.apply {
if (this) sendDownKeyEvent(eventTime, KeyEvent.KEYCODE_SHIFT_LEFT)
it.modifiers.apply {
if (this.shift) sendDownKeyEvent(eventTime, KeyEvent.KEYCODE_SHIFT_LEFT)

sendDownKeyEvent(eventTime, keyCode, it.modifiers.metaState)

if (this) sendUpKeyEvent(eventTime, KeyEvent.KEYCODE_SHIFT_LEFT)
if (this.shift) sendUpKeyEvent(eventTime, KeyEvent.KEYCODE_SHIFT_LEFT)

if (this.ctrl && (keyCode == KeyEvent.KEYCODE_C || keyCode == KeyEvent.KEYCODE_V)) {
cancelTextSelection()
KeyboardSwitcher.currentKeyboardView.setShifted(false, false)
}
}
}
} else {
Expand Down Expand Up @@ -918,6 +924,16 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
return false
}

fun cancelTextSelection() {
currentInputConnection?.getSelectedText(0)?.let {
val etr = ExtractedTextRequest().apply { token = 0 }
val et = currentInputConnection.getExtractedText(etr, 0)
et?.let {
currentInputConnection.setSelection(it.selectionEnd, it.selectionEnd)
}
}
}

private val composingTextMode by prefs.general.composingTextMode

private fun updateComposingText(ctx: RimeProto.Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ package com.osfans.trime.ime.keyboard
@Deprecated("Migrate into KeyboardWindow")
object KeyboardSwitcher {
lateinit var currentKeyboard: Keyboard
lateinit var currentKeyboardView: KeyboardView
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class KeyboardWindow(
currentKeyboardView ?: KeyboardView(context, theme, newKeyboard, keyPreviewChoreographer).also {
cachedKeyboards[target] = newKeyboard to it
}
KeyboardSwitcher.currentKeyboardView = newView
newView.let {
it.keyboardActionListener = keyboardActionListener
keyboardView.apply { add(it, lParams(matchParent, matchParent)) }
Expand Down

0 comments on commit 96e8288

Please sign in to comment.