KeyHandler // Swiftifying "buildAssociatePhraseStateWithKey".

This commit is contained in:
ShikiSuen 2022-04-19 14:49:11 +08:00
parent 0cdf0020c1
commit 4145c15920
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)clear;
- (nullable InputState *)buildAssociatePhraseStateWithKey:(NSString *)key useVerticalMode:(BOOL)useVerticalMode;
@property(strong, nonatomic) InputMode inputMode;
@property(weak, nonatomic) id<KeyHandlerDelegate> delegate;

View File

@ -421,15 +421,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
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
- (BOOL)chkKeyValidity:(UniChar)charCode

View File

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

View File

@ -32,7 +32,7 @@ import Cocoa
// MARK: - State Building
func buildInputtingState() -> InputState.Inputting {
//
//
packageBufferStateMaterials()
//
let composedText = getComposedText()
@ -63,7 +63,7 @@ import Cocoa
return newState
}
// MARK: -
// MARK: -
func _buildCandidateState(
_ currentState: InputState.NotEmpty,
@ -80,7 +80,23 @@ import Cocoa
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: -

View File

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