Skip to content

Commit

Permalink
remember currentWorkAreaService and activeEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
jens-meisner committed Dec 3, 2024
1 parent 030f510 commit 704ffae
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/ckeditor5-coremedia-link/src/contentlink/ContentLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class ContentLinks extends Plugin {
readonly #logger = LoggerProvider.getLogger("ContentLinks");
#serviceRegisteredSubscription: Pick<Subscription, "unsubscribe"> | undefined = undefined;
#initialized = false;
#currentWorkAreaService: WorkAreaService | undefined = undefined;
#activeEntity: string | undefined = "";

/**
* Closes the contextual balloon whenever a new active entity is set.
Expand All @@ -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;
},
});
}
Expand Down Expand Up @@ -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<WorkAreaService>(createWorkAreaServiceDescriptor())
Expand Down

0 comments on commit 704ffae

Please sign in to comment.