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

BUGFIX: Properly pause mousetrap during inline editing #3498

Merged
merged 1 commit into from
Jun 3, 2023

Conversation

grebaldi
Copy link
Contributor

fixes: #3099

The problem

We have a Hotkeys saga that initializes a Mousetrap (see: https://www.npmjs.com/package/mousetrap). The saga does so once for the host frame. For the guest frame it then initializes a separate Mousetrap every time, a document has been loaded.

In theory this should ensure that keyboard shortcuts work both in the host and in the guest frame. There's one specific scenario though in which we do not want keyboard shortcuts to work at all and that is: inline editing (basically, because typing something into CKEditor would otherwise trigger all kinds of unintended actions).

This is why the Hotkeys saga tracks a mousetrapPaused flag. The idea is to pause the mousetrap every time the content canvas signals that there's inline editing going on:

if (action.type === actionTypes.UI.ContentCanvas.SET_CURRENTLY_EDITED_PROPERTY_NAME) {
mousetrapPaused = action.payload.propertyName !== '';
}

#3099 describes that the hot keys do not work inside the guest frame at all. I found that this is due to mousetrapPaused always being true.

Looking at the declaration of the action creator for SET_CURRENTLY_EDITED_PROPERTY_NAME:

const setCurrentlyEditedPropertyName = (propertyName: string) => createAction(actionTypes.SET_CURRENTLY_EDITED_PROPERTY_NAME, propertyName);

I could see that the payload for SET_CURRENTLY_EDITED_PROPERTY_NAME is not an object with a key propertyName, but a string that represents just the property name. So, the condition action.payload.propertyName !== '' is always true, because action.payload.propertyName is always undefined.

The solution

I changed the condition for mousetrapPaused to

mousetrapPaused = action.payload !== '';

to match the intended semantics with the action creator definition for SET_CURRENTLY_EDITED_PROPERTY_NAME. Now keyboard shortcuts work as intended in the guest frame, but are ignored if there's inline editing going on.

@grebaldi grebaldi linked an issue May 22, 2023 that may be closed by this pull request
@github-actions github-actions bot added Bug Label to mark the change as bugfix 7.3 labels May 22, 2023
Copy link
Member

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

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

Thank you for this well written description and fix ❤️

seems like a classic js refactoring bug ^^

@crydotsnake crydotsnake merged commit 735bbfe into neos:7.3 Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7.3 Bug Label to mark the change as bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: shorcuts/hotkeys dont work in guest-iframe
3 participants