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

fix(block-tunes): enter keydown problems #2650

Merged
merged 7 commits into from
Mar 13, 2024
Merged

fix(block-tunes): enter keydown problems #2650

merged 7 commits into from
Mar 13, 2024

Conversation

neSpecc
Copy link
Member

@neSpecc neSpecc commented Mar 9, 2024

Right now we have several problems with Enter keydown.

Unexpected new line on Enter press with selected block without caret

The problem can be reproduced when there is no caret set, but the block is selected.

new-line-bug.mov

Since there is no caret in a Block, the Ui.ts module's enterKeydown is involved. We call BlockManager.insert() and Caret.setToBlock(), but we're not calling the event.preventDefault() to disable default "Enter" behaviour. There was no problem until the 2.29 because there was a delay between block adding and caret setting. This delay was removed by #2570 — now block addition follows by immediate focusing so Enter handler ends with caret in a new block and default behaviour (a linebreak) is happening.

Solution

Addition of event.preventDefault() after block insertion resolves the issue.

Autofocus loosing after Block Tunes opening.

Block Tunes have autofocus on search field. But the caret disappears in a moment:

cursor-loosing.mov

After the focusing of the search field, the ui.ts@selectionChanged() callback is called. It checks if isCrossBlockSelectionStarted() to remove all ranges.

The problem was in the isCrossBlockSelectionStarted() it was treating the single selected block as a CBS. The requestAnimationFrame in input focusing was redundant and just hides the problem.

Block removing while Enter press on Block Tunes

It is related to the previous problem: after caret loosing, the enterKeydown !Selection.isSelectionExists leads us to the BlockSelection.clearSelection(event); where block was deleting.

block-deletion.mov

Fix #2637

* but by default cypress' KeyboardEvent is not an instance of the native KeyboardEvent,
* so real-world and Cypress behaviour were different.
*
* To make it work we need to trigger Cypres event with "eventConstructor: 'KeyboardEvent'",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* To make it work we need to trigger Cypres event with "eventConstructor: 'KeyboardEvent'",
* To make it work we need to trigger Cypress event with "eventConstructor: 'KeyboardEvent'",

@neSpecc neSpecc merged commit ee64332 into next Mar 13, 2024
6 checks passed
@neSpecc neSpecc deleted the fix/enter branch March 13, 2024 14:30
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.

Remove block on SP with keyboard
3 participants