diff --git a/webapp/components/Editor/ContextMenu.vue b/webapp/components/Editor/ContextMenu.vue index d0cf4c087..487920d2b 100644 --- a/webapp/components/Editor/ContextMenu.vue +++ b/webapp/components/Editor/ContextMenu.vue @@ -7,21 +7,28 @@ export default { node: Object, }, methods: { - displayContextMenu(target, content, trigger) { + displayContextMenu(target, content, type) { + const trigger = type === 'link' ? 'click' : 'mouseenter' + const showOnInit = type !== 'link' + if (this.menu) { return } + this.menu = tippy(target, { - content: content, - trigger: trigger || 'mouseenter', - interactive: true, - theme: 'dark', - placement: 'top-start', - inertia: true, - duration: [400, 200], - showOnInit: true, arrow: true, arrowType: 'round', + content: content, + // duration: [400, 200], + inertia: true, + interactive: true, + placement: 'top-start', + showOnInit, + theme: 'dark', + trigger, + onMount(instance) { + instance.popper.querySelector('input').focus() + }, }) // we have to update tippy whenever the DOM is updated if (MutationObserver) { diff --git a/webapp/components/Editor/Editor.vue b/webapp/components/Editor/Editor.vue index c511eae8e..168e2e732 100644 --- a/webapp/components/Editor/Editor.vue +++ b/webapp/components/Editor/Editor.vue @@ -1,6 +1,6 @@ @@ -54,7 +61,7 @@ export default { lastValueHash: null, editor: null, linkUrl: null, - linkMenuIsActive: false, + isLinkInputActive: false, suggestionType: '', query: null, suggestionRange: null, @@ -242,23 +249,17 @@ export default { this.$emit('input', content) } }, - showLinkMenu(attrs, element) { - this.linkUrl = attrs.href - this.linkMenuIsActive = true - this.$refs.contextMenu.displayContextMenu(element, this.$refs.linkMenu.$el, 'click') - this.$nextTick(() => { - try { - const input = this.$refs.linkMenu.$el.querySelector('input') - input.focus() - input.select() - } catch (err) {} - }) - }, - hideLinkMenu() { - this.$refs.contextMenu.hideContextMenu() - this.linkUrl = null - this.linkMenuIsActive = false - this.editor.focus() + toggleLinkInput(attrs, element) { + if (!this.isLinkInputActive && attrs && element) { + this.linkUrl = attrs.href + this.isLinkInputActive = true + this.$refs.contextMenu.displayContextMenu(element, this.$refs.linkInput.$el, 'link') + } else { + this.$refs.contextMenu.hideContextMenu() + this.linkUrl = null + this.isLinkInputActive = false + this.editor.focus() + } }, setLinkUrl(command, url) { const links = linkify().match(url) @@ -267,7 +268,7 @@ export default { command({ href: links.pop().url, }) - this.hideLinkMenu() + this.toggleLinkInput() this.editor.focus() } else if (!url) { // remove link diff --git a/webapp/components/Editor/LinkInput.vue b/webapp/components/Editor/LinkInput.vue index d870065ef..7478b43b3 100644 --- a/webapp/components/Editor/LinkInput.vue +++ b/webapp/components/Editor/LinkInput.vue @@ -1,11 +1,13 @@