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

Hotfix/issue1133 selection shortcut removed on editor destroy #1140

Merged
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.

2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
- `Improvements` - Improve performance of DOM traversing at the `isEmpty()` method [#1095](https://github.com/codex-team/editor.js/issues/1095)
- `Improvements` - Add code of conduct
- `Improvements` - Disabled useCapture flag for a block keydown handling. That will allow plugins to override keydown and stop event propagation, for example, to make own Tab behavior.
- `Improvements` - All modules now might have `destroy` method called on Editor.js destroy
- `Fix` - Editor's styles won't be appended to the `<head>` when another instance have already do that [#1079](https://github.com/codex-team/editor.js/issues/1079)
- `Fix` - Fixed wrong toolbar icon centering in Firefox [#1120](https://github.com/codex-team/editor.js/pull/1120)
- `Fix` - Toolbox: Tool's order in Toolbox now saved in accordance with `tools` object keys order [#1073](https://github.com/codex-team/editor.js/issues/1073)
- `Fix` - Setting `autofocus` config property to `true` cause adding `.ce-block--focused` for the autofocused block [#1073](https://github.com/codex-team/editor.js/issues/1124)
- `Fix` - Public getter `shortcut` now works for Inline Tools [#1132](https://github.com/codex-team/editor.js/issues/1132)
- `Fix` - `CMD+A` handler removed after Editor.js destroy [#1133](https://github.com/codex-team/editor.js/issues/1133)

### 2.17

Expand Down
11 changes: 8 additions & 3 deletions src/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '@babel/register';

import 'components/polyfills';
import Core from './components/core';
import * as _ from './components/utils';

declare const VERSION: string;

Expand Down Expand Up @@ -81,9 +82,13 @@ export default class EditorJS {
public exportAPI(editor: Core): void {
const fieldsToExport = [ 'configuration' ];
const destroy = (): void => {
editor.moduleInstances.Listeners.removeAll();
editor.moduleInstances.UI.destroy();
editor.moduleInstances.ModificationsObserver.destroy();
Object.values(editor.moduleInstances)
.forEach((moduleInstance) => {
if (_.isFunction(moduleInstance.destroy)) {
moduleInstance.destroy();
}
});

editor = null;

for (const field in this) {
Expand Down
11 changes: 11 additions & 0 deletions src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ export default class BlockSelection extends Module {
this.Editor.InlineToolbar.close();
}

/**
* Module destruction
* De-registers Shortcut CMD+A
*/
public destroy(): void {
const { Shortcuts } = this.Editor;

/** Selection shortcut */
Shortcuts.remove('CMD+A');
}

/**
* First CMD+A selects all input content by native behaviour,
* next CMD+A keypress selects all blocks
Expand Down
7 changes: 7 additions & 0 deletions src/components/modules/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ export default class Listeners extends Module {
this.allListeners = [];
}

/**
* Module cleanup on destruction
*/
public destroy(): void {
this.removeAll();
}

/**
* Search method: looks for listener by passed element
*
Expand Down