From 23100153cc25684d3bc526d48634b1720fafacfe Mon Sep 17 00:00:00 2001 From: zonble Date: Sun, 2 Jan 2022 22:09:23 +0800 Subject: [PATCH] Adds an option to clear entire input buffer by ESC key. This fixes #146. --- Source/Base.lproj/MainMenu.xib | 7 +- Source/Base.lproj/preferences.xib | 163 ++++++++++++++------------- Source/InputMethodController.mm | 44 +++++--- Source/zh-Hant.lproj/preferences.xib | 65 ++++++----- 4 files changed, 157 insertions(+), 122 deletions(-) diff --git a/Source/Base.lproj/MainMenu.xib b/Source/Base.lproj/MainMenu.xib index 5f7bcf12..6a12278f 100644 --- a/Source/Base.lproj/MainMenu.xib +++ b/Source/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -11,7 +11,7 @@ - + @@ -288,6 +288,7 @@ + diff --git a/Source/Base.lproj/preferences.xib b/Source/Base.lproj/preferences.xib index 4534c6b6..cfe934d0 100644 --- a/Source/Base.lproj/preferences.xib +++ b/Source/Base.lproj/preferences.xib @@ -1,8 +1,8 @@ - + - + @@ -19,14 +19,81 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Item 1 + Item 2 + Item 3 + + + + + + + + + + + + + + + - + @@ -46,38 +113,19 @@ - - + - + @@ -86,7 +134,7 @@ - + @@ -95,7 +143,7 @@ - + @@ -104,7 +152,7 @@ - + @@ -130,7 +178,7 @@ - + @@ -156,7 +204,7 @@ - + @@ -178,45 +226,8 @@ - - - - - - - - - - Item 1 - Item 2 - Item 3 - - - - - - - - - - - - - - - - + diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 9dec8a06..1a76847a 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -79,6 +79,7 @@ static NSString *const kComposingBufferSizePreferenceKey = @"ComposingBufferSize static NSString *const kDisableUserCandidateSelectionLearning = @"DisableUserCandidateSelectionLearning"; static NSString *const kChooseCandidateUsingSpaceKey = @"ChooseCandidateUsingSpaceKey"; static NSString *const kChineseConversionEnabledKey = @"ChineseConversionEnabledKey"; +static NSString *const kEscToCleanInputBufferKey = @"EscToCleanInputBufferKey"; // advanced (usually optional) settings static NSString *const kCandidateTextFontName = @"CandidateTextFontName"; @@ -664,8 +665,9 @@ public: if (_bpmfReadingBuffer->isValidKey((char)charCode)) { _bpmfReadingBuffer->combineKey((char)charCode); - // if we have a tone marker, we have to insert the reading to the builder - // in other words, if we don't have a tone marker, we just update the composing buffer + // if we have a tone marker, we have to insert the reading to the + // builder in other words, if we don't have a tone marker, we just + // update the composing buffer composeReading = _bpmfReadingBuffer->hasToneMarker(); if (!composeReading) { [self updateClientComposingBuffer:client]; @@ -741,17 +743,36 @@ public: // Esc if (charCode == 27) { - // if reading is not empty, we cancel the reading; Apple's built-in Zhuyin (and the erstwhile Hanin) has a default option that Esc "cancels" the current composed character and revert it to Bopomofo reading, in odds with the expectation of users from other platforms - - if (_bpmfReadingBuffer->isEmpty()) { - // no nee to beep since the event is deliberately triggered by user + BOOL escToClearInputBufferEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:kEscToCleanInputBufferKey]; + if (escToClearInputBufferEnabled) { + // if the optioon is enabled, we clear everythiong including the composing + // buffer, walked nodes and the reading. if (![_composingBuffer length]) { return NO; } + _bpmfReadingBuffer->clear(); + _builder->clear(); + _walkedNodes.clear(); + [_composingBuffer setString:@""]; } else { - _bpmfReadingBuffer->clear(); + // if reading is not empty, we cancel the reading; Apple's built-in + // Zhuyin (and the erstwhile Hanin) has a default option that Esc + // "cancels" the current composed character and revert it to + // Bopomofo reading, in odds with the expectation of users from + // other platforms + + if (_bpmfReadingBuffer->isEmpty()) { + // no nee to beep since the event is deliberately triggered by user + + if (![_composingBuffer length]) { + return NO; + } + } + else { + _bpmfReadingBuffer->clear(); + } } [self updateClientComposingBuffer:client]; @@ -989,15 +1010,6 @@ public: - (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode { -// if (_inputMode == kPlainBopomofoModeIdentifier) { -// if (charCode == '<') { -// keyCode = kPageUpKeyCode; -// } -// else if (charCode == '>') { -// keyCode = kPageDownKeyCode; -// } -// } - BOOL cancelCandidateKey = (charCode == 27) || ((_inputMode == kPlainBopomofoModeIdentifier) && diff --git a/Source/zh-Hant.lproj/preferences.xib b/Source/zh-Hant.lproj/preferences.xib index 17e6e2c9..ee2d4322 100644 --- a/Source/zh-Hant.lproj/preferences.xib +++ b/Source/zh-Hant.lproj/preferences.xib @@ -1,8 +1,8 @@ - + - + @@ -19,14 +19,14 @@ - - + + - + - + @@ -49,7 +49,7 @@ - + @@ -58,7 +58,7 @@ - + @@ -69,17 +69,8 @@ - - - - - - - - - - + @@ -88,7 +79,7 @@ - + @@ -97,7 +88,7 @@ - + @@ -106,7 +97,7 @@ - + @@ -132,7 +123,7 @@ - + @@ -158,7 +149,7 @@ - + @@ -181,7 +172,7 @@ - + @@ -220,7 +211,7 @@ - + @@ -228,9 +219,29 @@ + + + + + + + + + + - +