Pre Merge pull request !84 from ShikiSuen/upd/1.9.3sp1

This commit is contained in:
ShikiSuen 2022-08-15 05:04:16 +00:00 committed by Gitee
commit e3108d1fc7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 135 additions and 174 deletions

View File

@ -0,0 +1,73 @@
// Copyright (c) 2011 and onwards The OpenVanilla Project (MIT License).
// All possible vChewing-specific modifications are of:
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
// ... with NTL restriction stating that:
// 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 defined in MIT License.
import InputMethodKit
extension ctlInputMethod {
/// handle() IMK
/// handle()
/// - Parameter event: IMK
/// - Returns: `true` IMK`false`
func commonEventHandler(_ event: NSEvent!) -> Bool {
// Shift macOS 10.15 macOS
let shouldUseHandle =
(IME.arrClientShiftHandlingExceptionList.contains(clientBundleIdentifier)
|| mgrPrefs.shouldAlwaysUseShiftKeyAccommodation)
if #available(macOS 10.15, *) {
if ShiftKeyUpChecker.check(event), !mgrPrefs.disableShiftTogglingAlphanumericalMode {
if !shouldUseHandle || (!rencentKeyHandledByKeyHandler && shouldUseHandle) {
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Alphanumerical Mode", comment: ""), "\n",
toggleASCIIMode()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
)
)
}
if shouldUseHandle {
rencentKeyHandledByKeyHandler = false
}
return false
}
}
/// flags使 KeyHandler
/// flags
/// event.type == .flagsChanged return false
/// NSInternalInconsistencyException
if event.type == .flagsChanged { return false }
//
ctlInputMethod.areWeNerfing = event.modifierFlags.contains([.shift, .command])
var input = InputSignal(event: event, isVerticalTyping: isVerticalTyping)
input.isASCIIModeInput = isASCIIMode
//
// KeyHandler
if !input.charCode.isPrintable {
return false
}
/// 調
/// result bool IMK
/// keyHandler.handleCandidate()
let result = keyHandler.handle(input: input, state: state) { newState in
self.handle(state: newState)
} errorCallback: {
clsSFX.beep()
}
if shouldUseHandle {
rencentKeyHandledByKeyHandler = result
}
return result
}
}

View File

