Repository navigation
XKey v1.2.21 (Build 20260512)
What's New
fix(engine): auto-capitalize sentence first char — full audit & fixes
Thorough audit and fixes for the "Tự động viết hoa chữ đầu câu"
feature. Covers 5 independent bugs across VNEngine core and the
XKeyIM Input Method, introduces a DRY invariant to prevent future
regressions, and adds full test coverage.
Core bugs fixed
-
updateUpperCaseStatus() reset status to 0 on space, breaking the
period → space → letter capitalize flow. Now preserves pending
status when space is typed. -
handleNormalKey() trigger only checked status == 2 (newline) but
never status == 1 (period). Changed to status >= 1 so both "."
and "\n" capitalize the next word. -
handleWordBreak() had inline duplicate logic for upperCaseStatus
that was practically dead code (EventHandler and XKeyIMController
both intercept word breaks first). Replaced with delegation to
updateUpperCaseStatus() — single source of truth. -
handleWordBreak() used VietnameseData.char(for: keyCode) which
returned nil for KEY_ENTER/KEY_RETURN, incorrectly resetting
status to 0. Pass the already-available character parameter
directly ("\n" for Enter, "." for period, etc.). -
processWordBreak() had 3 early-return paths (macro replacement,
macro after restore, spell-check restore success) that skipped
the updateUpperCaseStatus() call. Typing "gm. b" with a macro
"gm → gmail" produced "gmail. b" instead of "gmail. B".
DRY invariant
Replace 3 scattered updateUpperCaseStatus() calls in processWordBreak
with a single defer { updateUpperCaseStatus(character: character) }
at function entry. Guarantees the status is always updated regardless
of which return path is taken, including future paths.
XKeyIM Input Method (critical bug)
XKeyIMSettings class was missing the upperCaseFirstChar property.
applySettings() never forwarded it to the engine, so vUpperCaseFirstChar
stayed 0 in XKeyIM mode even though the toggle saved to plist correctly.
Users running XKeyIM as their input method never saw the feature work.
- Add upperCaseFirstChar property to XKeyIMSettings
- Read XKey.upperCaseFirstChar from plist in reload()
- Forward to engine in applySettings()
Also added the missing updateUpperCaseStatus("\n") call in the Enter
handler before engine.resetWithCursorMoved().
State hygiene
VNEngineSettings.updateSettings() now clears upperCaseStatus when the
feature is toggled off, preventing stale pending status from leaking
into future typing if the user re-enables the feature later.
Feature scope expanded
updateUpperCaseStatus() now treats "?" and "!" as sentence-ending
punctuation in addition to ".". Previously only "." triggered
capitalize even though "?" and "!" are semantically equivalent.
Test coverage
New file XKeyTests/VNEngineAutoCapitalizeTests.swift with 15 tests:
- Happy paths: . ? ! and \n with/without intervening spaces
- Negative paths: , space alone, feature disabled
- State transitions: reset by non-space, only first char caps
- Regression guards for bugs #5 (macro path) and state-leak
(toggle off then on must not leak pending status)
All 391 tests in the full suite pass. Both XKey main app and XKeyIM
targets build successfully.
Files changed
XKey/Core/Engine/VNEngine.swift
XKey/Core/Engine/VNEngineSettings.swift
XKeyIM/XKeyIMController.swift
XKeyTests/VNEngineAutoCapitalizeTests.swift (new)
XKey.xcodeproj/project.pbxproj