-
Notifications
You must be signed in to change notification settings - Fork 215
Make highlight visibility state work in a multi-guest world #3830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
425b6e7
e3b7728
4a10862
7f2c0b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -121,7 +121,7 @@ export default class Sidebar { | |||||
| this.toolbar = new ToolbarController(toolbarContainer, { | ||||||
| createAnnotation: () => guest.createAnnotation(), | ||||||
| setSidebarOpen: open => (open ? this.open() : this.close()), | ||||||
| setHighlightsVisible: show => this.setAllVisibleHighlights(show), | ||||||
| setHighlightsVisible: show => this.setHighlightsVisible(show), | ||||||
| }); | ||||||
|
|
||||||
| if (config.theme === 'clean') { | ||||||
|
|
@@ -130,9 +130,6 @@ export default class Sidebar { | |||||
| this.toolbar.useMinimalControls = false; | ||||||
| } | ||||||
|
|
||||||
| this._emitter.subscribe('highlightsVisibleChanged', visible => { | ||||||
| this.toolbar.highlightsVisible = visible; | ||||||
| }); | ||||||
| this._emitter.subscribe('hasSelectionChanged', hasSelection => { | ||||||
| this.toolbar.newAnnotationType = hasSelection ? 'annotation' : 'note'; | ||||||
| }); | ||||||
|
|
@@ -197,6 +194,12 @@ export default class Sidebar { | |||||
| this.iframeContainer.style.display = ''; | ||||||
| } | ||||||
|
|
||||||
| // Set initial highlight visibility. We do this only once the sidebar app | ||||||
| // is ready because `setHighlightsVisible` needs to reflect this state to | ||||||
| // the sidebar app. | ||||||
| const showHighlights = config.showHighlights === 'always'; | ||||||
| this.setHighlightsVisible(showHighlights); | ||||||
|
|
||||||
| if ( | ||||||
| config.openSidebar || | ||||||
| config.annotations || | ||||||
|
|
@@ -236,6 +239,9 @@ export default class Sidebar { | |||||
| sidebarTrigger(document.body, () => this.open()); | ||||||
| features.init(this._sidebarRPC); | ||||||
|
|
||||||
| this._sidebarRPC.on('showHighlights', () => | ||||||
| this.setHighlightsVisible(true) | ||||||
| ); | ||||||
| this._sidebarRPC.on('openSidebar', () => this.open()); | ||||||
| this._sidebarRPC.on('closeSidebar', () => this.close()); | ||||||
|
|
||||||
|
|
@@ -449,7 +455,7 @@ export default class Sidebar { | |||||
| this.toolbar.sidebarOpen = true; | ||||||
|
|
||||||
| if (this.options.showHighlights === 'whenSidebarOpen') { | ||||||
| this.guest.setVisibleHighlights(true); | ||||||
| this.setHighlightsVisible(true); | ||||||
| } | ||||||
|
|
||||||
| this._notifyOfLayoutChange(true); | ||||||
|
|
@@ -464,19 +470,22 @@ export default class Sidebar { | |||||
| this.toolbar.sidebarOpen = false; | ||||||
|
|
||||||
| if (this.options.showHighlights === 'whenSidebarOpen') { | ||||||
| this.guest.setVisibleHighlights(false); | ||||||
| this.setHighlightsVisible(false); | ||||||
| } | ||||||
|
|
||||||
| this._notifyOfLayoutChange(false); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Hide or show highlights associated with annotations in the document. | ||||||
| * Set whether highlights are visible in guest frames. | ||||||
| * | ||||||
| * @param {boolean} shouldShowHighlights | ||||||
| * @param {boolean} visible | ||||||
| */ | ||||||
| setAllVisibleHighlights(shouldShowHighlights) { | ||||||
| this._sidebarRPC.call('setVisibleHighlights', shouldShowHighlights); | ||||||
| setHighlightsVisible(visible) { | ||||||
| this.toolbar.highlightsVisible = visible; | ||||||
|
|
||||||
| // Notify sidebar app of change which will in turn reflect state to guest frames. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| this._sidebarRPC.call('setHighlightsVisible', visible); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,9 @@ export class FrameSyncService { | |
| // Set of tags of annotations that are currently loaded into the frame | ||
| const inFrame = new Set(); | ||
|
|
||
| /** Whether highlights are visible in guest frames. */ | ||
| this._highlightsVisible = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A single state for all the guest frames. |
||
|
|
||
| /** | ||
| * Watch for changes to the set of annotations displayed in the sidebar and | ||
| * notify connected guests about new/updated/deleted annotations. | ||
|
|
@@ -164,6 +167,11 @@ export class FrameSyncService { | |
| this._hostRPC.call('openSidebar'); | ||
| } | ||
|
|
||
| // Ensure that the highlight for the newly-created annotation is visible. | ||
| // Currently we only support a single, shared visibility state for all highlights | ||
| // in all frames, so this will make all existing highlights visible too. | ||
| this._hostRPC.call('showHighlights'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To recap the sequence of events here when creating a new highlight while the "Show highlights" control is disabled:
This might seem rather roundabout, but steps 3-5 are the same as when toggling the "Show highlights" control manually, so we avoid having multiple code paths to handle keeping the state in sync across all frames. In future if we have a direct guest <-> host channel for each guest, we might be able to eliminate the relaying of the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been thinking about I would support the creation of |
||
|
|
||
| // Create the new annotation in the sidebar. | ||
| annotationsService.create(annot); | ||
| }); | ||
|
|
@@ -226,6 +234,9 @@ export class FrameSyncService { | |
| * @param {PortRPC} channel | ||
| */ | ||
| const addFrame = channel => { | ||
| // Synchronize highlight visibility in this guest with the sidebar's controls. | ||
| channel.call('setHighlightsVisible', this._highlightsVisible); | ||
|
|
||
| channel.call('getDocumentInfo', (err, info) => { | ||
| if (err) { | ||
| channel.destroy(); | ||
|
|
@@ -279,8 +290,9 @@ export class FrameSyncService { | |
|
|
||
| // When user toggles the highlight visibility control in the sidebar container, | ||
| // update the visibility in all the guest frames. | ||
| this._hostRPC.on('setVisibleHighlights', state => { | ||
| this._guestRPC.call('setVisibleHighlights', state); | ||
| this._hostRPC.on('setHighlightsVisible', visible => { | ||
| this._highlightsVisible = visible; | ||
| this._guestRPC.call('setHighlightsVisible', visible); | ||
| }); | ||
|
|
||
| // Create channel for sidebar <-> host communication and send port to host. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showHighlightsis a new event type that is sent from thesidebarto thehostframe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. These lines reported errors as expected after a rebase and I've updated the types.