@ -107,11 +107,15 @@ class ctlInputMethod: IMKInputController {
// activateServer nil
//
if keyHandler.delegate == nil { keyHandler.delegate = self }
guard let client = client() else { return }
setValue(IME.currentInputMode.rawValue, forTag: 114_514, client: client)
setValue(IME.currentInputMode.rawValue, forTag: 114_514, client: client())
keyHandler.clear() // handle State.Empty()
keyHandler.ensureParser()
if #available(macOS 10.13, *) {
} else {
mgrPrefs.useIMKCandidateWindow = false // macOS 10.11 IMK
}
if isASCIIMode {
if mgrPrefs.disableShiftTogglingAlphanumericalMode {
isASCIIMode = false
@ -128,7 +132,7 @@ class ctlInputMethod: IMKInputController {
///
/// macOS
if client.bundleIdentifier() != Bundle.main.bundleIdentifier {
if let client = client(), client.bundleIdentifier() != Bundle.main.bundleIdentifier {
// 使
setKeyLayout()
handle(state: InputState.Empty())
@ -205,64 +209,18 @@ class ctlInputMethod: IMKInputController {
@objc(handleEvent:client:) override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
_ = sender //
// Shift macOS 10.15 macOS
let shouldUseHandle =
(IME.arrClientShiftHandlingExceptionList.contains(clientBundleIdentifier)
|| mgrPrefs.shouldAlwaysUseShiftKeyAccommodation)
if #available(macOS 10.15, *) {
if ShiftKeyUpChecker.check(event), !mgrPrefs.disableShiftTogglingAlphanumericalMode {
if !shouldUseHandle || (!rencentKeyHandledByKeyHandler && shouldUseHandle) {
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Alphanumerical Mode", comment: ""), "\n",
toggleASCIIMode()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
)
)
}
if shouldUseHandle {
rencentKeyHandledByKeyHandler = false
}
return false
}
}
/// IMK IMK
// IMK IMK
// interpretKeyEvents()
// - super.interpretKeyEvents()
// - delegate ctlInputMethod KeyHandler
if let ctlCandidateCurrent = ctlInputMethod.ctlCandidateCurrent as? ctlCandidateIMK, ctlCandidateCurrent.visible {
ctlCandidateCurrent.interpretKeyEvents([event])
return true
}
/// flags使 KeyHandler
/// flags
/// event.type == .flagsChanged return false
/// NSInternalInconsistencyException
if event.type == .flagsChanged { return false }
//
ctlInputMethod.areWeNerfing = event.modifierFlags.contains([.shift, .command])
var input = InputSignal(event: event, isVerticalTyping: isVerticalTyping)
input.isASCIIModeInput = isASCIIMode
//
// KeyHandler
if !input.charCode.isPrintable {
return false
}
/// 調
/// result bool IMK
let result = keyHandler.handle(input: input, state: state) { newState in
self.handle(state: newState)
} errorCallback: {
clsSFX.beep()
}
if shouldUseHandle {
rencentKeyHandledByKeyHandler = result
}
return result
/// commonEventHandler
/// IMK 便
return commonEventHandler(event)
}
/// App Ctrl+Enter / Shift+Enter
@ -282,34 +240,24 @@ class ctlInputMethod: IMKInputController {
override func candidates(_ sender: Any!) -> [Any]! {
_ = sender //
var arrResult = [String]()
//
func handleCandidatesPrepared(_ candidates: [(String, String)]) {
for theCandidate in candidates {
let theConverted = IME.kanjiConversionIfRequired(theCandidate.1)
var result = (theCandidate.1 == theConverted) ? theCandidate.1 : "\(theConverted)(\(theCandidate.1))"
if arrResult.contains(result) {
result = "\(result)(\(theCandidate.0))"
}
arrResult.append(result)
}
}
if let state = state as? InputState.AssociatedPhrases {
for theCandidate in state.candidates {
let theConverted = IME.kanjiConversionIfRequired(theCandidate.1)
var result = (theCandidate.1 == theConverted) ? theCandidate.1 : "\(theConverted)(\(theCandidate.1))"
if arrResult.contains(result) {
result = "\(result)(\(theCandidate.0))"
}
arrResult.append(result)
}
handleCandidatesPrepared(state.candidates)
} else if let state = state as? InputState.SymbolTable {
for theCandidate in state.candidates {
let theConverted = IME.kanjiConversionIfRequired(theCandidate.1)
var result = (theCandidate.1 == theConverted) ? theCandidate.1 : "\(theConverted)(\(theCandidate.1))"
if arrResult.contains(result) {
result = "\(result)(\(theCandidate.0))"
}
arrResult.append(result)
}
handleCandidatesPrepared(state.candidates)
} else if let state = state as? InputState.ChoosingCandidate {
for theCandidate in state.candidates {
let theConverted = IME.kanjiConversionIfRequired(theCandidate.1)
var result = (theCandidate.1 == theConverted) ? theCandidate.1 : "\(theConverted)(\(theCandidate.1))"
if arrResult.contains(result) {
result = "\(result)(\(theCandidate.0))"
}
arrResult.append(result)
}
handleCandidatesPrepared(state.candidates)
}
return arrResult
}
@ -337,37 +285,9 @@ class ctlInputMethod: IMKInputController {
}
var indexDeducted = 0
//
if let state = state as? InputState.AssociatedPhrases {
for (i, neta) in state.candidates.enumerated() {
let theConverted = IME.kanjiConversionIfRequired(neta.1)
let netaShown = (neta.1 == theConverted) ? neta.1 : "\(theConverted)(\(neta.1))"
let netaShownWithPronunciation = "\(theConverted)(\(neta.0))"
if candidateString.string == netaShownWithPronunciation {
indexDeducted = i
break
}
if candidateString.string == netaShown {
indexDeducted = i
break
}
}
} else if let state = state as? InputState.SymbolTable {
for (i, neta) in state.candidates.enumerated() {
let theConverted = IME.kanjiConversionIfRequired(neta.1)
let netaShown = (neta.1 == theConverted) ? neta.1 : "\(theConverted)(\(neta.1))"
let netaShownWithPronunciation = "\(theConverted)(\(neta.0))"
if candidateString.string == netaShownWithPronunciation {
indexDeducted = i
break
}
if candidateString.string == netaShown {
indexDeducted = i
break
}
}
} else if let state = state as? InputState.ChoosingCandidate {
for (i, neta) in state.candidates.enumerated() {
func handleCandidatesSelected(_ candidates: [(String, String)]) {
for (i, neta) in candidates.enumerated() {
let theConverted = IME.kanjiConversionIfRequired(neta.1)
let netaShown = (neta.1 == theConverted) ? neta.1 : "\(theConverted)(\(neta.1))"
let netaShownWithPronunciation = "\(theConverted)(\(neta.0))"
@ -381,6 +301,14 @@ class ctlInputMethod: IMKInputController {
}
}
}
if let state = state as? InputState.AssociatedPhrases {
handleCandidatesSelected(state.candidates)
} else if let state = state as? InputState.SymbolTable {
handleCandidatesSelected(state.candidates)
} else if let state = state as? InputState.ChoosingCandidate {
handleCandidatesSelected(state.candidates)
}
keyHandler(
keyHandler,
didSelectCandidateAt: indexDeducted,

View File

@ -54,64 +54,13 @@ extension ctlInputMethod: KeyHandlerDelegate {
extension ctlInputMethod: ctlCandidateDelegate {
var isAssociatedPhrasesMode: Bool { state is InputState.AssociatedPhrases }
/// handle() IMK
/// handle()
/// handle() IMK
/// handle()
/// IMK commonEventHandler()
/// - Parameter event: IMK
/// - Returns: `true` IMK`false`
func handleDelegateEvent(_ event: NSEvent!) -> Bool {
// Shift macOS 10.15 macOS
let shouldUseHandle =
(IME.arrClientShiftHandlingExceptionList.contains(clientBundleIdentifier)
|| mgrPrefs.shouldAlwaysUseShiftKeyAccommodation)
if #available(macOS 10.15, *) {
if ShiftKeyUpChecker.check(event), !mgrPrefs.disableShiftTogglingAlphanumericalMode {
if !shouldUseHandle || (!rencentKeyHandledByKeyHandler && shouldUseHandle) {
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Alphanumerical Mode", comment: ""), "\n",
toggleASCIIMode()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
)
)
}
if shouldUseHandle {
rencentKeyHandledByKeyHandler = false
}
return false
}
}
/// flags使 KeyHandler
/// flags
/// event.type == .flagsChanged return false
/// NSInternalInconsistencyException
if event.type == .flagsChanged { return false }
//
ctlInputMethod.areWeNerfing = event.modifierFlags.contains([.shift, .command])
var input = InputSignal(event: event, isVerticalTyping: isVerticalTyping)
input.isASCIIModeInput = isASCIIMode
//
// KeyHandler
if !input.charCode.isPrintable {
return false
}
/// 調
/// result bool IMK
/// keyHandler.handleCandidate()
let result = keyHandler.handle(input: input, state: state) { newState in
self.handle(state: newState)
} errorCallback: {
clsSFX.beep()
}
if shouldUseHandle {
rencentKeyHandledByKeyHandler = result
}
return result
@discardableResult func sharedEventHandler(_ event: NSEvent!) -> Bool {
commonEventHandler(event)
}
func candidateCountForController(_ controller: ctlCandidateProtocol) -> Int {

View File

@ -28,7 +28,7 @@ public class CandidateKeyLabel: NSObject {
public protocol ctlCandidateDelegate: AnyObject {
var isAssociatedPhrasesMode: Bool { get }
func handleDelegateEvent(_ event: NSEvent!) -> Bool
func sharedEventHandler(_ event: NSEvent!) -> Bool
func candidateCountForController(_ controller: ctlCandidateProtocol) -> Int
func candidatesForController(_ controller: ctlCandidateProtocol) -> [(String, String)]
func ctlCandidate(_ controller: ctlCandidateProtocol, candidateAtIndex index: Int)

View File

@ -249,7 +249,7 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
let input = InputSignal(event: event)
guard let delegate = delegate else { return }
if input.isEsc || input.isBackSpace || input.isDelete || (input.isShiftHold && !input.isSpace) {
_ = delegate.handleDelegateEvent(event)
_ = delegate.sharedEventHandler(event)
} else if input.isSymbolMenuPhysicalKey || input.isSpace {
if input.isShiftHold {
switch currentLayout {
@ -308,7 +308,7 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
!input.isCursorClockLeft, !input.isCursorClockRight, !input.isSpace,
!input.isEnter || !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter
{
_ = delegate.handleDelegateEvent(event)
_ = delegate.sharedEventHandler(event)
return
}
super.interpretKeyEvents(eventArray)

View File

@ -335,16 +335,23 @@ extension ctlPrefWindow: NSToolbarDelegate {
window.contentView?.addSubview(view)
}
var toolbarIdentifiers: [NSToolbarItem.Identifier] {
if #available(macOS 10.13, *) {
return [.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard, .ofDevZone]
}
return [.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard]
}
func toolbarDefaultItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {
[.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard, .ofDevZone]
toolbarIdentifiers
}
func toolbarAllowedItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {
[.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard, .ofDevZone]
toolbarIdentifiers
}
func toolbarSelectableItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {
[.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard, .ofDevZone]
toolbarIdentifiers
}
@objc func showGeneralView(_: Any?) {

View File

@ -38,6 +38,7 @@
5B62A34927AE7CD900A19448 /* TooltipController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A34327AE7CD900A19448 /* TooltipController.swift */; };
5B62A34A27AE7CD900A19448 /* NotifierController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A34527AE7CD900A19448 /* NotifierController.swift */; };
5B62A35327AE89C400A19448 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */; };
5B6C141228A9D4B30098ADF8 /* ctlInputMethod_Common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6C141128A9D4B30098ADF8 /* ctlInputMethod_Common.swift */; };
5B73FB5E27B2BE1300E9BF49 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5B73FB6027B2BE1300E9BF49 /* InfoPlist.strings */; };
5B782EC4280C243C007276DE /* KeyHandler_HandleCandidate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B782EC3280C243C007276DE /* KeyHandler_HandleCandidate.swift */; };
5B78EE0D28A562B4009456C1 /* suiPrefPaneDevZone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B78EE0C28A562B4009456C1 /* suiPrefPaneDevZone.swift */; };
@ -244,6 +245,7 @@
5B62A34327AE7CD900A19448 /* TooltipController.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = TooltipController.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
5B62A34527AE7CD900A19448 /* NotifierController.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = NotifierController.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
5B65B919284D0185007C558B /* README-CHT.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "README-CHT.md"; sourceTree = "<group>"; };
5B6C141128A9D4B30098ADF8 /* ctlInputMethod_Common.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ctlInputMethod_Common.swift; sourceTree = "<group>"; };
5B73FB5427B2BD6900E9BF49 /* PhraseEditor-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "PhraseEditor-Info.plist"; path = "UserPhraseEditor/PhraseEditor-Info.plist"; sourceTree = SOURCE_ROOT; };
5B73FB5F27B2BE1300E9BF49 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
5B782EC3280C243C007276DE /* KeyHandler_HandleCandidate.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = KeyHandler_HandleCandidate.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
@ -468,6 +470,7 @@
children = (
5B11328827B94CFB00E58451 /* AppleKeyboardConverter.swift */,
D4A13D5927A59D5C003BE359 /* ctlInputMethod_Core.swift */,
5B6C141128A9D4B30098ADF8 /* ctlInputMethod_Common.swift */,
5B21176F28753B9D000443A9 /* ctlInputMethod_Delegates.swift */,
5B21176D28753B35000443A9 /* ctlInputMethod_HandleDisplay.swift */,
5B21176B287539BB000443A9 /* ctlInputMethod_HandleStates.swift */,
@ -1188,6 +1191,7 @@
5BA9FD4327FEF3C8002DE248 /* Preferences.swift in Sources */,
5BA9FD4427FEF3C8002DE248 /* SegmentedControlStyleViewController.swift in Sources */,
5B78EE0D28A562B4009456C1 /* suiPrefPaneDevZone.swift in Sources */,
5B6C141228A9D4B30098ADF8 /* ctlInputMethod_Common.swift in Sources */,
D47F7DCE278BFB57002F9DD7 /* ctlPrefWindow.swift in Sources */,
5BD0113D2818543900609769 /* KeyHandler_Core.swift in Sources */,
5B2170E4289FACAD00BE7304 /* 2_Walker.swift in Sources */,