From 7e57eb74c146b0b9544f285e8ea8550405036247 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 26 Nov 2022 04:19:02 +0800 Subject: [PATCH] InputHandler // Allow committing composer / calligrapher contents. - Requiring that the compositor is empty. --- .../InputHandler_HandleComposition.swift | 10 ++++++++++ Source/Modules/InputHandler_States.swift | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Source/Modules/InputHandler_HandleComposition.swift b/Source/Modules/InputHandler_HandleComposition.swift index c81836ac..01b9fd35 100644 --- a/Source/Modules/InputHandler_HandleComposition.swift +++ b/Source/Modules/InputHandler_HandleComposition.swift @@ -86,6 +86,11 @@ extension InputHandler { // readingKey 不能為空。 composeReading = composeReading && !readingKey.isEmpty if composeReading { + if input.isControlHold, input.isCommandHold, input.isEnter, + !input.isOptionHold, !input.isShiftHold, compositor.isEmpty + { + return handleCtrlCommandEnter() + } // 向語言模型詢問是否有對應的記錄。 if !currentLM.hasUnigramsFor(key: readingKey) { delegate.callError("B49C0979:語彙庫內無「\(readingKey)」的匹配記錄。") @@ -229,6 +234,11 @@ extension InputHandler { // 來看看詞庫內到底有沒有對應的讀音索引。這裡用了類似「|=」的判斷處理方式。 combineStrokes = combineStrokes || (!calligrapher.isEmpty && confirmCombination) if combineStrokes { + if input.isControlHold, input.isCommandHold, input.isEnter, + !input.isOptionHold, !input.isShiftHold, composer.isEmpty + { + return handleCtrlCommandEnter() + } // 向語言模型詢問是否有對應的記錄。 if !currentLM.hasUnigramsFor(key: calligrapher) { delegate.callError("B49C0979_Cassette:語彙庫內無「\(calligrapher)」的匹配記錄。") diff --git a/Source/Modules/InputHandler_States.swift b/Source/Modules/InputHandler_States.swift index 72e0ac06..e8ec0a36 100644 --- a/Source/Modules/InputHandler_States.swift +++ b/Source/Modules/InputHandler_States.swift @@ -298,9 +298,21 @@ extension InputHandler { guard state.type == .ofInputting else { return false } var displayedText = compositor.keys.joined(separator: "\t") - if prefs.inlineDumpPinyinInLieuOfZhuyin, !prefs.cassetteEnabled { - displayedText = Tekkon.restoreToneOneInZhuyinKey(target: displayedText) // 恢復陰平標記 - displayedText = Tekkon.cnvPhonaToHanyuPinyin(target: displayedText) // 注音轉拼音 + if compositor.isEmpty { + displayedText = readingForDisplay + } + if !prefs.cassetteEnabled { + if prefs.inlineDumpPinyinInLieuOfZhuyin { + if !compositor.isEmpty { + displayedText = Tekkon.restoreToneOneInZhuyinKey(target: displayedText) // 恢復陰平標記 + } + displayedText = Tekkon.cnvPhonaToHanyuPinyin(target: displayedText) // 注音轉拼音 + } + if prefs.showHanyuPinyinInCompositionBuffer { + if compositor.isEmpty { + displayedText = displayedText.replacingOccurrences(of: "1", with: "") + } + } } let isVCED = delegate.clientBundleIdentifier.contains("vChewingPhraseEditor")