NSEventImpl // Again fix NSInternalInconsistencyException issue.
This commit is contained in:
parent
965008fb7f
commit
cfad082b14
|
@ -27,14 +27,18 @@ public extension NSEvent? {
|
||||||
public extension NSEvent {
|
public extension NSEvent {
|
||||||
var copyAsKBEvent: KBEvent? {
|
var copyAsKBEvent: KBEvent? {
|
||||||
guard let typeKB = type.toKB else { return nil }
|
guard let typeKB = type.toKB else { return nil }
|
||||||
|
// NSEvent 只是個外表皮,裡面有好幾個影子 class。
|
||||||
|
// 不是所有的影子 class 都有「characters」和「isARepeated」。
|
||||||
|
// 貿然存取的話,會觸發 NSInternalInconsistencyException。
|
||||||
|
// 已知 FlagsChanged 類型的事件是如此,那就對這個類型做例外處理。
|
||||||
return .init(
|
return .init(
|
||||||
with: typeKB,
|
with: typeKB,
|
||||||
modifierFlags: modifierFlags.toKB,
|
modifierFlags: modifierFlags.toKB,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
windowNumber: windowNumber,
|
windowNumber: windowNumber,
|
||||||
characters: characters,
|
characters: typeKB != .flagsChanged ? characters : nil,
|
||||||
charactersIgnoringModifiers: charactersIgnoringModifiers,
|
charactersIgnoringModifiers: typeKB != .flagsChanged ? charactersIgnoringModifiers : nil,
|
||||||
isARepeat: isARepeat,
|
isARepeat: typeKB != .flagsChanged ? isARepeat : nil,
|
||||||
keyCode: keyCode
|
keyCode: keyCode
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue