KeyHandler // Swiftifying "buildAssociatePhraseStateWithKey".

This commit is contained in:
ShikiSuen 2022-04-19 14:49:11 +08:00
parent e45ed48ef4
commit 8e0b9fac22
5 changed files with 24 additions and 21 deletions

View File

@ -59,8 +59,6 @@ struct BufferStatePackage
- (void)fixNodeWithValue:(NSString *)value NS_SWIFT_NAME(fixNode(value:)); - (void)fixNodeWithValue:(NSString *)value NS_SWIFT_NAME(fixNode(value:));
- (void)clear; - (void)clear;
- (nullable InputState *)buildAssociatePhraseStateWithKey:(NSString *)key useVerticalMode:(BOOL)useVerticalMode;
@property(strong, nonatomic) InputMode inputMode; @property(strong, nonatomic) InputMode inputMode;
@property(weak, nonatomic) id<KeyHandlerDelegate> delegate; @property(weak, nonatomic) id<KeyHandlerDelegate> delegate;

View File

@ -421,15 +421,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
return array; return array;
} }
- (nullable InputState *)buildAssociatePhraseStateWithKey:(NSString *)key useVerticalMode:(BOOL)useVerticalMode
{
NSArray<NSString *> *array = [self buildAssociatePhraseArrayWithKey:key];
if (array == nil || [array count] == 0)
return nil;
else
return [[InputStateAssociatedPhrases alloc] initWithCandidates:array useVerticalMode:useVerticalMode];
}
#pragma mark - 必須用 ObjCpp 處理的部分: Mandarin #pragma mark - 必須用 ObjCpp 處理的部分: Mandarin
- (BOOL)chkKeyValidity:(UniChar)charCode - (BOOL)chkKeyValidity:(UniChar)charCode

View File

@ -201,12 +201,12 @@ import Cocoa
if !mgrPrefs.associatedPhrasesEnabled { if !mgrPrefs.associatedPhrasesEnabled {
stateCallback(InputState.Empty()) stateCallback(InputState.Empty())
} else { } else {
let associatedPhrases = if let associatedPhrases =
buildAssociatePhraseState( buildAssociatePhraseState(
withKey: text, withKey: text,
useVerticalMode: input.useVerticalMode useVerticalMode: input.useVerticalMode
) as? InputState.AssociatedPhrases ), !associatedPhrases.candidates.isEmpty
if let associatedPhrases = associatedPhrases { {
stateCallback(associatedPhrases) stateCallback(associatedPhrases)
} else { } else {
stateCallback(InputState.Empty()) stateCallback(InputState.Empty())

View File

@ -32,7 +32,7 @@ import Cocoa
// MARK: - State Building // MARK: - State Building
func buildInputtingState() -> InputState.Inputting { func buildInputtingState() -> InputState.Inputting {
// //
packageBufferStateMaterials() packageBufferStateMaterials()
// //
let composedText = getComposedText() let composedText = getComposedText()
@ -63,7 +63,7 @@ import Cocoa
return newState return newState
} }
// MARK: - // MARK: -
func _buildCandidateState( func _buildCandidateState(
_ currentState: InputState.NotEmpty, _ currentState: InputState.NotEmpty,
@ -80,7 +80,23 @@ import Cocoa
return state return state
} }
// MARK: - // MARK: -
// buildAssociatePhraseStateWithKey
// 使
// ObjC buildAssociatePhraseArray
// String Swift
// nil
//
//
func buildAssociatePhraseState(
withKey key: String!,
useVerticalMode: Bool
) -> InputState.AssociatedPhrases! {
//  Xcode
return InputState.AssociatedPhrases(
candidates: buildAssociatePhraseArray(withKey: key), useVerticalMode: useVerticalMode)
}
// MARK: - // MARK: -

View File

@ -626,8 +626,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
if mgrPrefs.associatedPhrasesEnabled, if mgrPrefs.associatedPhrasesEnabled,
let associatePhrases = keyHandler.buildAssociatePhraseState( let associatePhrases = keyHandler.buildAssociatePhraseState(
withKey: composingBuffer, useVerticalMode: state.useVerticalMode withKey: composingBuffer, useVerticalMode: state.useVerticalMode
) ), !associatePhrases.candidates.isEmpty
as? InputState.AssociatedPhrases
{ {
handle(state: associatePhrases, client: client) handle(state: associatePhrases, client: client)
} else { } else {
@ -645,8 +644,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
if mgrPrefs.associatedPhrasesEnabled, if mgrPrefs.associatedPhrasesEnabled,
let associatePhrases = keyHandler.buildAssociatePhraseState( let associatePhrases = keyHandler.buildAssociatePhraseState(
withKey: selectedValue, useVerticalMode: state.useVerticalMode withKey: selectedValue, useVerticalMode: state.useVerticalMode
) ), !associatePhrases.candidates.isEmpty
as? InputState.AssociatedPhrases
{ {
handle(state: associatePhrases, client: client) handle(state: associatePhrases, client: client)
} else { } else {