Skip to content

Commit

Permalink
Clear focus on multiple editor instances (codex-team#632)
Browse files Browse the repository at this point in the history
* Clear focus on multiple editor instances

* update

* update bundles

* close inline toolbar
  • Loading branch information
khaydarov authored Mar 1, 2019
1 parent 681e8a5 commit 1e5e779
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Welcome to testing stage. Please, join a [public Telegram-chat](//t.me/codex_edi

### 2.7-2.9 changelog

- `Fix` - Clear focus when click is outside the Editor instance
- `Fix` — Fix CMD+A Selection on multiple Editor instances
- `New` — Toolbox now have beautiful helpers with Tool names and shortcuts
- `Improvements` — Prevent navigating back on Firefox when Block is removing by backspace
Expand Down
6 changes: 3 additions & 3 deletions 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.11.4

- `Fix` - Clear focus when click is outside the Editor instance

### 2.11.3

- `Fix` — Fix CMD+A Selection on multiple Editor instances
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/editorjs",
"version": "2.11.3",
"version": "2.11.4",
"description": "Editor.js — Native JS, based on API and Open Source",
"main": "dist/editor.js",
"types": "./types/index.d.ts",
Expand Down
31 changes: 19 additions & 12 deletions src/components/modules/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default class UI extends Module {
false,
);
this.Editor.Listeners.on(document, 'keydown', (event) => this.documentKeydown(event as KeyboardEvent), true);
this.Editor.Listeners.on(document, 'click', (event) => this.documentClicked(event as MouseEvent), false);
this.Editor.Listeners.on(document, 'click', (event) => this.documentClicked(event as MouseEvent), true);
}

/**
Expand Down Expand Up @@ -328,24 +328,31 @@ export default class UI extends Module {
*/
const target = event.target as HTMLElement;
const clickedOnInlineToolbarButton = target.closest(`.${this.Editor.InlineToolbar.CSS.inlineToolbar}`);
const clickedInsideofEditor = target.closest(`.${UI.CSS.editorWrapper}`);
const clickedInsideofEditor = target.closest(`#${this.config.holderId}`);

/** Clear highlightings and pointer on BlockManager */
if (!clickedInsideofEditor && !Selection.isAtEditor) {
if (!clickedInsideofEditor) {
/**
* Clear highlightings and pointer on BlockManager
*
* Current page might contain several instances
* Click between instances MUST clear focus, pointers and close toolbars
*/
this.Editor.BlockManager.dropPointer();
this.Editor.InlineToolbar.close();
this.Editor.Toolbar.close();
}
this.Editor.BlockSelection.clearSelection();

if (!clickedOnInlineToolbarButton) {
} else if (!clickedOnInlineToolbarButton) {
/**
* Move inline toolbar to the focused Block
*/
this.Editor.InlineToolbar.handleShowingEvent(event);
}

if (Selection.isAtEditor) {
} else if (Selection.isAtEditor) {
/**
* Focus clicked Block
*/
this.Editor.BlockManager.setCurrentBlockByChildNode(Selection.anchorNode);
}

/** Clear selection */
this.Editor.BlockSelection.clearSelection();
}

/**
Expand Down

0 comments on commit 1e5e779

Please sign in to comment.