From 33523c98c24d17d2df0f2e47e8a1db51496271d4 Mon Sep 17 00:00:00 2001 From: Ota <106656898+Opi-Txm@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:48:51 +0100 Subject: [PATCH] Fix #20628: Stop caret left moving off the input string --- distribution/changelog.txt | 1 + src/openrct2-ui/TextComposition.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 6fef16d23d..88619ef374 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -4,6 +4,7 @@ - Improved: [#20951] Activate OpenRCT2 window after using native file dialog on macOS. - Fix: [#20255] Images from the last hovered-over coaster in the object selection are not freed. - Fix: [#20616] Confirmation button in the track designer’s quit prompt has the wrong text. +- Fix: [#20628] Moving caret using Ctrl+left can move too far when using a multibyte grapheme. - Fix: [#21145] [Plugin] setInterval/setTimeout handle conflict. - Fix: [#21157] [Plugin] Widgets do not redraw correctly when updating disabled or visibility state. - Fix: [#21158] [Plugin] Potential crash using setInterval/setTimeout within the callback. diff --git a/src/openrct2-ui/TextComposition.cpp b/src/openrct2-ui/TextComposition.cpp index fd39cb27ee..48f26c3d25 100644 --- a/src/openrct2-ui/TextComposition.cpp +++ b/src/openrct2-ui/TextComposition.cpp @@ -276,7 +276,8 @@ void TextComposition::CaretMoveToLeftToken() lastChar = selectionOffset; break; } - + if (selectionOffset == 0) + break; ch--; selectionOffset--; } @@ -295,12 +296,13 @@ void TextComposition::CaretMoveToLeftToken() break; lastChar = selectionOffset; - + if (selectionOffset == 0) + break; ch--; selectionOffset--; } - _session.SelectionSize = std::max(0, _session.SelectionSize - (selectionOffset - _session.SelectionStart)); + _session.SelectionSize = _session.SelectionSize - (selectionOffset - _session.SelectionStart); _session.SelectionStart = selectionOffset == 0 ? 0 : lastChar; }