Skip to content

Commit

Permalink
fix: hide tooltip on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Nov 23, 2020
1 parent 2557865 commit 0fab30f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/plugins/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,13 @@ class FloatingOptionsView {
const commands = document.createElement('div');
commands.classList.add('commands');

const editOpt = document.createElement('button');
editOpt.type = 'button';
editOpt.classList.add('command');
editOpt.textContent = 'Edit';

const removeOpt = document.createElement('button');
removeOpt.type = 'button';
removeOpt.classList.add('command');
removeOpt.textContent = 'Remove';

removeOpt.onclick = removeCB;
removeOpt.addEventListener('mousedown', removeCB, { once: true });

// commands.appendChild(editOpt);
commands.appendChild(removeOpt);

el.appendChild(link);
Expand All @@ -78,12 +72,12 @@ class FloatingOptionsView {
return;
}

// const hasFocus = view.hasFocus();
const hasFocus = view.hasFocus();
const isActive = isLinkActive(state);
const linkMarks: Mark[] = getSelectionMarks(state).filter(mark => mark.type === schema.marks.link);

// hide for selection and show only for clicks
if (!isActive) {
if (!hasFocus || !isActive) {
this.hideBubble();
return;
}
Expand All @@ -94,6 +88,7 @@ class FloatingOptionsView {

const removeCB = (e: MouseEvent) => {
e.preventDefault();
e.stopPropagation();

removeLink(view);
view.focus();
Expand All @@ -116,6 +111,15 @@ function linkPlugin(): Plugin {
key: new PluginKey('link'),
view(editorView: EditorView): FloatingOptionsView {
return new FloatingOptionsView(editorView);
},
props: {
handleDOMEvents: {
blur: (view: EditorView): boolean => {
// dummy transaction to update
view.dispatch(view.state.tr.setMeta('LINK_PLUGIN_EDITOR_BLUR', true));
return false;
}
}
}
});
}
Expand Down

0 comments on commit 0fab30f

Please sign in to comment.