From 6dbfc34f75c8236bed44eb6bfabce8e37801a6bd Mon Sep 17 00:00:00 2001 From: Lexikos Date: Sun, 22 May 2022 09:12:00 +1000 Subject: [PATCH] Fixed double backspacing of supplementary Unicode chars in hotstrings. --- source/hotkey.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/hotkey.cpp b/source/hotkey.cpp index 8bcd4806d..d687e6aa6 100644 --- a/source/hotkey.cpp +++ b/source/hotkey.cpp @@ -2382,14 +2382,19 @@ void Hotstring::DoReplace(LPARAM alParam) if (mDoBackspace) { + int backspace_count = mStringLength; +#ifdef UNICODE + for (LPCTSTR cp = mString; *cp; ++cp) + if (IS_SURROGATE_PAIR(cp[0], cp[1])) + ++cp, --backspace_count; // Treat this surrogate pair as a single character (which it is). +#endif // Subtract 1 from backspaces because the final key pressed by the user to make a // match was already suppressed by the hook (it wasn't sent through to the active // window). So what we do is backspace over all the other keys prior to that one, // put in the replacement text (if applicable), then send the EndChar through // (if applicable) to complete the sequence. - int backspace_count = mStringLength - 1; - if (mEndCharRequired) - ++backspace_count; + if (!mEndCharRequired) + --backspace_count; for (int i = 0; i < backspace_count; ++i) *start_of_replacement++ = '\b'; // Use raw backspaces, not {BS n}, in case the send will be raw. *start_of_replacement = '\0'; // Terminate the string created above.