fix: block copy using settings button #2851
Open
+4
−1
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.
Block copy (CMD + C) via settings button is broken in recent editorjs releases.
After debugging, I found the issue is related to this logic:
editor.js/src/components/utils/popover/popover-abstract.ts
Lines 121 to 123 in 6313409
It tries to focus the search input in the popover, but it won't work.
We need to wrap it with
requestAnimationFrame
.The old logic did the same:
editor.js/src/components/utils/popover/index.ts
Lines 239 to 243 in e9b4c30
Why does this matter?
I found the answer after debugging both the old version and the latest version.
When a keydown event is detected on the document listener, it tries to decide if the event happens inside the editor element by:
editor.js/src/components/modules/ui.ts
Line 501 in 6313409
Since the popover does not manage to get the focus on the search element, so when we press
CMD + C
with the popover is showing, theevent.target
is actuallydocument
itself. SokeyDownOnEditor
is null.When
keyDownOnEditor === null
:editor.js/src/components/modules/ui.ts
Lines 507 to 511 in 6313409
It will call
this.Editor.BlockEvents.keydown(event)
, which willclose
the popover andunselectBlock
.editor.js/src/components/modules/toolbar/blockSettings.ts
Lines 184 to 186 in 6313409
So we won't have a selected block any more when we do the keydown event handling later.
This PR fixs this issue by making the focus on the search element actually work again when we click the settings button.