Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # 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 1 commit
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
16 changes: 8 additions & 8 deletions dist/editor.js

Large diffs are not rendered by default.

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.clearWindowSelection();
this.inlineToolbar.close();
this.checkState();
}

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

/**
* Clear current window selection
*/
public clearWindowSelection(): void {
const sel = window.getSelection();
const range = document.createRange();
/**
* Set node content to node where selection ends
*/
range.selectNodeContents(sel.focusNode);
/**
* To set the caret at the end of the selection
*/
range.collapse(false);
if (sel.removeAllRanges) {
sel.removeAllRanges();
} else if (sel.empty) {
sel.empty();
}
sel.addRange(range);
}

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