-
Notifications
You must be signed in to change notification settings - Fork 127
HAR-9336 - fix toolbar state updates #412
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
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 |
|---|---|---|
|
|
@@ -187,7 +187,6 @@ export class SuperDoc extends EventEmitter { | |
|
|
||
| // If a toolbar element is provided, render a toolbar | ||
| this.addToolbar(this); | ||
|
|
||
| } | ||
|
|
||
| get requiredNumberOfEditors() { | ||
|
|
@@ -354,11 +353,13 @@ export class SuperDoc extends EventEmitter { | |
| role: this.config.role, | ||
| pagination: this.config.pagination, | ||
| icons: this.config.toolbarIcons, | ||
| documentMode: this.config.documentMode, | ||
| superdoc: this, | ||
| }; | ||
|
|
||
| this.toolbar = new SuperToolbar(config); | ||
| this.toolbar.on('superdoc-command', this.onToolbarCommand.bind(this)); | ||
| this.once('editorCreate', () => this.toolbar.updateToolbarState()); | ||
|
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. We need to wait for the editor to be created to update the toolbar state because there are a lot of asynchronous things behind. |
||
| } | ||
|
|
||
| addCommentsList(element) { | ||
|
|
@@ -402,26 +403,38 @@ export class SuperDoc extends EventEmitter { | |
| if (this.config.role !== 'editor') return this.#setModeSuggesting(); | ||
| if (this.superdocStore.documents.length > 0) { | ||
| const firstEditor = this.superdocStore.documents[0]?.getEditor(); | ||
| if (firstEditor) { | ||
| this.setActiveEditor(firstEditor); | ||
| this.toolbar.activeEditor = firstEditor; | ||
| } | ||
| if (firstEditor) this.setActiveEditor(firstEditor); | ||
| } | ||
|
|
||
| this.superdocStore.documents.forEach((doc) => { | ||
| doc.restoreComments(); | ||
| const editor = doc.getEditor(); | ||
| if (editor) editor.setDocumentMode('editing'); | ||
| }); | ||
|
|
||
| if (this.toolbar) { | ||
|
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. Set document mode for toolbar and update the state. |
||
| this.toolbar.documentMode = 'editing'; | ||
| this.toolbar.updateToolbarState(); | ||
| } | ||
| } | ||
|
|
||
| #setModeSuggesting() { | ||
| if (!['editor', 'suggester'].includes(this.config.role)) return this.#setModeViewing(); | ||
| if (this.superdocStore.documents.length > 0) { | ||
| const firstEditor = this.superdocStore.documents[0]?.getEditor(); | ||
| if (firstEditor) this.setActiveEditor(firstEditor); | ||
| } | ||
|
|
||
| this.superdocStore.documents.forEach((doc) => { | ||
| doc.restoreComments(); | ||
| const editor = doc.getEditor(); | ||
| if (editor) editor.setDocumentMode('suggesting'); | ||
| }); | ||
|
|
||
| if (this.toolbar) { | ||
| this.toolbar.documentMode = 'suggesting'; | ||
| this.toolbar.updateToolbarState(); | ||
| } | ||
| } | ||
|
|
||
| #setModeViewing() { | ||
|
|
@@ -431,6 +444,11 @@ export class SuperDoc extends EventEmitter { | |
| const editor = doc.getEditor(); | ||
| if (editor) editor.setDocumentMode('viewing'); | ||
| }); | ||
|
|
||
| if (this.toolbar) { | ||
| this.toolbar.documentMode = 'viewing'; | ||
| this.toolbar.updateToolbarState(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
The document mode was set to 'editing' and never changed.
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.
But since the document mode is checked on toolbar state update, I can assume that it should change (on doc mode change).