Skip to content
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

Intenational key binding fixes #234

Merged
merged 18 commits into from
Jan 26, 2024
Merged

Conversation

MrStashley
Copy link

@MrStashley MrStashley commented Jan 17, 2024

This PR creates a new function in the global model for checking key presses, and it creates a special key press syntax

An example of this syntax: if you want to check for ctrl + shift + e, you would write "ctrl:shift:e"

We also now use event.key instead of event.code for checking key presses
There are a lot of considerations here
Event.key changes depending on modifiers - if user presses shift + e, event.key = "E" and if user pre sses option + e, on Mac event.key = "´"

I have handled the shift case, basically any of the above work - "Shift:e" == "Shift:E" == "E"
The option case however is still around, not sure how to go about handling that one
For now option keys aren't really going to work
I guess the way is to go by event code rather than key, but then people have to write their option commands with different syntax, ie "Alt:KeyR" rather than "Alt:r"
We could also do some string conversions on the event code, like we can map "KeyR" to "r", and a lot of the non character keys like "Escape" or "Enter" or "ArrowDown" are the same both key and code. There will be a few special cases though, like "[" = "LeftBracket"

or we can just roll with the punches and make users do "Alt:®" for Alt + r (this is how it is working right now), or maybe there's a tool out there for finding the un optioned version of an option key

@@ -232,59 +232,59 @@ class TextAreaInput extends React.Component<{ screen: Screen; onHeightChange: ()
}
inputModel.closeAIAssistantChat();
return;
}
if (e.code == "KeyE" && e.getModifierState("Meta")) {
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I call this meta instead of command?

@MrStashley MrStashley marked this pull request as ready for review January 17, 2024 01:10
@MrStashley MrStashley changed the title Mr stashley add check key press function Intenational key binding fixes Jan 17, 2024
@sawka
Copy link
Member

sawka commented Jan 17, 2024

I think your CopyFile code got merged into this PR somehow?

e.preventDefault();
inputModel.resetInput();
return;
}
if (
e.code == "KeyR" &&
(e.getModifierState("Meta") || e.getModifierState("Control")) &&
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some or key bindings here
I feel like we should make these either Ctrl or Cmd, rather than both

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should just be control?
Looking at this though I understand why or is used here since it's a really important command

MrStashley and others added 15 commits January 23, 2024 15:02
Adds job status indicators that will show any updates to running commands while you are focused away from a tab. These will show up as status icons in the tab view.

These indicators will reset for a given tab when you focus back to it.

I've updated the inner formatting of the tab to use flexboxes, allowing the title to display more text when there are no icons to display.

Also includes some miscellaneous for-loop pattern improvements in model.ts and removing of unused variables, etc.

---------

Co-authored-by: sawka <[email protected]>
@MrStashley MrStashley force-pushed the MrStashley-add-checkKeyPress-function branch from 635f5dc to 202ee84 Compare January 23, 2024 23:37
@@ -95,29 +96,33 @@ function formatSessionName(snames: Record<string, string>, sessionId: string): s
}

@mobxReact.observer
class HistoryCheckbox extends React.Component<{ checked: boolean, partialCheck?: boolean, onClick?: () => void }, {}> {
class HistoryCheckbox extends React.Component<{ checked: boolean; partialCheck?: boolean; onClick?: () => void }, {}> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier related changes, not rebase artifacts I'm pretty sure

e.preventDefault();
e.stopPropagation();
inputModel.closeAIAssistantChat();
}
if (e.code == "KeyL" && e.getModifierState("Control")) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove space here
Idk what is your thought on spacing?
Apple was super strict on spacing inside of functions for some reason, so I'm hardwired to get rid of them


function parseKeyDescription(keyDescription: string): KeyPressDecl {
let rtn = { key: "", mods: {} } as KeyPressDecl;
rtn.mods.Cmd = false;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ugly to init this way? wasn't sure how to properly init a record type
seems I have to set each of the values otherwise they end up as none

}
let eventKey = event.key;
let descKey = keyPress.key;
if (eventKey.length == 1 && /[A-Z]/.test(eventKey.charAt(0))) {
Copy link
Author

@MrStashley MrStashley Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this accepts shift:e, shift:E or E all as the same thing
it also accepts "Space" or " " to mean space
Thoughts?

Also I'm wondering if I should move this logic to the adapt keyboard event functions so that WaveKeyboardEvent has a standardized key value in these cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add unicode checks in here. instead of checking for [A-Z] you can use \p{Lu} (unicode uppercase characters). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape . I think you also need to set the v flag on the regexp.

see also https://unicode.org/reports/tr18/#General_Category_Property

@sawka
Copy link
Member

sawka commented Jan 25, 2024

For event.key, I think space bar actually comes back as " " and not "Space" . https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values#whitespace_keys


type ModKeyStrs = "Cmd" | "Option" | "Shift" | "Ctrl";

interface WaveKeyboardEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe cut down the number of lines of comments here. since they are single line, just use //

@sawka
Copy link
Member

sawka commented Jan 25, 2024

I think for WaveKeyboardEvent, it shouldn't have cmd. You should just set alt and meta from the keyboard events so WaveKeyboardEvent always matches the native event.

put the special cmd logic in the check function. also better since that logic will then only live in once place instead of multiple.

@sawka sawka merged commit 0648d48 into main Jan 26, 2024
4 checks passed
@MrStashley MrStashley deleted the MrStashley-add-checkKeyPress-function branch February 15, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants