From 907e14da285d39677113a9440d58c4a44ef05b1b Mon Sep 17 00:00:00 2001 From: pablohc Date: Wed, 22 Apr 2026 21:18:26 +0200 Subject: [PATCH] fix: pressing space barely moves input cursor (#1729) (#1733) ## Summary * **What is the goal of this PR?** Fix the visual keyboard cursor not advancing when typing a space. Typing one space leaves the cursor at position 0; typing two spaces advances it only by one space width. This affects all input types except URL. * **What changes are included?** Replace `getTextWidth()` with `getTextAdvanceX()` in four locations within `KeyboardEntryActivity::render()` for cursor positioning and line-wrapping calculations. ## Additional Context * **Root cause**: `getTextWidth()` returns the bounding-box width of the drawn glyphs. The space glyph has `width=0` and `height=0` (it's invisible), so `getTextWidth(" ") == 0`. The trailing `advanceX` of the last character is only flushed when the *next* character is processed, so a string ending in space reports zero width. `getTextAdvanceX()` correctly includes the final glyph's advance, matching how `drawText()` actually positions characters. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**YES**_ --- src/activities/util/KeyboardEntryActivity.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/activities/util/KeyboardEntryActivity.cpp b/src/activities/util/KeyboardEntryActivity.cpp index eebd0b5d8..7e5e1a7ef 100644 --- a/src/activities/util/KeyboardEntryActivity.cpp +++ b/src/activities/util/KeyboardEntryActivity.cpp @@ -421,7 +421,7 @@ void KeyboardEntryActivity::render(RenderLock&&) { while (true) { std::string lineText = displayText.substr(lineStartIdx, lineEndIdx - lineStartIdx); - textWidth = renderer.getTextWidth(UI_12_FONT_ID, lineText.c_str()); + textWidth = renderer.getTextAdvanceX(UI_12_FONT_ID, lineText.c_str(), EpdFontFamily::REGULAR); if (textWidth <= maxLineWidth) { const bool isLastLine = (lineEndIdx == static_cast(displayText.length())); bool isCursorLine = false; @@ -433,12 +433,14 @@ void KeyboardEntryActivity::render(RenderLock&&) { } else { beforeCursor = displayText.substr(lineStartIdx, cursorPos - lineStartIdx); } - int beforeWidth = renderer.getTextWidth(UI_12_FONT_ID, beforeCursor.c_str()); + int beforeWidth = renderer.getTextAdvanceX(UI_12_FONT_ID, beforeCursor.c_str(), EpdFontFamily::REGULAR); int kernOffset = 0; if (cursorPos < displayText.length()) { std::string beforeAndCursor = beforeCursor + displayText.substr(cursorPos, 1); - int beforeAndCursorWidth = renderer.getTextWidth(UI_12_FONT_ID, beforeAndCursor.c_str()); - int charAdvance = renderer.getTextWidth(UI_12_FONT_ID, displayText.substr(cursorPos, 1).c_str()); + int beforeAndCursorWidth = + renderer.getTextAdvanceX(UI_12_FONT_ID, beforeAndCursor.c_str(), EpdFontFamily::REGULAR); + int charAdvance = + renderer.getTextAdvanceX(UI_12_FONT_ID, displayText.substr(cursorPos, 1).c_str(), EpdFontFamily::REGULAR); kernOffset = beforeAndCursorWidth - beforeWidth - charAdvance; } if (centerText) {