Skip to content

Commit

Permalink
fix: 修复中文输入模式下,空格和回车失效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertyyb committed Oct 28, 2020
1 parent aaa0662 commit 14c9103
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions Fire/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
InputSource.shared.activateInputSource()
NSApp.terminate(nil)
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
private func commandHandler() {
if CommandLine.arguments.count > 1 {
print("[Fire] launch argument: \(CommandLine.arguments[1])")
let command = CommandLine.arguments[1]
Expand All @@ -34,6 +34,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return NSApp.terminate(nil)
}
}
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
commandHandler()
if !hasDict() {
NSLog("[Fire] first run,build dict")
buildDict()
Expand Down
8 changes: 4 additions & 4 deletions Fire/FireInputController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class FireInputController: IMKInputController {
if let attributes = attrs as? [NSAttributedString.Key: Any] {
var selected = self._originalString
if Defaults[.showCodeInWindow] {
selected = self._originalString.count > 1 ? " " : ""
selected = self._originalString.count > 0 ? " " : ""
}
let text = NSAttributedString(string: selected, attributes: attributes)
client()?.setMarkedText(text, selectionRange: selectionRange(), replacementRange: replacementRange())
Expand Down Expand Up @@ -164,7 +164,7 @@ class FireInputController: IMKInputController {
// 获取输入的字符
let string = event.characters!
// 当前输入的是数字,选择当前候选列表中的第N个字符 v
if let pos = Int(string) {
if let pos = Int(string), _originalString.count > 0 {
let index = pos - 1
let candidates = self.getCandidates(self)
if index < candidates.count {
Expand All @@ -180,7 +180,7 @@ class FireInputController: IMKInputController {

private func enterKeyHandler(event: NSEvent) -> Bool? {
// 回车键输入原字符
if event.keyCode == kVK_Return {
if event.keyCode == kVK_Return && _originalString.count > 0 {
// 插入原字符
_composedString = _originalString
insertText(self)
Expand All @@ -191,7 +191,7 @@ class FireInputController: IMKInputController {

private func spaceKeyHandler(event: NSEvent) -> Bool? {
// 空格键输入转换后的中文字符
if event.keyCode == kVK_Space {
if event.keyCode == kVK_Space && _originalString.count > 0 {
if let first = self.getCandidates(self).first {
_composedString = first.text
insertText(self)
Expand Down

0 comments on commit 14c9103

Please sign in to comment.