Commit b394b412 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Only provided clustered highlights in integrations that support it

Allow an integration to declare whether or not it supports clustered
highlights. At this time, only HTML documents support the feature.

Fixes #4925
parent 35e5a089
...@@ -199,11 +199,6 @@ export class Guest { ...@@ -199,11 +199,6 @@ export class Guest {
}); });
this.features = new FeatureFlags(); this.features = new FeatureFlags();
this._clusterToolbar = new HighlightClusterController(element, {
features: this.features,
});
/** /**
* Integration that handles document-type specific functionality in the * Integration that handles document-type specific functionality in the
* guest. * guest.
...@@ -217,6 +212,12 @@ export class Guest { ...@@ -217,6 +212,12 @@ export class Guest {
this._integration.showContentInfo?.(config.contentInfoBanner); this._integration.showContentInfo?.(config.contentInfoBanner);
} }
if (this._integration.canStyleClusteredHighlights?.()) {
this._clusterToolbar = new HighlightClusterController(element, {
features: this.features,
});
}
/** /**
* Channel for host-guest communication. * Channel for host-guest communication.
* *
...@@ -485,6 +486,7 @@ export class Guest { ...@@ -485,6 +486,7 @@ export class Guest {
this._selectionObserver.disconnect(); this._selectionObserver.disconnect();
this._adder.destroy(); this._adder.destroy();
this._bucketBarClient.destroy(); this._bucketBarClient.destroy();
this._clusterToolbar?.destroy();
removeAllHighlights(this.element); removeAllHighlights(this.element);
......
...@@ -109,6 +109,10 @@ export class HTMLIntegration extends TinyEmitter { ...@@ -109,6 +109,10 @@ export class HTMLIntegration extends TinyEmitter {
return true; return true;
} }
canStyleClusteredHighlights() {
return true;
}
destroy() { destroy() {
this._navObserver.disconnect(); this._navObserver.disconnect();
this._metaObserver.disconnect(); this._metaObserver.disconnect();
......
...@@ -39,6 +39,8 @@ describe('Guest', () => { ...@@ -39,6 +39,8 @@ describe('Guest', () => {
let FakeBucketBarClient; let FakeBucketBarClient;
let fakeBucketBarClient; let fakeBucketBarClient;
let fakeHighlightClusterController;
let FakeHighlightClusterController;
let fakeCreateIntegration; let fakeCreateIntegration;
let fakeFindClosestOffscreenAnchor; let fakeFindClosestOffscreenAnchor;
let fakeFrameFillsAncestor; let fakeFrameFillsAncestor;
...@@ -124,6 +126,13 @@ describe('Guest', () => { ...@@ -124,6 +126,13 @@ describe('Guest', () => {
}; };
FakeBucketBarClient = sinon.stub().returns(fakeBucketBarClient); FakeBucketBarClient = sinon.stub().returns(fakeBucketBarClient);
fakeHighlightClusterController = {
destroy: sinon.stub(),
};
FakeHighlightClusterController = sinon
.stub()
.returns(fakeHighlightClusterController);
fakeFindClosestOffscreenAnchor = sinon.stub(); fakeFindClosestOffscreenAnchor = sinon.stub();
fakeFrameFillsAncestor = sinon.stub().returns(true); fakeFrameFillsAncestor = sinon.stub().returns(true);
...@@ -131,6 +140,7 @@ describe('Guest', () => { ...@@ -131,6 +140,7 @@ describe('Guest', () => {
fakeIntegration = Object.assign(new TinyEmitter(), { fakeIntegration = Object.assign(new TinyEmitter(), {
anchor: sinon.stub(), anchor: sinon.stub(),
canAnnotate: sinon.stub().returns(true), canAnnotate: sinon.stub().returns(true),
canStyleClusteredHighlights: sinon.stub().returns(false),
contentContainer: sinon.stub().returns({}), contentContainer: sinon.stub().returns({}),
describe: sinon.stub(), describe: sinon.stub(),
destroy: sinon.stub(), destroy: sinon.stub(),
...@@ -172,6 +182,9 @@ describe('Guest', () => { ...@@ -172,6 +182,9 @@ describe('Guest', () => {
'./bucket-bar-client': { './bucket-bar-client': {
BucketBarClient: FakeBucketBarClient, BucketBarClient: FakeBucketBarClient,
}, },
'./highlight-clusters': {
HighlightClusterController: FakeHighlightClusterController,
},
'./highlighter': highlighter, './highlighter': highlighter,
'./integrations': { './integrations': {
createIntegration: fakeCreateIntegration, createIntegration: fakeCreateIntegration,
...@@ -1330,6 +1343,14 @@ describe('Guest', () => { ...@@ -1330,6 +1343,14 @@ describe('Guest', () => {
guest.destroy(); guest.destroy();
assert.called(sidebarRPC().destroy); assert.called(sidebarRPC().destroy);
}); });
it('removes the clustered highlights toolbar', () => {
fakeIntegration.canStyleClusteredHighlights.returns(true);
const guest = createGuest();
guest.destroy();
assert.called(fakeHighlightClusterController.destroy);
});
}); });
it('discovers and creates a channel for communication with the sidebar', async () => { it('discovers and creates a channel for communication with the sidebar', async () => {
...@@ -1373,6 +1394,22 @@ describe('Guest', () => { ...@@ -1373,6 +1394,22 @@ describe('Guest', () => {
}); });
}); });
it('does not create a HighlightClusterController if the integration does not support clustered highlights', () => {
fakeIntegration.canStyleClusteredHighlights.returns(false);
createGuest();
assert.notCalled(FakeHighlightClusterController);
});
it('creates a HighlightClustersController if the integration supports clustered highlights', () => {
fakeIntegration.canStyleClusteredHighlights.returns(true);
createGuest();
assert.calledOnce(FakeHighlightClusterController);
});
it('sends document metadata and URIs to sidebar', async () => { it('sends document metadata and URIs to sidebar', async () => {
createGuest(); createGuest();
await delay(0); await delay(0);
......
...@@ -162,6 +162,10 @@ export type IntegrationBase = { ...@@ -162,6 +162,10 @@ export type IntegrationBase = {
* of the current document. * of the current document.
*/ */
canAnnotate(range: Range): boolean; canAnnotate(range: Range): boolean;
/**
* Return whether this integration supports styling multiple clusters of highlights
*/
canStyleClusteredHighlights?(): boolean;
/** /**
* Attempt to resolve a set of serialized selectors to the corresponding content in the current document. * Attempt to resolve a set of serialized selectors to the corresponding content in the current document.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment