Merge pull request #271 from zonble/dev/tests

Adds unit test cases for the key handler
This commit is contained in:
Lukhnos Liu 2022-02-02 07:52:10 -08:00 committed by GitHub
commit 68732e6b15
8 changed files with 1106 additions and 169 deletions

View File

@ -60,6 +60,7 @@
D485D3B92796A8A000657FF3 /* PreferencesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D485D3B82796A8A000657FF3 /* PreferencesTests.swift */; };
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */; };
D4A13D5A27A59F0B003BE359 /* InputMethodController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A13D5927A59D5C003BE359 /* InputMethodController.swift */; };
D4A8E43627A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A8E43527A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift */; };
D4E33D8A27A838CF006DB1CF /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D4E33D8827A838CF006DB1CF /* Localizable.strings */; };
D4E33D8F27A838F0006DB1CF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D4E33D8D27A838F0006DB1CF /* InfoPlist.strings */; };
D4E569DC27A34D0E00AC2CEF /* KeyHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = D4E569DB27A34CC100AC2CEF /* KeyHandler.mm */; };
@ -218,6 +219,7 @@
D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionUpdateTests.swift; sourceTree = "<group>"; };
D495583A27A5C6C4006ADE1C /* LanguageModelManager+Privates.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LanguageModelManager+Privates.h"; sourceTree = "<group>"; };
D4A13D5927A59D5C003BE359 /* InputMethodController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputMethodController.swift; sourceTree = "<group>"; };
D4A8E43527A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyHandlerPlainBopomofoTests.swift; sourceTree = "<group>"; };
D4E33D8927A838CF006DB1CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
D4E33D8B27A838D5006DB1CF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
D4E33D8C27A838D8006DB1CF /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
@ -501,6 +503,7 @@
isa = PBXGroup;
children = (
D47D73A327A5D43900255A50 /* KeyHandlerBopomofoTests.swift */,
D4A8E43527A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift */,
D485D3B82796A8A000657FF3 /* PreferencesTests.swift */,
D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */,
);
@ -754,6 +757,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D4A8E43627A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift in Sources */,
D47D73A427A5D43900255A50 /* KeyHandlerBopomofoTests.swift in Sources */,
D485D3B92796A8A000657FF3 /* PreferencesTests.swift in Sources */,
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,203 @@
import XCTest
@testable import McBopomofo
class KeyHandlerPlainBopomofoTests: XCTestCase {
var handler = KeyHandler()
override func setUpWithError() throws {
LanguageModelManager.loadDataModels()
handler = KeyHandler()
handler.inputMode = .plainBopomofo
}
override func tearDownWithError() throws {
}
func testPunctuationTable() {
let input = KeyHandlerInput(inputText: "`", keyCode: 0, charCode: charCode("`"), flags: .shift, isVerticalMode: false)
var state: InputState = InputState.Empty()
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
XCTAssertTrue(state is InputState.ChoosingCandidate, "\(state)")
if let state = state as? InputState.ChoosingCandidate {
XCTAssertTrue(state.candidates.contains(""))
}
}
func testPunctuationComma() {
let enabled = Preferences.halfWidthPunctuationEnabled
Preferences.halfWidthPunctuationEnabled = false
let input = KeyHandlerInput(inputText: "<", keyCode: 0, charCode: charCode("<"), flags: .shift, isVerticalMode: false)
var state: InputState = InputState.Empty()
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
XCTAssertTrue(state is InputState.ChoosingCandidate, "\(state)")
if let state = state as? InputState.ChoosingCandidate {
XCTAssertEqual(state.composingBuffer, "")
}
Preferences.halfWidthPunctuationEnabled = enabled
}
func testPunctuationPeriod() {
let enabled = Preferences.halfWidthPunctuationEnabled
Preferences.halfWidthPunctuationEnabled = false
let input = KeyHandlerInput(inputText: ">", keyCode: 0, charCode: charCode(">"), flags: .shift, isVerticalMode: false)
var state: InputState = InputState.Empty()
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
XCTAssertTrue(state is InputState.ChoosingCandidate, "\(state)")
if let state = state as? InputState.ChoosingCandidate {
XCTAssertEqual(state.composingBuffer, "")
}
Preferences.halfWidthPunctuationEnabled = enabled
}
func testInputNe() {
let input = KeyHandlerInput(inputText: "s", keyCode: 0, charCode: charCode("s"), flags: .shift, isVerticalMode: false)
var state: InputState = InputState.Empty()
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
XCTAssertTrue(state is InputState.Inputting, "\(state)")
if let state = state as? InputState.Inputting {
XCTAssertEqual(state.composingBuffer, "")
}
}
func testInputNi() {
var state: InputState = InputState.Empty()
let keys = Array("su").map {
String($0)
}
for key in keys {
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
}
XCTAssertTrue(state is InputState.Inputting, "\(state)")
if let state = state as? InputState.Inputting {
XCTAssertEqual(state.composingBuffer, "ㄋㄧ")
}
}
func testInputNi3() {
var state: InputState = InputState.Empty()
let keys = Array("su3").map {
String($0)
}
for key in keys {
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
}
XCTAssertTrue(state is InputState.ChoosingCandidate, "\(state)")
if let state = state as? InputState.ChoosingCandidate {
XCTAssertTrue(state.candidates.contains(""))
}
}
func testCancelCandidateUsingDelete() {
var state: InputState = InputState.Empty()
let keys = Array("su3").map {
String($0)
}
for key in keys {
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
}
let input = KeyHandlerInput(inputText: " ", keyCode: KeyCode.delete.rawValue, charCode: 0, flags: [], isVerticalMode: false)
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
XCTAssertTrue(state is InputState.EmptyIgnoringPreviousState, "\(state)")
}
func testCancelCandidateUsingEsc() {
var state: InputState = InputState.Empty()
let keys = Array("su3").map {
String($0)
}
for key in keys {
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
}
let input = KeyHandlerInput(inputText: " ", keyCode: 0, charCode: 27, flags: [], isVerticalMode: false)
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
XCTAssertTrue(state is InputState.EmptyIgnoringPreviousState, "\(state)")
}
func testAssociatedPhrases() {
let enabled = Preferences.associatedPhrasesEnabled
Preferences.associatedPhrasesEnabled = true
var state: InputState = InputState.Empty()
let keys = Array("aul ").map {
String($0)
}
for key in keys {
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
}
XCTAssertTrue(state is InputState.AssociatedPhrases, "\(state)")
if let state = state as? InputState.AssociatedPhrases {
XCTAssertTrue(state.candidates.contains(""))
}
Preferences.associatedPhrasesEnabled = enabled
}
func testNoAssociatedPhrases() {
let enabled = Preferences.associatedPhrasesEnabled
Preferences.associatedPhrasesEnabled = false
var state: InputState = InputState.Empty()
let keys = Array("aul ").map {
String($0)
}
for key in keys {
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
}
XCTAssertTrue(state is InputState.Empty, "\(state)")
Preferences.associatedPhrasesEnabled = enabled
}
}

View File

@ -3,12 +3,37 @@ import XCTest
class PreferencesTests: XCTestCase {
func reset() {
Preferences.allKeys.forEach {
UserDefaults.standard.removeObject(forKey: $0)
}
}
func makeSnapshot() -> [String: Any] {
var dict = [String: Any]()
Preferences.allKeys.forEach {
dict[$0] = UserDefaults.standard.object(forKey: $0)
}
return dict
}
func restore(from snapshot:[String: Any]) {
Preferences.allKeys.forEach {
UserDefaults.standard.set(snapshot[$0], forKey: $0)
}
}
var snapshot: [String: Any]?
override func setUpWithError() throws {
Preferences.reset()
snapshot = makeSnapshot()
reset()
}
override func tearDownWithError() throws {
Preferences.reset()
if let snapshot = snapshot {
restore(from: snapshot)
}
}
func testKeyboardLayout() {

View File

@ -71,7 +71,7 @@ class McBopomofoInputMethodController: IMKInputController {
let halfWidthPunctuationItem = menu.addItem(withTitle: NSLocalizedString("Use Half-Width Punctuations", comment: ""), action: #selector(toggleHalfWidthPunctuation(_:)), keyEquivalent: "h")
halfWidthPunctuationItem.keyEquivalentModifierMask = [.command, .control]
halfWidthPunctuationItem.state = Preferences.chineseConversionEnabled.state
halfWidthPunctuationItem.state = Preferences.halfWidthPunctuationEnabled.state
let inputMode = keyHandler.inputMode
let optionKeyPressed = NSEvent.modifierFlags.contains(.option)
@ -181,9 +181,8 @@ class McBopomofoInputMethodController: IMKInputController {
let input = KeyHandlerInput(event: event, isVerticalMode: useVerticalMode)
let result = keyHandler.handle(input, state: state) { newState in
let result = keyHandler.handle(input: input, state: state) { newState in
self.handle(state: newState, client: client)
} candidateSelectionCallback: {
} errorCallback: {
NSSound.beep()
}
@ -575,7 +574,7 @@ extension McBopomofoInputMethodController: CandidateControllerDelegate {
if let state = state as? InputState.ChoosingCandidate {
let selectedValue = state.candidates[Int(index)]
keyHandler.fixNode(withValue: selectedValue)
keyHandler.fixNode(value: selectedValue)
guard let inputting = keyHandler.buildInputtingState() as? InputState.Inputting else {
return

View File

@ -45,11 +45,10 @@ extern InputMode InputModePlainBopomofo;
- (BOOL)handleInput:(KeyHandlerInput *)input
state:(InputState *)state
stateCallback:(void (^)(InputState *))stateCallback
candidateSelectionCallback:(void (^)(void))candidateSelectionCallback
errorCallback:(void (^)(void))errorCallback;
errorCallback:(void (^)(void))errorCallback NS_SWIFT_NAME(handle(input:state:stateCallback:errorCallback:));
- (void)syncWithPreferences;
- (void)fixNodeWithValue:(NSString *)value;
- (void)fixNodeWithValue:(NSString *)value NS_SWIFT_NAME(fixNode(value:));
- (void)clear;
- (InputState *)buildInputtingState;

View File

@ -219,7 +219,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
return layout;
}
- (BOOL)handleInput:(KeyHandlerInput *)input state:(InputState *)inState stateCallback:(void (^)(InputState *))stateCallback candidateSelectionCallback:(void (^)(void))candidateSelectionCallback errorCallback:(void (^)(void))errorCallback
- (BOOL)handleInput:(KeyHandlerInput *)input state:(InputState *)inState stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
InputState *state = inState;
UniChar charCode = input.charCode;
@ -278,12 +278,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
// MARK: Handle Candidates
if ([state isKindOfClass:[InputStateChoosingCandidate class]]) {
return [self _handleCandidateState:state input:input stateCallback:stateCallback candidateSelectionCallback:candidateSelectionCallback errorCallback:errorCallback];
return [self _handleCandidateState:state input:input stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Handle Associated Phrases
if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) {
BOOL result = [self _handleCandidateState:state input:input stateCallback:stateCallback candidateSelectionCallback:candidateSelectionCallback errorCallback:errorCallback];
BOOL result = [self _handleCandidateState:state input:input stateCallback:stateCallback errorCallback:errorCallback];
if (result) {
return YES;
}
@ -294,7 +294,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
// MARK: Handle Marking
if ([state isKindOfClass:[InputStateMarking class]]) {
InputStateMarking *marking = (InputStateMarking *) state;
if ([self _handleMarkingState:(InputStateMarking *) state input:input stateCallback:stateCallback candidateSelectionCallback:candidateSelectionCallback errorCallback:errorCallback]) {
if ([self _handleMarkingState:(InputStateMarking *) state input:input stateCallback:stateCallback errorCallback:errorCallback]) {
return YES;
}
state = [marking convertToInputting];
@ -371,8 +371,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
if (!Preferences.associatedPhrasesEnabled) {
InputStateEmpty *empty = [[InputStateEmpty alloc] init];
stateCallback(empty);
}
else {
} else {
InputStateAssociatedPhrases *associatedPhrases = (InputStateAssociatedPhrases *)[self buildAssociatePhraseStateWithKey:text useVerticalMode:input.useVerticalMode];
if (associatedPhrases) {
stateCallback(associatedPhrases);
@ -532,6 +531,10 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleEscWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
BOOL escToClearInputBufferEnabled = Preferences.escToCleanInputBuffer;
if (escToClearInputBufferEnabled) {
@ -547,15 +550,15 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
// Bopomofo reading, in odds with the expectation of users from
// other platforms
if (_bpmfReadingBuffer->isEmpty()) {
// no need to beep since the event is deliberately triggered by user
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
} else {
if (!_bpmfReadingBuffer->isEmpty()) {
_bpmfReadingBuffer->clear();
InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState];
stateCallback(inputting);
if (!_builder->length()) {
InputStateEmpty *empty = [[InputStateEmpty alloc] init];
stateCallback(empty);
} else {
InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState];
stateCallback(inputting);
}
}
}
return YES;
@ -563,16 +566,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleBackwardWithState:(InputState *)state input:(KeyHandlerInput *)input stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) {
errorCallback();
stateCallback(state);
return YES;
}
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
InputStateInputting *currentState = (InputStateInputting *) state;
if ([input isShiftHold]) {
@ -601,16 +604,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleForwardWithState:(InputState *)state input:(KeyHandlerInput *)input stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) {
errorCallback();
stateCallback(state);
return YES;
}
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
InputStateInputting *currentState = (InputStateInputting *) state;
if ([input isShiftHold]) {
@ -640,16 +643,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleHomeWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) {
errorCallback();
stateCallback(state);
return YES;
}
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (_builder->cursorIndex()) {
_builder->setCursorIndex(0);
InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState];
@ -664,16 +667,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleEndWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) {
errorCallback();
stateCallback(state);
return YES;
}
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (_builder->cursorIndex() != _builder->length()) {
_builder->setCursorIndex(_builder->length());
InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState];
@ -688,6 +691,10 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleAbsorbedArrowKeyWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) {
errorCallback();
}
@ -697,11 +704,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleBackspaceWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if (_bpmfReadingBuffer->isEmpty()) {
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (_bpmfReadingBuffer->isEmpty()) {
if (_builder->cursorIndex()) {
_builder->deleteReadingBeforeCursor();
[self _walk];
@ -714,11 +721,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
_bpmfReadingBuffer->backspace();
}
InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState];
if (!inputting.composingBuffer.length) {
if (!_builder->length()) {
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
stateCallback(empty);
} else {
InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState];
stateCallback(inputting);
}
return YES;
@ -726,11 +733,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleDeleteWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if (_bpmfReadingBuffer->isEmpty()) {
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (_bpmfReadingBuffer->isEmpty()) {
if (_builder->cursorIndex() != _builder->length()) {
_builder->deleteReadingAfterCursor();
[self _walk];
@ -755,26 +762,26 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleEnterWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
{
if ([state isKindOfClass:[InputStateInputting class]]) {
if (_inputMode == InputModePlainBopomofo) {
if (!_bpmfReadingBuffer->isEmpty()) {
errorCallback();
}
return YES;
if (![state isKindOfClass:[InputStateInputting class]]) {
return NO;
}
if (_inputMode == InputModePlainBopomofo) {
if (!_bpmfReadingBuffer->isEmpty()) {
errorCallback();
}
[self clear];
InputStateInputting *current = (InputStateInputting *) state;
NSString *composingBuffer = current.composingBuffer;
InputStateCommitting *committing = [[InputStateCommitting alloc] initWithPoppedText:composingBuffer];
stateCallback(committing);
InputStateEmpty *empty = [[InputStateEmpty alloc] init];
stateCallback(empty);
return YES;
}
return NO;
[self clear];
InputStateInputting *current = (InputStateInputting *) state;
NSString *composingBuffer = current.composingBuffer;
InputStateCommitting *committing = [[InputStateCommitting alloc] initWithPoppedText:composingBuffer];
stateCallback(committing);
InputStateEmpty *empty = [[InputStateEmpty alloc] init];
stateCallback(empty);
return YES;
}
- (BOOL)_handlePunctuation:(string)customPunctuation state:(InputState *)state usingVerticalMode:(BOOL)useVerticalMode stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
@ -817,7 +824,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleMarkingState:(InputStateMarking *)state
input:(KeyHandlerInput *)input
stateCallback:(void (^)(InputState *))stateCallback
candidateSelectionCallback:(void (^)(void))candidateSelectionCallback
errorCallback:(void (^)(void))errorCallback
{
UniChar charCode = input.charCode;
@ -877,7 +883,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
- (BOOL)_handleCandidateState:(InputState *)state
input:(KeyHandlerInput *)input
stateCallback:(void (^)(InputState *))stateCallback
candidateSelectionCallback:(void (^)(void))candidateSelectionCallback
errorCallback:(void (^)(void))errorCallback;
{
NSString *inputText = input.inputText;
@ -919,7 +924,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
if (!updated) {
errorCallback();
}
candidateSelectionCallback();
return YES;
}
@ -928,7 +932,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
if (!updated) {
errorCallback();
}
candidateSelectionCallback();
return YES;
}
@ -944,7 +947,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
errorCallback();
}
}
candidateSelectionCallback();
return YES;
}
@ -953,7 +955,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
if (!updated) {
errorCallback();
}
candidateSelectionCallback();
return YES;
}
@ -969,7 +970,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
errorCallback();
}
}
candidateSelectionCallback();
return YES;
}
@ -978,7 +978,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
if (!updated) {
errorCallback();
}
candidateSelectionCallback();
return YES;
}
@ -994,7 +993,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
errorCallback();
}
}
candidateSelectionCallback();
return YES;
}
@ -1010,7 +1008,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
errorCallback();
}
}
candidateSelectionCallback();
return YES;
}
@ -1021,7 +1018,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
gCurrentCandidateController.selectedCandidateIndex = 0;
}
candidateSelectionCallback();
return YES;
}
@ -1043,8 +1039,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
} else {
gCurrentCandidateController.selectedCandidateIndex = candidates.count - 1;
}
candidateSelectionCallback();
return YES;
}
@ -1112,14 +1106,13 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
[self clear];
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
stateCallback(empty);
[self handleInput:input state:empty stateCallback:stateCallback candidateSelectionCallback:candidateSelectionCallback errorCallback:errorCallback];
[self handleInput:input state:empty stateCallback:stateCallback errorCallback:errorCallback];
}
return YES;
}
}
errorCallback();
candidateSelectionCallback();
return YES;
}

