fix(block-tunes): enter keydown problems #2650
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 callBlockManager.insert()
andCaret.setToBlock()
, but we're not calling theevent.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 ifisCrossBlockSelectionStarted()
to remove all ranges.The problem was in the
isCrossBlockSelectionStarted()
it was treating the single selected block as a CBS. TherequestAnimationFrame
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 theBlockSelection.clearSelection(event);
where block was deleting.block-deletion.mov
Fix #2637