From 01429f8f665029ccb572f8fc18f72607b89e989e Mon Sep 17 00:00:00 2001 From: Saul-Mirone Date: Thu, 3 Apr 2025 09:36:28 +0000 Subject: [PATCH] fix(editor): clear remote selection when editor is deactive (#11450) Closes: BS-3022 --- .../src/doc/doc-remote-selection.ts | 8 ++++++++ .../store/src/extension/selection/selection-extension.ts | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/blocksuite/affine/widgets/widget-remote-selection/src/doc/doc-remote-selection.ts b/blocksuite/affine/widgets/widget-remote-selection/src/doc/doc-remote-selection.ts index 69a088f09e..1591b27901 100644 --- a/blocksuite/affine/widgets/widget-remote-selection/src/doc/doc-remote-selection.ts +++ b/blocksuite/affine/widgets/widget-remote-selection/src/doc/doc-remote-selection.ts @@ -323,6 +323,14 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent { this._updateSelections(selections); }) ); + + this.disposables.add( + this.std.event.active$.subscribe(value => { + if (!value) { + this.std.selection.clearRemote(); + } + }) + ); } override render() { diff --git a/blocksuite/framework/store/src/extension/selection/selection-extension.ts b/blocksuite/framework/store/src/extension/selection/selection-extension.ts index 81338f6c5e..d4126ae7ff 100644 --- a/blocksuite/framework/store/src/extension/selection/selection-extension.ts +++ b/blocksuite/framework/store/src/extension/selection/selection-extension.ts @@ -162,6 +162,13 @@ export class StoreSelectionExtension extends StoreExtension { this.set([...current, ...selections]); } + // This method is used to clear **current editor's remote selections** + // When the editor is not active, the remote selections should be cleared + // So other editors won't see the remote selections from this editor + clearRemote() { + this.store.awarenessStore.setLocalSelection(this._id, []); + } + update(fn: (currentSelections: BaseSelection[]) => BaseSelection[]) { const selections = fn(this.value); this.set(selections);