1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 14:52:19 +03:00

GH-543 Add an NSEvent.MofifierFlags extension for (left, right) modifiers.

This commit is contained in:
Tae Won Ha 2018-04-05 08:45:15 +02:00
parent 96518391ad
commit 69116676e7
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -49,48 +49,17 @@ extension NSView {
}
}
extension NSEvent {
struct Modifier: OptionSet {
let rawValue: UInt
extension NSEvent.ModifierFlags {
// Values are from https://github.com/SFML/SFML/blob/master/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm
// @formatter:off
static let rightShift = Modifier(rawValue: 0x020004)
static let leftShift = Modifier(rawValue: 0x020002)
static let rightCommand = Modifier(rawValue: 0x100010)
static let leftCommand = Modifier(rawValue: 0x100008)
static let rightOption = Modifier(rawValue: 0x080040)
static let leftOption = Modifier(rawValue: 0x080020)
static let rightControl = Modifier(rawValue: 0x042000)
static let leftControl = Modifier(rawValue: 0x040001)
static let shift = Modifier(rawValue: NSEvent.ModifierFlags.shift.rawValue)
static let command = Modifier(rawValue: NSEvent.ModifierFlags.command.rawValue)
static let option = Modifier(rawValue: NSEvent.ModifierFlags.option.rawValue)
static let control = Modifier(rawValue: NSEvent.ModifierFlags.control.rawValue)
static let all: Array<Modifier> = Array(arrayLiteral:
.rightShift, .leftShift, .rightCommand, .leftCommand, .rightOption, .leftOption, .rightControl, .leftControl,
.shift, .command, .option, .control
)
static let rightShift = NSEvent.ModifierFlags(rawValue: 0x020004)
static let leftShift = NSEvent.ModifierFlags(rawValue: 0x020002)
static let rightCommand = NSEvent.ModifierFlags(rawValue: 0x100010)
static let leftCommand = NSEvent.ModifierFlags(rawValue: 0x100008)
static let rightOption = NSEvent.ModifierFlags(rawValue: 0x080040)
static let leftOption = NSEvent.ModifierFlags(rawValue: 0x080020)
static let rightControl = NSEvent.ModifierFlags(rawValue: 0x042000)
static let leftControl = NSEvent.ModifierFlags(rawValue: 0x040001)
// @formatter:on
}
var modifiers: Modifier {
var result: Modifier = []
Modifier.all
.compactMap { modifier in
if (self.modifierFlags.rawValue & modifier.rawValue) == modifier.rawValue {
return modifier
}
return nil
}
.forEach { result.insert($0) }
return result
}
}