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

Close inline toolbar after creating new link by pressing ENTER #722

Merged
merged 8 commits into from
Apr 27, 2019
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
18 changes: 9 additions & 9 deletions dist/editor.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
- `New` *Config* - Added new property in EditorConfig `holder`, use this property for append Editor instead `holderId`. `holder` property now support reference on dom element. [#696](https://github.com/codex-team/editor.js/issues/696)
- `Deprecated` *Config* - `holderId` property now is deprecated and will removed in next major release. Use `holder` instead.
- `Fix` *Types* — Fixed error with `codex-notifier` package [#713](https://github.com/codex-team/editor.js/issues/713)
- `Improvements` — Close inline toolbar after creating a new link

### 2.12.4

- `Improvements` CodeX.Shortcuts version updated to the v1.1 [#684](https://github.com/codex-team/editor.js/issues/684)
- `Improvements` CodeX.Shortcuts version updated to the v1.1 [#684](https://github.com/codex-team/editor.js/issues/684)
- `Fix` — Do not start multi-block selection on Toolbox and Inline Toolbar [#646](https://github.com/codex-team/editor.js/issues/646)
- `Fix` — Minor fixes of caret behaviour [#663](https://github.com/codex-team/editor.js/issues/663)
- `Fix` — Fix inline-link icon position in Firefox [#674](https://github.com/codex-team/editor.js/issues/674)
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.12.4",
"version": "2.12.5",
"description": "Editor.js — Native JS, based on API and Open Source",
"main": "dist/editor.js",
"types": "./types/index.d.ts",
Expand Down
16 changes: 10 additions & 6 deletions src/components/inline-tools/inline-tool-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ export default class LinkInlineTool implements InlineTool {
private inputOpened: boolean = false;

/**
* Available Inline Toolbar methods (open/close)
* Available Toolbar methods (open/close)
*/
private toolbar: Toolbar;

/**
* Available inline toolbar methods (open/close)
*/
private inlineToolbar: Toolbar;

Expand All @@ -94,7 +99,8 @@ export default class LinkInlineTool implements InlineTool {
* @param {{api: API}} - Editor.js API
*/
constructor({api}) {
this.inlineToolbar = api.toolbar;
this.toolbar = api.toolbar;
this.inlineToolbar = api.inlineToolbar;
this.notifier = api.notifier;
this.selection = new SelectionUtils();
}
Expand Down Expand Up @@ -156,7 +162,7 @@ export default class LinkInlineTool implements InlineTool {
this.unlink();
this.closeActions();
this.checkState();
this.inlineToolbar.close();
this.toolbar.close();
return;
}
}
Expand Down Expand Up @@ -288,10 +294,8 @@ export default class LinkInlineTool implements InlineTool {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();

this.closeActions();
this.selection.collapseToEnd();
this.inlineToolbar.close();
this.checkState();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/components/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ export default class SelectionUtils {
this.savedSelectionRange = null;
}

/**
* Collapse current selection
*/
public collapseToEnd(): void {
const sel = window.getSelection();
const range = document.createRange();
tanmayv marked this conversation as resolved.
Show resolved Hide resolved

range.selectNodeContents(sel.focusNode);
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
range.collapse(false);
sel.removeAllRanges();
sel.addRange(range);
}

/**
* Looks ahead to find passed tag from current selection
*
Expand Down