Merge branch 'master' of github.com:openvanilla/McBopomofo
This commit is contained in:
commit
e9707b5427
|
@ -60,6 +60,7 @@
|
|||
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */; };
|
||||
D4A13D5A27A59F0B003BE359 /* InputMethodController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A13D5927A59D5C003BE359 /* InputMethodController.swift */; };
|
||||
D4C9CAB127AAC9690058DFEA /* NSStringUtils in Frameworks */ = {isa = PBXBuildFile; productRef = D4C9CAB027AAC9690058DFEA /* NSStringUtils */; };
|
||||
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 */; };
|
||||
|
@ -186,6 +187,7 @@
|
|||
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>"; };
|
||||
D4C9CAAF27AAC8EC0058DFEA /* NSStringUtils */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = NSStringUtils; path = Packages/NSStringUtils; 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>"; };
|
||||
|
@ -430,6 +432,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
D47D73A327A5D43900255A50 /* KeyHandlerBopomofoTests.swift */,
|
||||
D4A8E43527A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift */,
|
||||
D485D3B82796A8A000657FF3 /* PreferencesTests.swift */,
|
||||
D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */,
|
||||
);
|
||||
|
@ -683,6 +686,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
|
@ -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
|
||||
}
|
||||
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -218,7 +218,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;
|
||||
|
@ -277,12 +277,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;
|
||||
}
|
||||
|
@ -293,7 +293,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];
|
||||
|
@ -370,8 +370,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);
|
||||
|
@ -531,6 +530,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) {
|
||||
|
@ -546,32 +549,32 @@ 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();
|
||||
if (!_builder->length()) {
|
||||
InputStateEmpty *empty = [[InputStateEmpty alloc] init];
|
||||
stateCallback(empty);
|
||||
} else {
|
||||
InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState];
|
||||
stateCallback(inputting);
|
||||
}
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (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]) {
|
||||
|
@ -600,16 +603,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]) {
|
||||
|
@ -639,16 +642,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];
|
||||
|
@ -663,16 +666,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];
|
||||
|
@ -687,6 +690,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();
|
||||
}
|
||||
|
@ -696,11 +703,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 (_bpmfReadingBuffer->isEmpty()) {
|
||||
if (_builder->cursorIndex()) {
|
||||
_builder->deleteReadingBeforeCursor();
|
||||
[self _walk];
|
||||
|
@ -713,11 +720,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;
|
||||
|
@ -725,11 +732,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 (_bpmfReadingBuffer->isEmpty()) {
|
||||
if (_builder->cursorIndex() != _builder->length()) {
|
||||
_builder->deleteReadingAfterCursor();
|
||||
[self _walk];
|
||||
|
@ -754,7 +761,10 @@ 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 (![state isKindOfClass:[InputStateInputting class]]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (_inputMode == InputModePlainBopomofo) {
|
||||
if (!_bpmfReadingBuffer->isEmpty()) {
|
||||
errorCallback();
|
||||
|
@ -773,9 +783,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)_handlePunctuation:(string)customPunctuation state:(InputState *)state usingVerticalMode:(BOOL)useVerticalMode stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
|
||||
{
|
||||
if (!_languageModel->hasUnigramsForKey(customPunctuation)) {
|
||||
|
@ -816,7 +823,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;
|
||||
|
@ -876,7 +882,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;
|
||||
|
@ -918,7 +923,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
if (!updated) {
|
||||
errorCallback();
|
||||
}
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -927,7 +931,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
if (!updated) {
|
||||
errorCallback();
|
||||
}
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -943,7 +946,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
errorCallback();
|
||||
}
|
||||
}
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -952,7 +954,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
if (!updated) {
|
||||
errorCallback();
|
||||
}
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -968,7 +969,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
errorCallback();
|
||||
}
|
||||
}
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -977,7 +977,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
if (!updated) {
|
||||
errorCallback();
|
||||
}
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -993,7 +992,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
errorCallback();
|
||||
}
|
||||
}
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -1009,7 +1007,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
errorCallback();
|
||||
}
|
||||
}
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -1020,7 +1017,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
gCurrentCandidateController.selectedCandidateIndex = 0;
|
||||
}
|
||||
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -1042,8 +1038,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
} else {
|
||||
gCurrentCandidateController.selectedCandidateIndex = candidates.count - 1;
|
||||
}
|
||||
|
||||
candidateSelectionCallback();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -1111,14 +1105,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue