Repository navigation
fix(segments): stop a failing word segment window from killing the IME - #2234
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by one critical token-offset bug and three additional retry, crash-recovery, and whitespace-preservation issues that remain unresolved.
4 open issues
What changed in this PR
This PR hardens the clipboard word-segmentation window so tokenizer or window-attachment failures no longer terminate the IME, while moving tokenization off the UI thread and reducing redundant composing-preview updates.
Changes:
- Adds ICU boundary validation and whitespace fallback tokenization.
- Makes window creation and attachment recoverable, restoring the keyboard after failures.
- Adds asynchronous tokenization, debounced previews, and broader whitespace handling.
| File | Description |
|---|---|
| app/src/main/java/com/osfans/trime/util/NativeTokenizer.kt | Adds ICU boundary validation, failure handling, and fallback segmentation. |
| app/src/main/java/com/osfans/trime/ime/window/BoardWindowManager.kt | Makes window creation and attachment recoverable with keyboard restoration after failures. |
| app/src/main/java/com/osfans/trime/ime/segments/SegmentsWindow.kt | Moves tokenization off the main thread and debounces composing-preview updates. |
| app/src/main/java/com/osfans/trime/ime/segments/SegmentsAdapter.kt | Uses Unicode-aware whitespace detection for segment separators. |
Review effort: Lite
The segment window ran the ICU word break iterator and let anything it threw escape into the window manager, which was in the middle of a switch. A vendor ICU build that fails while walking a text, or a window whose attach throws, ended the process there; Android does not restart an input method after that, so the keyboard simply disappeared. Tokenization now checks that ICU reported a boundary inside the text and falls back to splitting on whitespace, so the window still offers something to select. The window manager treats a failing attach as a failed switch: it removes the half inserted view and puts the keyboard back.
Building the segments ran on the main thread while the window was being attached, and every selection change wrote the joined text straight into the target app's InputConnection. Dragging across a long clip produced one round trip per touch move, on apps whose InputConnection is fragile to begin with. Tokenization now runs on a worker thread and is dropped if the window is gone by the time it finishes. The preview is debounced by 150 ms and skipped when the joined text did not change. Whitespace between segments is matched by character class instead of four explicit characters, which broke the separators for the rest.
WhiredPlanck
force-pushed
the
segment-crash-fix
branch
from
November 16, 2026 15:43
4ca6fb8 to
fb1a1c9
Compare
Bambooin
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Pull request
Issue tracker
Fixes #2230
Feature
Problem. Using the clipboard word segment window makes the keyboard disappear on some apps (Firefox web search, MT Manager) and some ROMs (reported on realme/ColorOS). The keyboard does not come back until the IME is selected again.
Mechanism.
SegmentsWindow.onAttached()ran the ICU word break iterator synchronously, unprotected, whileBoardWindowManager.attachWindow()was in the middle of a switch. Anything the tokenizer threw — or anything a window'sonCreateView()/onAttached()threw — escaped to the main thread, where the release build's uncaught handler exits the process. Android does not restart an input method after that, so the user sees the keyboard vanish rather than a crash dialog. The same failure also left the window manager pointing at a window whose view had never been added, so even a caught failure would have meant an empty input area.What changed (4 files, +124/−26):
app/src/main/java/com/osfans/trime/util/NativeTokenizer.ktapp/src/main/java/com/osfans/trime/ime/window/BoardWindowManager.ktonCreateView()leaves the current window in place, a failingonAttached()removes the half-inserted view and puts the keyboard back.currentWindow/currentVieware assigned beforeonAttached()runs.app/src/main/java/com/osfans/trime/ime/segments/SegmentsWindow.ktInputConnectionround trip per touch move while dragging.app/src/main/java/com/osfans/trime/ime/segments/SegmentsAdapter.ktChar.isWhitespace()instead of four explicit characters.This does not fix the vendor ICU bug itself — that is not reproducible off the affected ROMs, and the log in #2230 is an ordinary
logcatsnapshot without a stack. What it does is turn a process death into a degraded but usable state: a failed tokenize still shows whitespace-split segments, and a failed window attach returns to the keyboard.Code of conduct
Code style
make style-lintBuild pass
make debugManually test
Code Review
Daily build
Login and download artifact at https://github.com/osfans/trime/actions
Additional Info
Verified on an API 35 x86_64 emulator with the debug package:
Failed to tokenize N characters, splitting on whitespace, and the process keeps its PID.onAttached()failure:Failed to attach …SegmentsWindowis followed immediately byAttach …KeyboardWindow, the keyboard comes back, and the PID is unchanged.Notes:
onTrimMemory-style retry is not involved: a window that fails to attach is retried on the next user action, not automatically.SegmentsAdapterchange is a correctness fix found while reading the surrounding code; it does not affect the crash.