View File

@ -198,29 +198,29 @@ struct ComposingBufferSize {
// MARK: -
class Preferences: NSObject {
static func reset() {
let defaults = UserDefaults.standard
defaults.removeObject(forKey: kKeyboardLayoutPreferenceKey)
defaults.removeObject(forKey: kBasisKeyboardLayoutPreferenceKey)
defaults.removeObject(forKey: kFunctionKeyKeyboardLayoutPreferenceKey)
defaults.removeObject(forKey: kFunctionKeyKeyboardLayoutOverrideIncludeShiftKey)
defaults.removeObject(forKey: kCandidateListTextSizeKey)
defaults.removeObject(forKey: kSelectPhraseAfterCursorAsCandidatePreferenceKey)
defaults.removeObject(forKey: kUseHorizontalCandidateListPreferenceKey)
defaults.removeObject(forKey: kComposingBufferSizePreferenceKey)
defaults.removeObject(forKey: kChooseCandidateUsingSpaceKey)
defaults.removeObject(forKey: kChineseConversionEnabledKey)
defaults.removeObject(forKey: kHalfWidthPunctuationEnabledKey)
defaults.removeObject(forKey: kEscToCleanInputBufferKey)
defaults.removeObject(forKey: kCandidateTextFontName)
defaults.removeObject(forKey: kCandidateKeyLabelFontName)
defaults.removeObject(forKey: kCandidateKeys)
defaults.removeObject(forKey: kPhraseReplacementEnabledKey)
defaults.removeObject(forKey: kChineseConversionEngineKey)
defaults.removeObject(forKey: kChineseConversionStyle)
defaults.removeObject(forKey: kAssociatedPhrasesEnabledKey)
static var allKeys:[String] {
[kKeyboardLayoutPreferenceKey,
kBasisKeyboardLayoutPreferenceKey,
kFunctionKeyKeyboardLayoutPreferenceKey,
kFunctionKeyKeyboardLayoutOverrideIncludeShiftKey,
kCandidateListTextSizeKey,
kSelectPhraseAfterCursorAsCandidatePreferenceKey,
kUseHorizontalCandidateListPreferenceKey,
kComposingBufferSizePreferenceKey,
kChooseCandidateUsingSpaceKey,
kChineseConversionEnabledKey,
kHalfWidthPunctuationEnabledKey,
kEscToCleanInputBufferKey,
kCandidateTextFontName,
kCandidateKeyLabelFontName,
kCandidateKeys,
kPhraseReplacementEnabledKey,
kChineseConversionEngineKey,
kChineseConversionStyle,
kAssociatedPhrasesEnabledKey]
}
@UserDefault(key: kKeyboardLayoutPreferenceKey, defaultValue: 0)
@objc static var keyboardLayout: Int