From dbf6e91d112856a18904d8945f10bac28611aa1f Mon Sep 17 00:00:00 2001 From: zonble Date: Thu, 11 Nov 2021 02:22:19 +0800 Subject: [PATCH 1/7] Allows commit the first canidate while typing a punctuation in plain BPMF mode. --- Source/InputMethodController.mm | 65 ++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 7d664553..f54b033f 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -542,6 +542,35 @@ public: NSBeep(); } +- (string)currentLayout +{ + string layout = string("Standard_");; + NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey]; + switch (keyboardLayout) { + case 0: + layout = string("Standard_"); + break; + case 1: + layout = string("ETen_"); + break; + case 2: + layout = string("ETen26_"); + break; + case 3: + layout = string("Hsu_"); + break; + case 4: + layout = string("HanyuPinyin_"); + break; + case 5: + layout = string("IBM_"); + break; + default: + break; + } + return layout; +} + - (BOOL)handleInputText:(NSString*)inputText key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)client { NSRect textFrame = NSZeroRect; @@ -891,31 +920,7 @@ public: } } - string layout = string("Standard_");; - NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey]; - switch (keyboardLayout) { - case 0: - layout = string("Standard_"); - break; - case 1: - layout = string("ETen_"); - break; - case 2: - layout = string("ETen26_"); - break; - case 3: - layout = string("Hsu_"); - break; - case 4: - layout = string("HanyuPinyin_"); - break; - case 5: - layout = string("IBM_"); - break; - default: - break; - } - + string layout = [self currentLayout]; string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); if (_languageModel->hasUnigramsForKey(customPunctuation)) { if (_bpmfReadingBuffer->isEmpty()) { @@ -1133,7 +1138,15 @@ public: } if (_inputMode == kPlainBopomofoModeIdentifier) { - if (_bpmfReadingBuffer->isValidKey((char)charCode)) { + // TODO: also commit punctuation. + string layout = [self currentLayout]; + string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); + string punctuation = string("_punctuation_") + string(1, (char)charCode); + + BOOL shouldAutoSelectCandidate = _bpmfReadingBuffer->isValidKey((char)charCode) || _languageModel->hasUnigramsForKey(customPunctuation) || + _languageModel->hasUnigramsForKey(punctuation); + + if (shouldAutoSelectCandidate) { NSUInteger candidateIndex = [gCurrentCandidateController candidateIndexAtKeyLabelIndex:0]; if (candidateIndex != NSUIntegerMax) { [self candidateController:gCurrentCandidateController didSelectCandidateAtIndex:candidateIndex]; From e22efd4e9010626fae1b3d0db8f204b23e38e03b Mon Sep 17 00:00:00 2001 From: zonble Date: Thu, 11 Nov 2021 23:02:18 +0800 Subject: [PATCH 2/7] Allows auto-commiting the first candidate when users input a punctuation in plan BPMF mode. --- Source/InputMethodController.mm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index f54b033f..2ed398a7 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -984,14 +984,14 @@ public: - (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode { - if (_inputMode == kPlainBopomofoModeIdentifier) { - if (charCode == '<') { - keyCode = kPageUpKeyCode; - } - else if (charCode == '>') { - keyCode = kPageDownKeyCode; - } - } +// if (_inputMode == kPlainBopomofoModeIdentifier) { +// if (charCode == '<') { +// keyCode = kPageUpKeyCode; +// } +// else if (charCode == '>') { +// keyCode = kPageDownKeyCode; +// } +// } BOOL cancelCandidateKey = (charCode == 27) || @@ -1138,7 +1138,6 @@ public: } if (_inputMode == kPlainBopomofoModeIdentifier) { - // TODO: also commit punctuation. string layout = [self currentLayout]; string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); string punctuation = string("_punctuation_") + string(1, (char)charCode); From 2784a0814a7c226e259bab0ac2c750c9ae8fb8e1 Mon Sep 17 00:00:00 2001 From: zonble Date: Fri, 12 Nov 2021 00:56:11 +0800 Subject: [PATCH 3/7] Updates CI settings. --- .github/workflows/continuous-integration-workflow.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index c8a87cdc..5c094c40 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -11,5 +11,10 @@ jobs: - uses: actions/checkout@v1 - name: Clean run: xcodebuild -scheme McBopomofo -configuration Release clean + - name: Clean + run: xcodebuild -scheme McBopomofoInstaller -configuration Release clean - name: Build - run: xcodebuild -scheme McBopomofo -configuration Release + run: xcodebuild -scheme McBopomofo -configuration Release build + - name: Build + run: xcodebuild -scheme McBopomofoInstaller -configuration Release build + From a7627f8dc79ae37e2350afd1765be2f686e67b04 Mon Sep 17 00:00:00 2001 From: zonble Date: Fri, 12 Nov 2021 01:15:06 +0800 Subject: [PATCH 4/7] Allows users to use left and right key to go to another candidate page in the vertical candidates list. This fixes #61. --- Source/InputMethodController.mm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 2ed398a7..1dbf9a0a 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -1040,7 +1040,10 @@ public: return YES; } else { - [self beep]; + BOOL updated = [gCurrentCandidateController showPreviousPage]; + if (!updated) { + [self beep]; + } [self updateClientComposingBuffer:_currentCandidateClient]; return YES; } @@ -1055,7 +1058,10 @@ public: return YES; } else { - [self beep]; + BOOL updated = [gCurrentCandidateController showNextPage]; + if (!updated) { + [self beep]; + } [self updateClientComposingBuffer:_currentCandidateClient]; return YES; } From 23100153cc25684d3bc526d48634b1720fafacfe Mon Sep 17 00:00:00 2001 From: zonble Date: Sun, 2 Jan 2022 22:09:23 +0800 Subject: [PATCH 5/7] 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 @@ + + + + + + + + + + - + From 69a6ac6d67449b92c3af1821e9641c033e79a3d0 Mon Sep 17 00:00:00 2001 From: zonble Date: Sun, 2 Jan 2022 22:13:14 +0800 Subject: [PATCH 6/7] Updates CI settings. --- .github/workflows/continuous-integration-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index 5c094c40..b70b3abe 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -6,7 +6,7 @@ jobs: name: Build runs-on: macOS-latest env: - DEVELOPER_DIR: /Applications/Xcode_12.app/Contents/Developer + DEVELOPER_DIR: /Applications/Xcode.app/Contents/Developer steps: - uses: actions/checkout@v1 - name: Clean From c32e216a6f1bf20961a6705d6015bd007ef9ee34 Mon Sep 17 00:00:00 2001 From: zonble Date: Sun, 2 Jan 2022 22:23:04 +0800 Subject: [PATCH 7/7] Updates the README file for system requirement. --- README.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.markdown b/README.markdown index 359a8385..f0fa1229 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,12 @@ # OpenVanilla McBopomofo 小麥注音輸入法 +## 系統需求 + +- macOS 10.15 Catalina 以上版本 +- Xcode 12.0 以上版本 + +由於小麥注音輸入法開始使用 SPM(Swift Package Manager)管理相依套件,因此必須使用 Xcode 12 開發。 + ## 開發流程 用 Xcode 開啟 `McBopomofo.xcodeproj`,選 "McBopomofo Installer" target,build 完之後直接執行該安裝程式,就可以安裝小麥注音。