InputState // Rewrite documentation in Chinese.

This commit is contained in:
ShikiSuen 2022-06-15 23:17:13 +08:00
parent 305c919bec
commit d2da05a267
1 changed files with 62 additions and 50 deletions

View File

@ -28,39 +28,40 @@ import Cocoa
// InputState 使 Struct Struct
/// Represents the states for the input method controller.
/// ctlInputMethod
///
/// An input method is actually a finite state machine. It receives the inputs
/// from hardware like keyboard and mouse, changes its state, updates user
/// interface by the state, and finally produces the text output and then them
/// to the client apps. It should be a one-way data flow, and the user interface
/// and text output should follow unconditionally one single data source.
/// Finite State Machine/
/// 使
/// 使
///
///
/// The InputState class is for representing what the input controller is doing,
/// and the place to store the variables that could be used. For example, the
/// array for the candidate list is useful only when the user is choosing a
/// candidate, and the array should not exist when the input controller is in
/// another state.
/// InputState
/// 使
///
///
///
/// They are immutable objects. When the state changes, the controller should
/// create a new state object to replace the current state instead of modifying
/// the existing one.
/// InputState
/// InputState.Marking InputState.Inputting
///
///
/// The input controller has following possible states:
///
///
/// - Deactivated: The user is not using the input method yet.
/// - Empty: The user has switched to this input method but inputted nothing yet,
/// or, he or she has committed text into the client apps and starts a new
/// input phase.
/// - Committing: The input controller is sending text to the client apps.
/// - Inputting: The user has inputted something and the input buffer is
/// visible.
/// - Marking: The user is creating a area in the input buffer and about to
/// create a new user phrase.
/// - Choosing Candidate: The candidate window is open to let the user to choose
/// one among the candidates.
/// - .Deactivated: 使使
/// - .AssociatedPhrases:
/// 西 .NotEmpty
/// - .Empty: 使
///
/// - .EmptyIgnorePreviousState: Empty
///
/// - .Committing:
/// - .NotEmpty:
/// - .Inputting: 使Compositor
/// - .Marking: 使
///
/// - .ChoosingCandidate: 使
/// - .SymbolTable:
class InputState {
/// Represents that the input controller is deactivated.
/// .Deactivated: 使使
class Deactivated: InputState {
var description: String {
"<InputState.Deactivated>"
@ -69,7 +70,8 @@ class InputState {
// MARK: -
/// Represents that the composing buffer is empty.
/// .Empty: 使
///
class Empty: InputState {
var composingBuffer: String {
""
@ -82,7 +84,8 @@ class InputState {
// MARK: -
/// Represents that the composing buffer is empty.
/// .EmptyIgnorePreviousState: Empty
///
class EmptyIgnoringPreviousState: Empty {
override var description: String {
"<InputState.EmptyIgnoringPreviousState>"
@ -91,7 +94,7 @@ class InputState {
// MARK: -
/// Represents that the input controller is committing text into client app.
/// .Committing:
class Committing: InputState {
private(set) var poppedText: String = ""
@ -107,7 +110,30 @@ class InputState {
// MARK: -
/// Represents that the composing buffer is not empty.
/// .AssociatedPhrases:
/// 西 .NotEmpty
class AssociatedPhrases: InputState {
private(set) var candidates: [String] = []
private(set) var isTypingVertical: Bool = false
init(candidates: [String], isTypingVertical: Bool) {
self.candidates = candidates
self.isTypingVertical = isTypingVertical
super.init()
}
var description: String {
"<InputState.AssociatedPhrases, candidates:\(candidates), isTypingVertical:\(isTypingVertical)>"
}
}
// MARK: -
/// .NotEmpty:
/// - .Inputting: 使Compositor
/// - .Marking: 使
///
/// - .ChoosingCandidate: 使
/// - .SymbolTable:
class NotEmpty: InputState {
private(set) var composingBuffer: String
private(set) var cursorIndex: Int = 0 { didSet { cursorIndex = max(cursorIndex, 0) } }
@ -136,7 +162,7 @@ class InputState {
// MARK: -
/// Represents that the user is inputting text.
/// .Inputting: 使Compositor
class Inputting: NotEmpty {
var poppedText: String = ""
var tooltip: String = ""
@ -152,7 +178,8 @@ class InputState {
// MARK: -
/// Represents that the user is marking a range in the composing buffer.
/// .Marking: 使
///
class Marking: NotEmpty {
private var allowedMarkRange: ClosedRange<Int> = mgrPrefs.minCandidateLength...mgrPrefs.maxCandidateLength
private(set) var markerIndex: Int = 0 { didSet { markerIndex = max(markerIndex, 0) } }
@ -316,7 +343,7 @@ class InputState {
// MARK: -
/// Represents that the user is choosing in a candidates list.
/// .ChoosingCandidate: 使
class ChoosingCandidate: NotEmpty {
private(set) var candidates: [String]
private(set) var isTypingVertical: Bool
@ -334,22 +361,7 @@ class InputState {
// MARK: -
/// Represents that the user is choosing in a candidates list
/// in the associated phrases mode.
class AssociatedPhrases: InputState {
private(set) var candidates: [String] = []
private(set) var isTypingVertical: Bool = false
init(candidates: [String], isTypingVertical: Bool) {
self.candidates = candidates
self.isTypingVertical = isTypingVertical
super.init()
}
var description: String {
"<InputState.AssociatedPhrases, candidates:\(candidates), isTypingVertical:\(isTypingVertical)>"
}
}
/// .SymbolTable:
class SymbolTable: ChoosingCandidate {
var node: SymbolNode