Skip to content

Commit

Permalink
add pageUp and pageDown support
Browse files Browse the repository at this point in the history
  • Loading branch information
lennylxx committed Feb 3, 2022
1 parent c518ee8 commit 7714295
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
58 changes: 50 additions & 8 deletions GoogleInputTools/GoogleInputToolsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,25 @@ class GoogleInputToolsController: IMKInputController {
}

override func activateServer(_ sender: Any!) {
NSLog("\(#function)(\(sender))")
super.activateServer(sender)
guard let client = sender as? IMKTextInput else {
return
}

NSLog("\(#function)(\(client))")

client.overrideKeyboard(withKeyboardNamed: "com.apple.keylayout.US")
}

override func deactivateServer(_ sender: Any) {
NSLog("\(#function)(\(sender))")
guard let client = sender as? IMKTextInput else {
return
}

NSLog("\(#function)(\(client))")

InputContext.shared.clean()
self.candidates.update()
self.candidates.hide()

super.deactivateServer(sender)
}

func getAndRenderCandidates(_ compString: String) {
Expand All @@ -66,7 +73,10 @@ class GoogleInputToolsController: IMKInputController {
}

func updateCandidatesWindow() {
NSLog("\(#function)")

let compString = InputContext.shared.composeString
NSLog("compString=\(compString)")

// set text at cursor
let range = NSMakeRange(NSNotFound, NSNotFound)
Expand All @@ -75,7 +85,7 @@ class GoogleInputToolsController: IMKInputController {
if UISettings.SystemUI {
if compString.count > 0 {
self.getAndRenderCandidates(compString)
self.candidates.show()
self.candidates.show(kIMKLocateCandidatesBelowHint)
} else {
self.candidates.hide()
}
Expand Down Expand Up @@ -146,19 +156,39 @@ class GoogleInputToolsController: IMKInputController {
let candidate = candidateString?.string ?? ""
let id = InputContext.shared.candidates.firstIndex(of: candidate) ?? 0

NSLog("candidate index: \(id)")
NSLog("candidate=\(candidate), index=\(id)")
InputContext.shared.currentIndex = id
commitCandidate(client: self.client())
}

override func candidateSelectionChanged(_ candidateString: NSAttributedString!) {
NSLog("\(#function)")

let candidate = candidateString?.string ?? ""
let id = InputContext.shared.candidates.firstIndex(of: candidate) ?? 0

NSLog("candidate=\(candidate), index=\(id)")
InputContext.shared.currentIndex = id
}

override func commitComposition(_ sender: Any!) {
NSLog("\(#function)")
}

override func updateComposition() {
NSLog("\(#function)")
}

override func cancelComposition() {
NSLog("\(#function)")
}

override func selectionRange() -> NSRange {
NSLog("\(#function)")

return NSMakeRange(NSNotFound, NSNotFound)
}

override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
NSLog("%@", event)

Expand Down Expand Up @@ -215,6 +245,16 @@ class GoogleInputToolsController: IMKInputController {
return true
}

else if event.keyCode == kVK_ANSI_Equal {
self.candidates.pageDown(sender)
return true
}

else if event.keyCode == kVK_ANSI_Minus {
self.candidates.pageUp(sender)
return true
}

else if event.keyCode == kVK_Delete && InputContext.shared.composeString.count > 0 {
InputContext.shared.composeString.removeLast()
updateCandidatesWindow()
Expand All @@ -238,7 +278,9 @@ class GoogleInputToolsController: IMKInputController {
self.candidates.update()
self.candidates.hide()
return true
} else {
}

else {
commitComposedString(client: sender)
return false
}
Expand Down
2 changes: 2 additions & 0 deletions GoogleInputTools/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SwiftUI
let connectionName = "GoogleInputTools_Connection"
let bundleId = Bundle.main.bundleIdentifier!

NSLog("creating IMK server")
let server = IMKServer(name: connectionName, bundleIdentifier: bundleId)

NSLog("NSApplication run")
NSApplication.shared.run()
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ A *cloud* input method that uses [Google Input Tools](https://www.google.com/inp
## Progress

- [x] Basic input handling logic
- [x] `Space` key to commit first candidate
- [x] `Space` key to commit current highlighted candidate
- [x] `Return` key to ignore candidate and commit input string
- [x] Number keys (`1`-`9`) to select candidate and commit
- [x] Continue to show new candidates after partial matched candidate is selected and committed
- [x] `Backspace` key to remove last composing letter
- [x] `Esc` key to cancel composing
- [ ] `-` and `=` keys to page up and page down candidate list respectively
- [x] System UI
- [x] Basic custom UI
- [x] Numbered candidates
Expand Down

0 comments on commit 7714295

Please sign in to comment.