From e8cef0404b5039ec2657536976b8b31931afd337 Mon Sep 17 00:00:00 2001 From: Dominik <6538827+bdbch@users.noreply.github.com> Date: Wed, 12 Apr 2023 16:00:22 +0200 Subject: [PATCH] fix(bubble-menu): fix debounce not working with collab/collaboration cursor (#3956) --- .vscode/settings.json | 5 ++++- demos/package.json | 2 +- package-lock.json | 13 +++++++----- .../src/bubble-menu-plugin.ts | 21 ++++++++++++++----- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6416cfd2876..f89d258263c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -57,5 +57,8 @@ "vue-2", "vue-3" ], - "editor.defaultFormatter": "dbaeumer.vscode-eslint" + "editor.defaultFormatter": "dbaeumer.vscode-eslint", + "[typescript]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + } } diff --git a/demos/package.json b/demos/package.json index 81f2212e588..f5aa14377f3 100644 --- a/demos/package.json +++ b/demos/package.json @@ -18,7 +18,7 @@ "shiki": "^0.10.0", "simplify-js": "^1.2.4", "y-prosemirror": "1.0.20", - "y-webrtc": "^10.2.3", + "y-webrtc": "^10.2.5", "yjs": "^13.5.39" }, "devDependencies": { diff --git a/package-lock.json b/package-lock.json index 19b8564987f..a8aaefbba4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,7 +61,7 @@ "shiki": "^0.10.0", "simplify-js": "^1.2.4", "y-prosemirror": "1.0.20", - "y-webrtc": "^10.2.3", + "y-webrtc": "^10.2.5", "yjs": "^13.5.39" }, "devDependencies": { @@ -19379,8 +19379,9 @@ } }, "node_modules/y-webrtc": { - "version": "10.2.3", - "license": "MIT", + "version": "10.2.5", + "resolved": "https://registry.npmjs.org/y-webrtc/-/y-webrtc-10.2.5.tgz", + "integrity": "sha512-ZyBNvTI5L28sQ2PQI0T/JvyWgvuTq05L21vGkIlcvNLNSJqAaLCBJRe3FHEqXoaogqWmRcEAKGfII4ErNXMnNw==", "dependencies": { "lib0": "^0.2.42", "simple-peer": "^9.11.0", @@ -33004,7 +33005,7 @@ "vue": "^3.0.5", "vue-router": "^4.0.11", "y-prosemirror": "1.0.20", - "y-webrtc": "^10.2.3", + "y-webrtc": "^10.2.5", "yjs": "^13.5.39" } }, @@ -33994,7 +33995,9 @@ } }, "y-webrtc": { - "version": "10.2.3", + "version": "10.2.5", + "resolved": "https://registry.npmjs.org/y-webrtc/-/y-webrtc-10.2.5.tgz", + "integrity": "sha512-ZyBNvTI5L28sQ2PQI0T/JvyWgvuTq05L21vGkIlcvNLNSJqAaLCBJRe3FHEqXoaogqWmRcEAKGfII4ErNXMnNw==", "requires": { "lib0": "^0.2.42", "simple-peer": "^9.11.0", diff --git a/packages/extension-bubble-menu/src/bubble-menu-plugin.ts b/packages/extension-bubble-menu/src/bubble-menu-plugin.ts index fea29cd537d..a92967b4c8d 100644 --- a/packages/extension-bubble-menu/src/bubble-menu-plugin.ts +++ b/packages/extension-bubble-menu/src/bubble-menu-plugin.ts @@ -164,23 +164,34 @@ export class BubbleMenuView { return } - this.updateHandler(view, oldState) + const selectionChanged = !oldState?.selection.eq(view.state.selection) + const docChanged = !oldState?.doc.eq(view.state.doc) + + this.updateHandler(view, selectionChanged, docChanged, oldState) } handleDebouncedUpdate = (view: EditorView, oldState?: EditorState) => { + const selectionChanged = !oldState?.selection.eq(view.state.selection) + const docChanged = !oldState?.doc.eq(view.state.doc) + + if (!selectionChanged && !docChanged) { + return + } + if (this.updateDebounceTimer) { clearTimeout(this.updateDebounceTimer) } this.updateDebounceTimer = window.setTimeout(() => { - this.updateHandler(view, oldState) + this.updateHandler(view, selectionChanged, docChanged, oldState) }, this.updateDelay) } - updateHandler = (view: EditorView, oldState?: EditorState) => { + updateHandler = (view: EditorView, selectionChanged: boolean, docChanged: boolean, oldState?: EditorState) => { const { state, composing } = view - const { doc, selection } = state - const isSame = oldState && oldState.doc.eq(doc) && oldState.selection.eq(selection) + const { selection } = state + + const isSame = !selectionChanged && !docChanged if (composing || isSame) { return