From 5d2da697561e6eba2057837fc38bb0e4a3af6ab2 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 18 Jun 2022 07:54:40 +0800 Subject: [PATCH] KeyHandler // Squashing _misc into _core & -SwiftUI refs. --- .../ControllerModules/KeyHandler_Core.swift | 35 ++++++++++ .../KeyHandler_HandleInput.swift | 1 - .../ControllerModules/KeyHandler_Misc.swift | 66 ------------------- vChewing.xcodeproj/project.pbxproj | 4 -- 4 files changed, 35 insertions(+), 71 deletions(-) delete mode 100644 Source/Modules/ControllerModules/KeyHandler_Misc.swift diff --git a/Source/Modules/ControllerModules/KeyHandler_Core.swift b/Source/Modules/ControllerModules/KeyHandler_Core.swift index 1399df32..63e8c310 100644 --- a/Source/Modules/ControllerModules/KeyHandler_Core.swift +++ b/Source/Modules/ControllerModules/KeyHandler_Core.swift @@ -88,6 +88,10 @@ class KeyHandler { // MARK: - Functions dealing with Megrez. + var actualCandidateCursorIndex: Int { + mgrPrefs.useRearCursorMode ? min(compositorCursorIndex, compositorLength - 1) : max(compositorCursorIndex, 1) + } + func walk() { // Retrieve the most likely grid, i.e. a Maximum Likelihood Estimation // of the best possible Mandarin characters given the input syllables, @@ -267,6 +271,10 @@ class KeyHandler { // MARK: - Extracted methods and functions (Tekkon). + var currentMandarinParser: String { + mgrPrefs.mandarinParserName + "_" + } + func ensureParser() { switch mgrPrefs.mandarinParser { case MandarinParser.ofStandard.rawValue: @@ -302,6 +310,33 @@ class KeyHandler { composer.clear() } + /// 用於網頁 Ruby 的注音需要按照教科書印刷的方式來顯示輕聲,所以這裡處理一下。 + func cnvZhuyinKeyToTextbookReading(target: String, newSeparator: String = "-") -> String { + var arrReturn: [String] = [] + for neta in target.split(separator: "-") { + var newString = String(neta) + if String(neta.reversed()[0]) == "˙" { + newString = String(neta.dropLast()) + newString.insert("˙", at: newString.startIndex) + } + arrReturn.append(newString) + } + return arrReturn.joined(separator: newSeparator) + } + + // 用於網頁 Ruby 的拼音的陰平必須顯示,這裡處理一下。 + func restoreToneOneInZhuyinKey(target: String, newSeparator: String = "-") -> String { + var arrReturn: [String] = [] + for neta in target.split(separator: "-") { + var newNeta = String(neta) + if !"ˊˇˋ˙".contains(String(neta.reversed()[0])), !neta.contains("_") { + newNeta += "1" + } + arrReturn.append(newNeta) + } + return arrReturn.joined(separator: newSeparator) + } + // MARK: - Extracted methods and functions (Megrez). var isCompositorEmpty: Bool { compositor.grid.width == 0 } diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index 120c46cc..724d10c4 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -25,7 +25,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import Cocoa -import SwiftUI // MARK: - § Handle Input with States. diff --git a/Source/Modules/ControllerModules/KeyHandler_Misc.swift b/Source/Modules/ControllerModules/KeyHandler_Misc.swift deleted file mode 100644 index 7c9e06c9..00000000 --- a/Source/Modules/ControllerModules/KeyHandler_Misc.swift +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2021 and onwards The vChewing Project (MIT-NTL License). -// Refactored from the ObjCpp-version of this class by: -// (c) 2011 and onwards The OpenVanilla Project (MIT License). -/* -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -1. The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -2. No trademark license is granted to use the trade names, trademarks, service -marks, or product names of Contributor, except as required to fulfill notice -requirements above. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -import Cocoa - -// MARK: - § Misc functions. - -extension KeyHandler { - var currentMandarinParser: String { - mgrPrefs.mandarinParserName + "_" - } - - var actualCandidateCursorIndex: Int { - mgrPrefs.useRearCursorMode ? min(compositorCursorIndex, compositorLength - 1) : max(compositorCursorIndex, 1) - } - - // 用於網頁 Ruby 的注音需要按照教科書印刷的方式來顯示輕聲,所以這裡處理一下。 - func cnvZhuyinKeyToTextbookReading(target: String, newSeparator: String = "-") -> String { - var arrReturn: [String] = [] - for neta in target.split(separator: "-") { - var newString = String(neta) - if String(neta.reversed()[0]) == "˙" { - newString = String(neta.dropLast()) - newString.insert("˙", at: newString.startIndex) - } - arrReturn.append(newString) - } - return arrReturn.joined(separator: newSeparator) - } - - // 用於網頁 Ruby 的拼音的陰平必須顯示,這裡處理一下。 - func restoreToneOneInZhuyinKey(target: String, newSeparator: String = "-") -> String { - var arrReturn: [String] = [] - for neta in target.split(separator: "-") { - var newNeta = String(neta) - if !"ˊˇˋ˙".contains(String(neta.reversed()[0])), !neta.contains("_") { - newNeta += "1" - } - arrReturn.append(newNeta) - } - return arrReturn.joined(separator: newSeparator) - } -} diff --git a/vChewing.xcodeproj/project.pbxproj b/vChewing.xcodeproj/project.pbxproj index 7ad62bf7..9a89f6e2 100644 --- a/vChewing.xcodeproj/project.pbxproj +++ b/vChewing.xcodeproj/project.pbxproj @@ -26,7 +26,6 @@ 5B40730D281672610023DFFF /* lmReplacements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B40730A281672610023DFFF /* lmReplacements.swift */; }; 5B54E743283A7D89001ECBDC /* lmCoreNS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B54E742283A7D89001ECBDC /* lmCoreNS.swift */; }; 5B5E535227EF261400C6AA1E /* IME.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B5E535127EF261400C6AA1E /* IME.swift */; }; - 5B61B0CA280BEFD4002E3CFA /* KeyHandler_Misc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B61B0C9280BEFD4002E3CFA /* KeyHandler_Misc.swift */; }; 5B62A32927AE77D100A19448 /* FSEventStreamHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A32827AE77D100A19448 /* FSEventStreamHelper.swift */; }; 5B62A33227AE792F00A19448 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */; }; 5B62A33627AE795800A19448 /* mgrPrefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33527AE795800A19448 /* mgrPrefs.swift */; }; @@ -193,7 +192,6 @@ 5B40730A281672610023DFFF /* lmReplacements.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; lineEnding = 0; path = lmReplacements.swift; sourceTree = ""; usesTabs = 0; }; 5B54E742283A7D89001ECBDC /* lmCoreNS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = lmCoreNS.swift; sourceTree = ""; }; 5B5E535127EF261400C6AA1E /* IME.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = IME.swift; sourceTree = ""; tabWidth = 2; usesTabs = 0; }; - 5B61B0C9280BEFD4002E3CFA /* KeyHandler_Misc.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = KeyHandler_Misc.swift; sourceTree = ""; tabWidth = 2; usesTabs = 0; }; 5B62A32827AE77D100A19448 /* FSEventStreamHelper.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = FSEventStreamHelper.swift; sourceTree = ""; tabWidth = 2; usesTabs = 0; }; 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = InputSourceHelper.swift; sourceTree = ""; tabWidth = 2; usesTabs = 0; }; 5B62A33527AE795800A19448 /* mgrPrefs.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = mgrPrefs.swift; sourceTree = ""; tabWidth = 2; usesTabs = 0; }; @@ -414,7 +412,6 @@ 5BD0113C2818543900609769 /* KeyHandler_Core.swift */, 5B782EC3280C243C007276DE /* KeyHandler_HandleCandidate.swift */, 5B7F225C2808501000DDD3CB /* KeyHandler_HandleInput.swift */, - 5B61B0C9280BEFD4002E3CFA /* KeyHandler_Misc.swift */, 5B3133BE280B229700A4A505 /* KeyHandler_States.swift */, 5B62A33727AE79CD00A19448 /* StringUtils.swift */, 5BAA8FBD282CAF380066C406 /* SyllableComposer.swift */, @@ -1104,7 +1101,6 @@ 5B62A33227AE792F00A19448 /* InputSourceHelper.swift in Sources */, 5B5E535227EF261400C6AA1E /* IME.swift in Sources */, 5B62A34927AE7CD900A19448 /* TooltipController.swift in Sources */, - 5B61B0CA280BEFD4002E3CFA /* KeyHandler_Misc.swift in Sources */, 5B38F59A281E2E49007D5F5D /* 6_Unigram.swift in Sources */, 5BA9FD4027FEF3C8002DE248 /* Localization.swift in Sources */, 5BAA8FBE282CAF380066C406 /* SyllableComposer.swift in Sources */,