Skip to content

Commit

Permalink
fix(bubble-menu): fix debounce not working with collab/collaboration …
Browse files Browse the repository at this point in the history
…cursor (#3956)
  • Loading branch information
bdbch authored Apr 12, 2023
1 parent cf175a3 commit e8cef04
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@
"vue-2",
"vue-3"
],
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
}
2 changes: 1 addition & 1 deletion demos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 8 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions packages/extension-bubble-menu/src/bubble-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8cef04

Please sign in to comment.