Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix so that modifiers are not reflected in non-alphabetic keys #58

Merged
merged 1 commit into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Lib/Magnet/Extensions/KeyExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,37 @@ public extension Key {
return false
}
}
var isAlphabet: Bool {
switch self {
case .a,
.b,
.c,
.d,
.e,
.f,
.g,
.h,
.i,
.j,
.k,
.l,
.m,
.n,
.o,
.p,
.q,
.r,
.s,
.t,
.u,
.v,
.w,
.x,
.y,
.z:
return true
default:
return false
}
}
}
6 changes: 4 additions & 2 deletions Lib/Magnet/KeyCombo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public final class KeyCombo: NSObject, NSCopying, NSCoding, Codable {
}
public var keyEquivalent: String {
guard !doubledModifiers else { return "" }
let modifiers = self.modifiers.convertSupportCocoaModifiers().filterNotShiftModifiers().carbonModifiers()
return Sauce.shared.character(by: Int(Sauce.shared.keyCode(by: key)), carbonModifiers: modifiers) ?? ""
let keyCode = Int(Sauce.shared.keyCode(by: key))
guard key.isAlphabet else { return Sauce.shared.character(by: keyCode, cocoaModifiers: []) ?? "" }
let modifiers = self.modifiers.convertSupportCocoaModifiers().filterNotShiftModifiers()
return Sauce.shared.character(by: keyCode, cocoaModifiers: modifiers) ?? ""
}
public var keyEquivalentModifierMask: NSEvent.ModifierFlags {
return modifiers.convertSupportCocoaModifiers()
Expand Down
2 changes: 1 addition & 1 deletion Lib/MagnetTests/KeyComboTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class KeyComboTests: XCTestCase {
keyCombo = KeyCombo(key: .a, cocoaModifiers: [.option, .shift])
XCTAssertEqual(keyCombo?.keyEquivalent, "A")
keyCombo = KeyCombo(key: .one, cocoaModifiers: [.option, .shift])
XCTAssertEqual(keyCombo?.keyEquivalent, "!")
XCTAssertEqual(keyCombo?.keyEquivalent, "1")
keyCombo = KeyCombo(key: .semicolon, cocoaModifiers: [.option])
XCTAssertEqual(keyCombo?.keyEquivalent, ";")
keyCombo = KeyCombo(key: .f1, cocoaModifiers: [.shift])
Expand Down