From e33de75402bda8e3ace589a938ec762238e68e3d Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Mon, 4 Dec 2023 21:14:26 +0100 Subject: [PATCH] Fix backspacing over control visualizers (#16400) During `!measureOnly` the old code would increment `distance` twice. Now it doesn't. :) Closes #16356 ## Validation Steps Performed See updated test instructions in `doc/COOKED_READ_DATA.md` (cherry picked from commit 654b755161f2635a16e2878e54941aee8d552075) Service-Card-Id: 91232745 Service-Version: 1.19 --- doc/COOKED_READ_DATA.md | 6 ++++++ src/host/readDataCooked.cpp | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/COOKED_READ_DATA.md b/doc/COOKED_READ_DATA.md index 113a51bb749..f4b463f7aa6 100644 --- a/doc/COOKED_READ_DATA.md +++ b/doc/COOKED_READ_DATA.md @@ -15,6 +15,12 @@ All of the following ✅ marks must be fulfilled during manual testing: * Press tab: Autocomplete to "a😊b.txt" ✅ * Navigate the cursor right past the "a" * Press tab twice: Autocomplete to "a😟b.txt" ✅ +* Execute `printf(" "); gets(buffer);` in C (or equivalent) + * Press Tab, A, Ctrl+V, Tab, A ✅ + * The prompt is " A^V A" ✅ + * Cursor navigation works ✅ + * Backspacing/Deleting random parts of it works ✅ + * It never deletes the initial 4 spaces ✅ * Backspace deletes preceding glyphs ✅ * Ctrl+Backspace deletes preceding words ✅ * Escape clears input ✅ diff --git a/src/host/readDataCooked.cpp b/src/host/readDataCooked.cpp index c842bab312d..4869e2ad91a 100644 --- a/src/host/readDataCooked.cpp +++ b/src/host/readDataCooked.cpp @@ -938,22 +938,31 @@ ptrdiff_t COOKED_READ_DATA::_writeCharsImpl(const std::wstring_view& text, const const auto wch = *it; if (wch == UNICODE_TAB) { - const auto col = _getColumnAtRelativeCursorPosition(distance + cursorOffset); - const auto remaining = width - col; - distance += std::min(remaining, 8 - (col & 7)); buf[0] = L'\t'; len = 1; } else { // In the interactive mode we replace C0 control characters (0x00-0x1f) with ASCII representations like ^C (= 0x03). - distance += 2; buf[0] = L'^'; buf[1] = gsl::narrow_cast(wch + L'@'); len = 2; } - if (!measureOnly) + if (measureOnly) + { + if (wch == UNICODE_TAB) + { + const auto col = _getColumnAtRelativeCursorPosition(distance + cursorOffset); + const auto remaining = width - col; + distance += std::min(remaining, 8 - (col & 7)); + } + else + { + distance += 2; + } + } + else { distance += _writeCharsUnprocessed({ &buf[0], len }); }