mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 06:43:24 +03:00
GH-543 Add an NSEvent.MofifierFlags extension for (left, right) modifiers.
This commit is contained in:
parent
96518391ad
commit
69116676e7
@ -49,48 +49,17 @@ extension NSView {
|
||||
}
|
||||
}
|
||||
|
||||
extension NSEvent {
|
||||
extension NSEvent.ModifierFlags {
|
||||
|
||||
struct Modifier: OptionSet {
|
||||
|
||||
let rawValue: UInt
|
||||
|
||||
// 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
|
||||
)
|
||||
// @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
|
||||
}
|
||||
// Values are from https://github.com/SFML/SFML/blob/master/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm
|
||||
// @formatter:off
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user