From 704ffaeef0b4d1a970ef470b39d338497019e3ba Mon Sep 17 00:00:00 2001 From: Jens Meisner Date: Tue, 3 Dec 2024 13:59:57 +0100 Subject: [PATCH] remember currentWorkAreaService and activeEntity --- .../src/contentlink/ContentLinks.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/ckeditor5-coremedia-link/src/contentlink/ContentLinks.ts b/packages/ckeditor5-coremedia-link/src/contentlink/ContentLinks.ts index 28fe98b2f..0fca1ed40 100644 --- a/packages/ckeditor5-coremedia-link/src/contentlink/ContentLinks.ts +++ b/packages/ckeditor5-coremedia-link/src/contentlink/ContentLinks.ts @@ -31,6 +31,8 @@ export default class ContentLinks extends Plugin { readonly #logger = LoggerProvider.getLogger("ContentLinks"); #serviceRegisteredSubscription: Pick | undefined = undefined; #initialized = false; + #currentWorkAreaService: WorkAreaService | undefined = undefined; + #activeEntity: string | undefined = ""; /** * Closes the contextual balloon whenever a new active entity is set. @@ -40,10 +42,14 @@ export default class ContentLinks extends Plugin { */ #listenForActiveEntityChanges(workAreaService: WorkAreaService): void { workAreaService.observe_activeEntity().subscribe({ - next: (activeEntities) => { - this.#logger.debug("Closing balloon because active entity changed", activeEntities); + next: (activeEntity) => { + if (this.#activeEntity === activeEntity) { + return; + } + this.#logger.debug("Closing balloon because active entity changed", activeEntity); this.#removeEditorFocusAndSelection(); closeContextualBalloon(this.editor); + this.#activeEntity = typeof activeEntity === "string" ? activeEntity : undefined; }, }); } @@ -86,12 +92,15 @@ export default class ContentLinks extends Plugin { this.#logger.debug("No WorkAreaService registered yet"); return; } + if (this.#currentWorkAreaService && services.includes(this.#currentWorkAreaService)) { + return; + } if (this.#serviceRegisteredSubscription) { this.#serviceRegisteredSubscription.unsubscribe(); } - this.#logger.debug("WorkAreaService is registered now, listening for activeEntities will be started"); - const clipboardService = services[0]; - this.#listenForActiveEntityChanges(clipboardService); + this.#logger.debug("WorkAreaService is registered now, listening for activeEntity will be started"); + this.#currentWorkAreaService = services[0]; + this.#listenForActiveEntityChanges(this.#currentWorkAreaService); }; this.#serviceRegisteredSubscription = serviceAgent .observeServices(createWorkAreaServiceDescriptor())