Skip to content

fix(input): segment Thai composing text by word boundaries#290

Open
Scott-Nx wants to merge 1 commit into
LeanBitLab:mainfrom
Scott-Nx:fix/thai-composing-word-boundaries
Open

fix(input): segment Thai composing text by word boundaries#290
Scott-Nx wants to merge 1 commit into
LeanBitLab:mainfrom
Scott-Nx:fix/thai-composing-word-boundaries

Conversation

@Scott-Nx

@Scott-Nx Scott-Nx commented Jul 17, 2026

Copy link
Copy Markdown

What this fixes

When suggestions are enabled for Thai input, the entire sequence will remain one composing word because Thai does not normally use spaces between words.

This causes two visible problems:

  • Suggestions are generated from the entire unsegmented sequence instead of the current Thai word.
  • Pressing Space once only commits the composing text, requiring a second press to insert an actual space.

The input logic now uses locale-aware word boundaries to commit completed Thai segments while keeping only the latest segment composing.

For example, after typing ภาษาไทยดี:

  • ภาษา and ไทย are committed individually.
  • Only ดี remains composing.
  • Suggestions are generated for the current segment instead of ภาษาไทยดี as one word.
  • Pressing Space once produces exactly ภาษาไทยดี .

Completed segments are committed individually so user history and n-gram context remain correct.

LeanType's immediate Text Expander is also respected: segmentation is deferred only while the current input can still match a configured shortcut.

Reproduction

  1. Select a Thai layout.
  2. Enable suggestions.
  3. Type multiple Thai words without spaces, such as ภาษาไทยดี.
  4. Observe the suggestions and press Space once.

Before this change:

  • The full sequence remain composing.
  • Suggestions based on the full unsegmented sequence.
  • The first Space only finished composing, requiring another press to insert a space.

After this change:

  • Suggestions follow the latest Thai word segment.
  • Completed segments are committed separately.
  • One Space press inserts the expected space.

Testing

Tested manually with:

  • Suggestions enabled
  • Suggestions after single and multiple Thai word segments
  • Space after segmented Thai input
  • Immediate Text Expander shortcuts

Unit tests cover Thai segmentation, composing state, history and n-gram context, shortcut handling, Space insertion, and locale detection.

Source

Based on HeliBoard PR #2531, with additional changes for LeanType's Text Expander integration. The shared fixes and cleanup have since been synced back to HeliBoard.

- defer segmentation only for matching immediate shortcuts
- respect per-shortcut prefixes during prefix detection
- commit completed Thai segments individually
- preserve user history and n-gram context
- add regression coverage for expansion and fallback paths
@Scott-Nx
Scott-Nx force-pushed the fix/thai-composing-word-boundaries branch from 7b30e76 to aab4391 Compare July 17, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant