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

Prevent duplicated event dispatching #1381

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2.20

- `Fix` - Prevented duplicated event dispatching when multiple Editor.js instances are launched [#1174](https://github.com/codex-team/editor.js/issues/1174)

### 2.19

- `New` - Read-only mode 🥳 [#837](https://github.com/codex-team/editor.js/issues/837)
Expand Down
1 change: 0 additions & 1 deletion src/components/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ export default class Core {
a: true,
} as SanitizerConfig;


Copy link
Contributor Author

Choose a reason for hiding this comment

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

yarn lint:fix

this.config.hideToolbar = this.config.hideToolbar ? this.config.hideToolbar : false;
this.config.tools = this.config.tools || {};
this.config.i18n = this.config.i18n || {};
Expand Down
4 changes: 2 additions & 2 deletions src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default class BlockSelection extends Module {
Shortcuts.add({
name: 'CMD+A',
handler: (event) => {
const { BlockManager, ReadOnly } = this.Editor;
const { ReadOnly } = this.Editor;

/**
* We use Editor's Block selection on CMD+A ShortCut instead of Browsers
Expand All @@ -175,7 +175,7 @@ export default class BlockSelection extends Module {
*
* Prevent such actions if focus is not inside the Editor
*/
if (!BlockManager.currentBlock) {
if (!event.target.closest(`.${this.Editor.UI.CSS.editorWrapper}`)?.isEqualNode(this.Editor.UI.nodes.wrapper)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When multiple Editor.js instances are launched, BlockManager.currentBlock can't be changed to null by focusing other instances.

Copy link
Member

@khaydarov khaydarov Nov 21, 2020

Choose a reason for hiding this comment

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

maybe it makes sense to create a function inside UI module that gets event and checks if event's target is under editor's instance wrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, this method seems DOM hacking!
Sorry, this problem has been resolved by #1431

return;
}

Expand Down
7 changes: 7 additions & 0 deletions src/components/modules/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ export default class Paste extends Module {
private handlePasteEvent = async (event: ClipboardEvent): Promise<void> => {
const { BlockManager, Toolbar } = this.Editor;

if (
!(event.target instanceof Element) ||
!event.target.closest(`.${this.Editor.UI.CSS.editorWrapper}`)?.isEqualNode(this.Editor.UI.nodes.wrapper)
) {
return;
}

Copy link
Contributor Author

@hata6502 hata6502 Nov 23, 2020

Choose a reason for hiding this comment

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

And... This fix is also already resolved in next.
This PR is invalid.
Sorry, I'll close it!

/** If target is native input or is not Block, use browser behaviour */
if (
!BlockManager.currentBlock || (this.isNativeBehaviour(event.target) && !event.clipboardData.types.includes('Files'))
Expand Down