From 9b7c205c5e358dc5e944e3d204e15c5af908dab8 Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Mon, 25 Jun 2018 01:08:16 +0800 Subject: [PATCH] Fix incorrect unprintable ASCII handling (#139) When Caps Lock is on and when the character code is not printable, we should simply reject handling such character instead of absorbing it and inserting the character to the client buffer--not all apps handle those insertions. --- Source/InputMethodController.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 5e207827..6197d5ae 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -593,6 +593,11 @@ public: return NO; } + // if ASCII but not printable, don't use insertText:replacementRange: as many apps don't handle non-ASCII char insertions. + if (charCode < 0x80 && !isprint(charCode)) { + return NO; + } + // when shift is pressed, don't do further processing, since it outputs capital letter anyway. NSString *popedText = [inputText lowercaseString]; [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)];