-
-
Notifications
You must be signed in to change notification settings - Fork 49
+semver:minor Added KeysExtensions class with the IsNavigationKey ext… #1437
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
Changes from all commits
a7d36ab
4242a32
15943d9
d3b08dc
1b05a19
7e1b808
3fd4c1a
a33ccff
218fd90
e0e9186
dab5ab2
e195a13
0645374
ab9ba40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using System.Windows.Forms; | ||
|
|
||
| namespace SIL.Windows.Forms.Extensions | ||
| { | ||
| public static class KeysExtensions | ||
| { | ||
| /// <summary> | ||
| /// Determines whether the specified key is considered a navigation key. | ||
| /// </summary> | ||
| /// <param name="key">The key (or key-combination) to examine.</param> | ||
| /// <param name="ctrlPressed">If <c>true</c>, the letter <c>Keys.A</c> will be treated as a | ||
| /// navigation key (even if the <paramref name="key"/> value does not explicitly include | ||
| /// <c>Keys.Control</c>). In contexts where Ctrl-A is not a shortcut for Select All or that | ||
| /// behavior is not relevant, pass false or omit this optional parameter.</param> | ||
| /// <remarks>If <paramref name="key"/> represents the combination Ctrl-A (i.e., | ||
| /// <c>Keys.Control | Keys.A</c>), but <paramref name="ctrlPressed"/> is <c>false</c>, | ||
| /// this method will return <c>false</c>.</remarks> | ||
| public static bool IsNavigationKey(this Keys key, bool ctrlPressed = false) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 IsNavigationKey's ctrlPressed parameter design is unconventional The Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👎The current design is correct, and Devin's suggested alternative would introduce a real bug. Here's the issue with the "infer from the key value" approach:
Different call sites have different semantics for Ctrl+A. When used (later) in Transcelerator, it will be called as |
||
| { | ||
| switch (key & Keys.KeyCode) | ||
| { | ||
| case Keys.Left: | ||
| case Keys.Up: | ||
| case Keys.Down: | ||
| case Keys.Right: | ||
| case Keys.Home: | ||
| case Keys.End: | ||
| case Keys.PageDown: | ||
| case Keys.PageUp: | ||
| return true; | ||
| case Keys.A: | ||
| return ctrlPressed; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.