diff --git a/Source/Modules/InputHandler_Core.swift b/Source/Modules/InputHandler_Core.swift index 00dd6a36..ecf14bca 100644 --- a/Source/Modules/InputHandler_Core.swift +++ b/Source/Modules/InputHandler_Core.swift @@ -471,7 +471,7 @@ public class InputHandler: InputHandlerProtocol { composer.phonabetCombinationCorrectionEnabled = prefs.autoCorrectReadingCombination } - public var isComposerUsingPinyin: Bool { composer.parser.rawValue >= 100 } + public var isComposerUsingPinyin: Bool { composer.isPinyinMode } public func clearComposerAndCalligrapher() { calligrapher.removeAll() diff --git a/Source/Modules/InputHandler_HandleComposition.swift b/Source/Modules/InputHandler_HandleComposition.swift index a066ae36..a54312ef 100644 --- a/Source/Modules/InputHandler_HandleComposition.swift +++ b/Source/Modules/InputHandler_HandleComposition.swift @@ -30,9 +30,9 @@ extension InputHandler { /// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。 private func handlePhonabetComposition(input: InputSignalProtocol) -> Bool? { guard let delegate = delegate else { return nil } + let existedIntonation = composer.intonation - // 威注音不打算支援對「先輸入聲調、後輸入注音」的情況的支援。 - // 但是對 keyConsumedByReading 的處理得保留。 + // 哪怕不啟用支援對「先輸入聲調、後輸入注音」的情況的支援,對 keyConsumedByReading 的處理得保留。 // 不然的話,「敲 Space 叫出選字窗」的功能會失效。 // 究其原因,乃是因為威注音所用的鐵恨注拼引擎「有在處理陰平聲調」的緣故。 // 對於某些動態注音排列,威注音會依賴包括陰平聲調鍵在內的聲調按鍵做結算判斷。 @@ -93,8 +93,8 @@ extension InputHandler { { return handleEnter(input: input, readingOnly: true) } - // 拿取用來進行索引檢索用的注音。 - guard let readingKey = composer.keyForQuery else { break ifComposeReading } + // 拿取用來進行索引檢索用的注音。這裡先不急著處理「僅有注音符號輸入」的情況。 + guard let readingKey = composer.keyForQuery(pronouncable: true) else { break ifComposeReading } // 向語言模型詢問是否有對應的記錄。 if !currentLM.hasUnigramsFor(keyArray: [readingKey]) { delegate.callError("B49C0979:語彙庫內無「\(readingKey)」的匹配記錄。") @@ -166,7 +166,19 @@ extension InputHandler { /// 是說此時注拼槽並非為空、卻還沒組音。這種情況下只可能是「注拼槽內只有聲調」。 /// 但這裡不處理陰平聲調。 if keyConsumedByReading { - if composer.abortConsumption { + // 此處將 strict 設為 false,以應對「僅有注音符號輸入」的情況。 + if composer.keyForQuery(pronouncable: false) == nil { + // 將被空格鍵覆蓋掉的既有聲調塞入組字器。 + if !composer.isPinyinMode, input.isSpace, + compositor.insertKey(existedIntonation.value) + { + walk() + var theInputting = generateStateOfInputting() + theInputting.textToCommit = commitOverflownComposition + composer.clear() + delegate.switchState(theInputting) + return true + } composer.clear() return nil } @@ -372,27 +384,28 @@ extension InputHandler { // 此處的功能擴充大概只會在威注音輸入法當中用到。 -private extension Tekkon.Composer { +extension Tekkon.Composer { + /// 闡明當前注拼槽是否處於拼音模式。 var isPinyinMode: Bool { parser.rawValue >= 100 } - // 拿取用來進行索引檢索用的注音。 - // 如果輸入法的辭典索引是漢語拼音的話,要注意改這裡、使其拿到的內容是漢語拼音。 - // 警告:該字串不能為空,否則組字引擎會炸。 - var keyForQuery: String? { + + /// 拿取用來進行索引檢索用的注音。 + /// 如果輸入法的辭典索引是漢語拼音的話,要注意改這裡、使其拿到的內容是漢語拼音。 + /// - Remark: 該字串不能為空,否則組字引擎會炸。 + /// - Parameter pronouncable: 是否可以唸出。 + /// - Returns: 可用的查詢用注音字串,或者 nil。 + func keyForQuery(pronouncable: Bool) -> String? { let readingKey = getComposition() var validKeyGeneratable = false switch isPinyinMode { case false: - // 威注音不處理「先輸入聲調、後輸入注音」的情形。 - validKeyGeneratable = !readingKey.isEmpty - // 是說改用下面這句的話就可以像小麥注音那樣處理「先輸入聲調、後輸入注音」的情形, - // 但這就沒辦法將注音符號單獨鍵入組字區了。 - // validKeyGeneratable = readingKey.isEmpty ? false : !romajiBuffer.isEmpty - case true: validKeyGeneratable = !romajiBuffer.isEmpty + switch pronouncable { + case false: + validKeyGeneratable = !readingKey.isEmpty + case true: + validKeyGeneratable = isPronouncable + } + case true: validKeyGeneratable = isPronouncable } return validKeyGeneratable ? readingKey : nil } - - var abortConsumption: Bool { - isPinyinMode ? romajiBuffer.isEmpty : getComposition().isEmpty - } }