From e784bd1694246a96eaa6bbf1db9217658df39c02 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 18 Jun 2024 17:53:19 +0200 Subject: [PATCH 1/7] fix(LinkBubble): Don't open bubble when initializing the editor Fixes: #5855 Fixes: nextcloud/collectives#1296 Signed-off-by: Jonas --- src/plugins/links.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/links.js b/src/plugins/links.js index ce3fe5d44fc..a6a52aaf34a 100644 --- a/src/plugins/links.js +++ b/src/plugins/links.js @@ -71,7 +71,9 @@ export function linkBubble(options) { appendTransaction: (transactions, oldState, state) => { const sameSelection = oldState?.selection.eq(state.selection) const sameDoc = oldState?.doc.eq(state.doc) - if (sameSelection && sameDoc) { + // Prevent bubble from opening at editor initialisation + const initLoad = oldState?.doc.content.size === 2 + if (initLoad || (sameSelection && sameDoc)) { return } const active = activeLinkFromSelection(state) From 89dc1d55f40d78b48cf593d3b12fa2054f72e8a3 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 19 Jun 2024 10:24:44 +0200 Subject: [PATCH 2/7] fix(LinkBubble): Don't open bubble on changes by other session members Signed-off-by: Jonas --- src/plugins/links.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/links.js b/src/plugins/links.js index a6a52aaf34a..31b7f99baef 100644 --- a/src/plugins/links.js +++ b/src/plugins/links.js @@ -69,11 +69,17 @@ export function linkBubble(options) { }), appendTransaction: (transactions, oldState, state) => { + // Don't open bubble at editor initialisation + if (oldState?.doc.content.size === 2) { + return + } + + // Don't open bubble if neither selection nor doc changed const sameSelection = oldState?.selection.eq(state.selection) const sameDoc = oldState?.doc.eq(state.doc) - // Prevent bubble from opening at editor initialisation - const initLoad = oldState?.doc.content.size === 2 - if (initLoad || (sameSelection && sameDoc)) { + // Don't open bubble on changes by other session members + const noHistory = !transactions.some(tr => tr.meta.addToHistory) + if (sameSelection && (noHistory || sameDoc)) { return } const active = activeLinkFromSelection(state) From 16d33f470499b1b05fa3fa824448c3a18ee6e11d Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 19 Jun 2024 11:10:20 +0200 Subject: [PATCH 3/7] test(cypress): Fix initial content undo test Undo button should be disabled after initial content got loaded and only get enabled after typing something. Signed-off-by: Jonas --- cypress/e2e/initial.spec.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cypress/e2e/initial.spec.js b/cypress/e2e/initial.spec.js index 75495a4d178..8c765591d47 100644 --- a/cypress/e2e/initial.spec.js +++ b/cypress/e2e/initial.spec.js @@ -32,10 +32,11 @@ describe('Test state loading of documents', function() { .find('h2').should('contain', 'Hello world') cy.getMenu().should('be.visible') - cy.getActionEntry('undo').should('be.visible').click() + cy.getActionEntry('undo').should('be.disabled') + cy.getContent() - .should('contain', 'Hello world') - .find('h2').should('contain', 'Hello world') + .type('New content') + cy.getActionEntry('undo').should('not.be.disabled') }) }) From 96b9467c55914cd8284ed2211ef40e016dca03b2 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 25 Jun 2024 11:52:31 +0200 Subject: [PATCH 4/7] fix(LinkBubble): Fix race condition between hide and update Hide was called with a timeout of 100ms, while update was not. This could lead to a race condition and flaky link bubble behaviour. Signed-off-by: Jonas --- src/plugins/LinkBubblePluginView.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/LinkBubblePluginView.js b/src/plugins/LinkBubblePluginView.js index d7da1558c0b..4c4a3a4e5e9 100644 --- a/src/plugins/LinkBubblePluginView.js +++ b/src/plugins/LinkBubblePluginView.js @@ -101,12 +101,14 @@ class LinkBubblePluginView { } this.createTooltip() if (active?.mark) { - this.updateTooltip(view, active) + setTimeout(() => { + this.updateTooltip(view, active) + }, 100) } else { + this.removeEventListeners() setTimeout(() => { this.tippy?.hide() }, 100) - this.removeEventListeners() } } From 3550815fb85428a7713fe94a787c9aa1f69569dc Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 25 Jun 2024 11:55:08 +0200 Subject: [PATCH 5/7] chore(LinkBubble): remove superfluous checks `active` object from prosemirror state and oldState are never similar anyway. Signed-off-by: Jonas --- src/plugins/LinkBubblePluginView.js | 4 ---- src/plugins/links.js | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/plugins/LinkBubblePluginView.js b/src/plugins/LinkBubblePluginView.js index 4c4a3a4e5e9..84d148329a6 100644 --- a/src/plugins/LinkBubblePluginView.js +++ b/src/plugins/LinkBubblePluginView.js @@ -92,13 +92,9 @@ class LinkBubblePluginView { update(view, oldState) { const { active } = this.plugin.getState(view.state) - const { active: oldActive } = this.plugin.getState(oldState) if (view.composing) { return } - if (active === oldActive) { - return - } this.createTooltip() if (active?.mark) { setTimeout(() => { diff --git a/src/plugins/links.js b/src/plugins/links.js index 31b7f99baef..dec19f47f6a 100644 --- a/src/plugins/links.js +++ b/src/plugins/links.js @@ -54,7 +54,7 @@ export function linkBubble(options) { init: () => ({ active: null }), apply: (tr, cur) => { const meta = tr.getMeta(linkBubbleKey) - if (meta && meta.active !== cur.active) { + if (meta) { return { ...cur, active: meta.active } } else { return cur From a2f9f65a7c1b0ad3dad4baa107bdf6a7c017fef4 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 25 Jun 2024 12:23:09 +0200 Subject: [PATCH 6/7] fix(LinkBubble): Hide link bubble when removing a link Signed-off-by: Jonas --- src/components/Link/LinkBubbleView.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/Link/LinkBubbleView.vue b/src/components/Link/LinkBubbleView.vue index 06960b54e8d..147db1811b7 100644 --- a/src/components/Link/LinkBubbleView.vue +++ b/src/components/Link/LinkBubbleView.vue @@ -228,7 +228,11 @@ export default { }, removeLink() { - this.editor.chain().unsetLink().focus().run() + this.editor.chain() + .hideLinkBubble() + .unsetLink() + .focus() + .run() this.stopEdit() }, }, From bd1c2e2bf38c0fa62bed682be9288903f5f1627d Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 25 Jun 2024 14:43:14 +0200 Subject: [PATCH 7/7] test(cypress): Remove superfluous `cy.get()` Should make the workspace link bubble test less flaky. Signed-off-by: Jonas --- cypress/e2e/workspace.spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/cypress/e2e/workspace.spec.js b/cypress/e2e/workspace.spec.js index 827e86c8e1d..db1b914d6bb 100644 --- a/cypress/e2e/workspace.spec.js +++ b/cypress/e2e/workspace.spec.js @@ -160,9 +160,6 @@ describe('Workspace', function() { cy.get('.file-picker [data-filename="test.md"]').click() cy.get('.dialog__actions button.button-vue--vue-primary').click() - cy.getEditor() - .find('a') - cy.getContent() .type('{leftArrow}')