Prevent an exception from being thrown #2205
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
I recently noticed some exceptions in my system log originating from QS. I've put a few examples in a gist: https://gist.github.com/mattbeshara/b07bef9bca8662d4e8e2d3c6ce306bb7
The cause seems to be that sometimes when I have the search window open, QS isn't getting the type of NSEvent it expects from [NSApp currentEvent]. A couple of "SysDefined" events sometimes occur where the code only expects either NSKeyDown or NSKeyUp events. I don't know what those unexpected events are, what triggers them, or when they occur, so I don't know how to reproduce this for those specific events. The code checks that the function key is held down before calling [NSEvent isARepeat], but I don't know what relationship that may have with the non-key events it's getting.
Getting the exception thrown is reproducible though, by causing another kind of unhandled event to occur. Open the search window, type a letter to cause an object to appear in the first pane if there isn't one there already, position the mouse cursor over the icon in the first pane, hold the function key, and scroll with a mouse or trackpad.
To prevent that exception from being thrown, this patch checks that an event is a valid key event before calling isARepeat on it.