From 3ffa329f20612e9d69cbbe963e599d2f6bd8eba0 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 11 Apr 2018 11:52:47 +0700 Subject: [PATCH] Pressing backspace corrupts cached context with SMP characters --- windows/src/engine/keyman32/appint/appint.cpp | 16 ++++++++++++++-- windows/src/engine/keyman32/appint/appint.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/windows/src/engine/keyman32/appint/appint.cpp b/windows/src/engine/keyman32/appint/appint.cpp index aaccab9c3c..cd067e8f9e 100644 --- a/windows/src/engine/keyman32/appint/appint.cpp +++ b/windows/src/engine/keyman32/appint/appint.cpp @@ -84,8 +84,11 @@ WCHAR *AppContext::BufMax(int n) // Used only by IMX DLLs void AppContext::Delete() { - if(CharIsDeadkey()) pos -= 2; - + if (CharIsDeadkey()) { + pos -= 2; + } else if (CharIsSurrogatePair()) { + pos--; + } //SendDebugMessageFormat(0, sdmAIDefault, 0, "AppContext::Delete"); if(pos > 0) pos--; @@ -144,6 +147,15 @@ BOOL AppContext::CharIsDeadkey() CurContext[pos-2] == CODE_DEADKEY; } +BOOL AppContext::CharIsSurrogatePair() +{ + if (pos < 2) // low_surrogate, high_surrogate + return FALSE; + + return Uni_IsSurrogate1(CurContext[pos - 2]) && + Uni_IsSurrogate2(CurContext[pos - 1]); +} + /* AppActionQueue */ AppActionQueue::AppActionQueue() diff --git a/windows/src/engine/keyman32/appint/appint.h b/windows/src/engine/keyman32/appint/appint.h index 3378327a50..0b0d9025fe 100644 --- a/windows/src/engine/keyman32/appint/appint.h +++ b/windows/src/engine/keyman32/appint/appint.h @@ -95,6 +95,7 @@ public: WCHAR *BufMax(int n); WCHAR *Buf(int n); BOOL CharIsDeadkey(); + BOOL CharIsSurrogatePair(); }; class AppContextWithStores : public AppContext // I4978