Repo // Preparing for IMK Candidate implementation.

This commit is contained in:
ShikiSuen 2022-07-31 21:31:20 +08:00
parent 7ea221f7ec
commit 40d3382564
4 changed files with 53 additions and 5 deletions

View File

@ -29,7 +29,7 @@ import Cocoa
// InputState 使 Struct Struct // InputState 使 Struct Struct
// enum // enum
enum StateType { public enum StateType {
case ofDeactivated case ofDeactivated
case ofAssociatedPhrases case ofAssociatedPhrases
case ofEmpty case ofEmpty
@ -43,7 +43,7 @@ enum StateType {
} }
// InputState // InputState
protocol InputStateProtocol { public protocol InputStateProtocol {
var type: StateType { get } var type: StateType { get }
} }
@ -79,7 +79,7 @@ protocol InputStateProtocol {
/// ///
/// - .ChoosingCandidate: 使 /// - .ChoosingCandidate: 使
/// - .SymbolTable: /// - .SymbolTable:
enum InputState { public enum InputState {
/// .Deactivated: 使使 /// .Deactivated: 使使
class Deactivated: InputStateProtocol { class Deactivated: InputStateProtocol {
public var type: StateType { .ofDeactivated } public var type: StateType { .ofDeactivated }

View File

@ -46,7 +46,7 @@ protocol KeyHandlerDelegate {
// MARK: - (Kernel). // MARK: - (Kernel).
/// KeyHandler 調 /// KeyHandler 調
class KeyHandler { public class KeyHandler {
/// ///
let kEpsilon: Double = 0.000001 let kEpsilon: Double = 0.000001
/// ///

View File

@ -24,7 +24,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import Foundation import Cocoa
// MARK: - KeyHandler Delegate // MARK: - KeyHandler Delegate
@ -70,6 +70,53 @@ extension ctlInputMethod: KeyHandlerDelegate {
// MARK: - Candidate Controller Delegate // MARK: - Candidate Controller Delegate
extension ctlInputMethod: ctlCandidateDelegate { extension ctlInputMethod: ctlCandidateDelegate {
func handleDelegateEvent(_ event: NSEvent!) -> Bool {
/// flags使 KeyHandler
/// flags
/// event.type == .flagsChanged return false
/// NSInternalInconsistencyException
if event.type == .flagsChanged {
return false
}
// Enter
ctlInputMethod.areWeDeleting = event.modifierFlags.contains([.shift, .command])
var textFrame = NSRect.zero
let attributes: [AnyHashable: Any]? = client().attributes(
forCharacterIndex: 0, lineHeightRectangle: &textFrame
)
let isTypingVertical =
(attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false
if client().bundleIdentifier()
== "org.atelierInmu.vChewing.vChewingPhraseEditor"
{
IME.areWeUsingOurOwnPhraseEditor = true
} else {
IME.areWeUsingOurOwnPhraseEditor = false
}
let input = InputSignal(event: event, isVerticalTyping: isTypingVertical)
//
// KeyHandler
if !input.charCode.isPrintable {
return false
}
/// 調
/// result bool IMK
let result = keyHandler.handleCandidate(state: state, input: input) { newState in
self.handle(state: newState)
} errorCallback: {
clsSFX.beep()
}
return result
}
func candidateCountForController(_ controller: ctlCandidateProtocol) -> Int { func candidateCountForController(_ controller: ctlCandidateProtocol) -> Int {
_ = controller // _ = controller //
if let state = state as? InputState.ChoosingCandidate { if let state = state as? InputState.ChoosingCandidate {

View File

@ -43,6 +43,7 @@ public class CandidateKeyLabel: NSObject {
} }
public protocol ctlCandidateDelegate: AnyObject { public protocol ctlCandidateDelegate: AnyObject {
func handleDelegateEvent(_ event: NSEvent!) -> Bool
func candidateCountForController(_ controller: ctlCandidateProtocol) -> Int func candidateCountForController(_ controller: ctlCandidateProtocol) -> Int
func candidatesForController(_ controller: ctlCandidateProtocol) -> [(String, String)] func candidatesForController(_ controller: ctlCandidateProtocol) -> [(String, String)]
func ctlCandidate(_ controller: ctlCandidateProtocol, candidateAtIndex index: Int) func ctlCandidate(_ controller: ctlCandidateProtocol, candidateAtIndex index: Int)