Skip to content
Permalink
Browse files

Merge pull request #539 from youknowone/fix-vi-mode

Fix vi-mode escape not to be processed by imk
  • Loading branch information...
youknowone committed Jun 1, 2019
2 parents 0cb1065 + 49b7065 commit 99e8c6c384da3af05ae7d1e46a7845159e5598e8
@@ -206,6 +206,7 @@ class GureumTests: XCTestCase {
}

func testBackQuoteHan2() {
Configuration.shared.hangulWonCurrencySymbolForBackQuote = true
for app in apps {
app.client.string = ""
app.controller.setValue(GureumInputSourceIdentifier.han2.rawValue, forTag: kTextServiceInputModePropertyTag, client: app.client)
@@ -219,6 +220,7 @@ class GureumTests: XCTestCase {
}

func testBackQuoteOnComposing() {
Configuration.shared.hangulWonCurrencySymbolForBackQuote = true
for app in apps {
app.client.string = ""
app.controller.setValue(GureumInputSourceIdentifier.han2.rawValue, forTag: kTextServiceInputModePropertyTag, client: app.client)
@@ -515,7 +517,7 @@ class GureumTests: XCTestCase {
}
}

func testEscapeOrCtrlAndLeftBracketHan3Gureum() {
func testViModeEscape() {
XCTAssertFalse(Configuration.shared.romanModeByEscapeKey)
Configuration.shared.romanModeByEscapeKey = true
for app in apps {
@@ -525,7 +527,25 @@ class GureumTests: XCTestCase {
app.inputKey(kVK_ANSI_M)
XCTAssertEqual("", app.client.string, "buffer: \(app.client.string) app: \(app)")

app.inputKey(kVK_ANSI_LeftBracket, modifiers: [.control])
let processed = app.inputKey(kVK_Escape)
XCTAssertFalse(processed)
XCTAssertEqual("", app.client.string, "buffer: \(app.client.string) app: \(app)")
XCTAssertTrue(app.controller.receiver.composer.inputMode.hasSuffix("qwerty"))
}
}

func testViModeCtrlAndLeftBracket() {
XCTAssertFalse(Configuration.shared.romanModeByEscapeKey)
Configuration.shared.romanModeByEscapeKey = true
for app in apps {
app.client.string = ""
app.controller.setValue(GureumInputSourceIdentifier.han3FinalNoShift.rawValue, forTag: kTextServiceInputModePropertyTag, client: app.client)

app.inputKey(kVK_ANSI_M)
XCTAssertEqual("", app.client.string, "buffer: \(app.client.string) app: \(app)")

let processed = app.inputKey(kVK_ANSI_LeftBracket, modifiers: [.control])
XCTAssertFalse(processed)
XCTAssertEqual("", app.client.string, "buffer: \(app.client.string) app: \(app)")
XCTAssertTrue(app.controller.receiver.composer.inputMode.hasSuffix("qwerty"))

@@ -34,10 +34,12 @@ class VirtualApp: NSObject {

@discardableResult
func inputKey(_ keyCode: Int, modifiers flags: NSEvent.ModifierFlags = NSEvent.ModifierFlags(rawValue: 0)) -> Bool {
assert(keyCode <= 0x33) // use inputText:key:modifiers:
var string = KeyMapLower[keyCode]
if !flags.intersection([.shift]).isEmpty {
string = KeyMapUpper[keyCode]
var string: String?
if keyCode <= 0x33 {
string = KeyMapLower[keyCode]
if !flags.intersection([.shift]).isEmpty {
string = KeyMapUpper[keyCode]
}
}
return inputText(string, key: keyCode, modifiers: flags)
}
@@ -48,7 +50,7 @@ class ModerateApp: VirtualApp {
let processed = super.inputText(string, key: keyCode, modifiers: flags)
let specialFlags = flags.intersection([.command, .control])

if !processed, specialFlags.isEmpty {
if !processed, specialFlags.isEmpty, string != nil {
client.insertText(string, replacementRange: client.markedRange())
}
return processed
@@ -236,7 +236,7 @@ class GureumComposer: DelegatedComposer {
// Handle SpecialKeyCode first
let inputKey = (UInt(keyCode), inputModifier)
if let shortcutKey = configuration.inputModeExchangeKey, shortcutKey == inputKey {
return .changeLayout(.toggle)
return .changeLayout(.toggle, true)
}
// else if (self.delegate == self->hangulComposer && inputModifier == CIMSharedConfiguration->inputModeEnglishKeyModifier && keyCode == CIMSharedConfiguration->inputModeEnglishKeyCode) {
// dlog(DEBUG_SHORTCUT, @"**** Layout exchange by change to english shortcut ****");
@@ -247,7 +247,7 @@ class GureumComposer: DelegatedComposer {
// need_exchange = YES;
// }
if let shortcutKey = configuration.inputModeHanjaKey, shortcutKey == inputKey {
return .changeLayout(.hanja)
return .changeLayout(.hanja, true)
}

if (delegate as? HanjaComposer) === hanjaComposer {
@@ -268,7 +268,7 @@ class GureumComposer: DelegatedComposer {
// Vi-mode: esc로 로마자 키보드로 전환
if Configuration.shared.romanModeByEscapeKey {
if keyCode == kVK_Escape || (keyCode, inputModifier) == (kVK_ANSI_LeftBracket, NSEvent.ModifierFlags.control) {
return .changeLayout(.roman)
return .changeLayout(.roman, false)
}
}
}
@@ -43,7 +43,7 @@ enum ChangeLayout {
}

enum InputEvent {
case changeLayout(ChangeLayout)
case changeLayout(ChangeLayout, Bool)
}

@objc(GureumInputController)
@@ -130,7 +130,7 @@ public extension InputController { // IMKServerInputHandleEvent
if changed.contains(.capsLock), Configuration.shared.enableCapslockToToggleInputMode {
if InputMethodServer.shared.io.capsLockTriggered {
dlog(DEBUG_IOKIT_EVENT, "controller detected capslock")
_ = receiver.input(event: .changeLayout(.toggleByCapsLock), client: client)
_ = receiver.input(event: .changeLayout(.toggleByCapsLock, true), client: client)
} else {
(sender as! IMKTextInput).selectMode(receiver.composer.inputMode)
}
@@ -296,7 +296,7 @@ public extension InputController { // IMKServerInput
public extension MockInputController { // IMKServerInputTextData
func inputFlags(_: Int, client sender: Any) -> Bool {
let client = asClient(sender)
let result = receiver.input(event: .changeLayout(.toggle), client: client)
let result = receiver.input(event: .changeLayout(.toggle, true), client: client)
if !result.processed {
// [self cancelComposition]
}
@@ -128,7 +128,7 @@ public class InputReceiver: InputTextDelegate {

func input(event: InputEvent, client sender: IMKTextInput & IMKUnicodeTextInput) -> InputResult {
switch event {
case let .changeLayout(layout):
case let .changeLayout(layout, processed):
let innerLayout = layout == .toggleByCapsLock ? .toggle : layout
let result = composer.changeLayout(innerLayout, client: sender)
// 합성 후보가 있다면 보여준다
@@ -150,7 +150,7 @@ public class InputReceiver: InputTextDelegate {

inputting = false

return .processed
return processed ? .processed : .notProcessed
}
return .notProcessed
}

0 comments on commit 99e8c6c

Please sign in to comment.
You can’t perform that action at this time.