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

initial logic for hotkey refactoring #1537

Merged
merged 8 commits into from
Sep 13, 2023

Conversation

sergzak022
Copy link
Collaborator

No description provided.

*
* @class
*/
export class HotkeyListener {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated HotkeyListener to enable support for multiple active scopes

@github-actions
Copy link

github-actions bot commented Aug 25, 2023

Unit Test Results

0 tests  ±0   0 ✔️ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ±0 

Results for commit d778a04. ± Comparison against base commit 38d12c6.

♻️ This comment has been updated with latest results.

@@ -589,14 +594,25 @@ export default Vue.extend({
if (this.enabled_edit_schema == true) {
this.edit_ui_schema()
}
this.hotkey_listener = HotkeyListener.getInstance()

this.hotkey_listener.addFilter(() => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey @anthony-sarkis , please note that I added hotkey_listener.addFilter method that allows us to use current logic (the one that updates this.$store.state.user.is_typing_or_menu_open), to control firing of the hotkey handlers. Please see HotkeyListener definition for more details.

},
beforeDestroy() {
this.hotkey_manager.deactivate()
window.removeEventListener(
"resize",
this.update_window_size_from_listener
);

this.hotkey_listener.clear()
this.hotkey_listener.restoreDefaultFilters()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hotkey_listener.restoreDefaultFilters remove all the filters that we added via hotkey_listener.addFilter and restores default filtering logic provided by hotkey-js library. The default logic I'm talking about prevents hotkeys from firing if user is focused on some input filed (input, textarea, etc) or element that has contenteditable (docs) set.

@@ -185,7 +185,6 @@
in order for the canvas render to detect it -->

<div
contenteditable="true"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please note that I removed contenteditable (docs) from the div element that wraps the main canvas. The reason I did this is that it was preventing hotkey-js from firing hotkey handlers. This happens because hotkey-js has the code (see bellow) that checks isContentEditable property to determine if should fire hotkey handler. My other option was to change hotkey-js filter logic, but I decided to remove contenteditable property because I didn't see how it can be used in this context. Specifically, contenteditable allows editing of the text inside html elements (like divs), but it does not look like we edit any text like that in the div container for the canvas element. This change makes the overall design simplier. Please let me know if I'm wrong and I'll be happy to just update hotkey-js filter.

const target = event.target || event.srcElement;
        const { tagName } = target;
          let flag = true;
          // ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select>
          if (
            target.isContentEditable
            || ((tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') && !target.readOnly)
          ) {
            flag = ture
          }

* Add a filter. The filter should return `true` if the event should be processed, and `false` otherwise.
* @param filter - The filter function to add.
*/
addFilter(filter: (event: KeyboardEvent) => boolean) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated HotkeyListener to enable support for custom filters that prevent hotkey handlers (callbacks) from firing.

this.toggle_file_change_left()
})

this.hotkey_listener.onKeyup({ keys: 'right,d', scope: 'image' }, (event, handler) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

More hotkeys are using HotkeyListener

@@ -1725,6 +1732,10 @@ export default Vue.extend({
}
this.mounted();

this.hotkeyListenerScope = `image ${this.working_file.hash}`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using image ${this.working_file.hash} as a hotkeys scope identifier

this.hotkey_listener.removeFilter(this.hotkeyListenerFilter)
},

hotkeyListenerFilter() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Local hotkeys filter

@@ -1733,6 +1744,159 @@ export default Vue.extend({
},
// TODO 312 Methods!! refactor in multiple files and classes.
methods: {

cleanUpHotkeys(scope) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added method to clean up hotkeys local filter and scope event handlers

}
})

this.hotkey_listener.onKeyup({ keys: 'ctrl+a,ctrl+left', scope }, () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ctrl+left, ctrl+right don't work on my Mac so also added ctrl+a, ctrl+d hotkeyes

@sergzak022 sergzak022 merged commit 0276a27 into diffgram:master Sep 13, 2023
4 of 7 checks passed
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.

None yet

1 participant