mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix propagation of noteTypeMimeChanged event to global scope to fix e.g. edit button switching depending on note type
This commit is contained in:
parent
a4e99662cb
commit
4116fe0a20
@ -184,7 +184,7 @@ class NoteContext extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// "readOnly" is a state valid only for text/code notes
|
// "readOnly" is a state valid only for text/code notes
|
||||||
if (!this.note || this.note.type !== 'text' && this.note.type !== 'code') {
|
if (!this.note || (this.note.type !== 'text' && this.note.type !== 'code')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
async refresh() {
|
async refresh() {
|
||||||
this.type = await this.getWidgetType();
|
this.type = await this.getWidgetType();
|
||||||
this.mime = this.note ? this.note.mime : null;
|
this.mime = this.note?.mime;
|
||||||
|
|
||||||
if (!(this.type in this.typeWidgets)) {
|
if (!(this.type in this.typeWidgets)) {
|
||||||
const clazz = typeWidgetClasses[this.type];
|
const clazz = typeWidgetClasses[this.type];
|
||||||
@ -273,10 +273,14 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async entitiesReloadedEvent({loadResults}) {
|
async entitiesReloadedEvent({loadResults}) {
|
||||||
if (loadResults.isNoteContentReloaded(this.noteId, this.componentId)
|
// we're detecting note type change on the note_detail level, but triggering the noteTypeMimeChanged
|
||||||
|| (loadResults.isNoteReloaded(this.noteId, this.componentId) && (this.type !== await this.getWidgetType() || this.mime !== this.note.mime))) {
|
// globally, so it gets also to e.g. ribbon components. But this means that the event can be generated multiple
|
||||||
|
// times if the same note is open in several tabs.
|
||||||
|
|
||||||
this.handleEvent('noteTypeMimeChanged', {noteId: this.noteId});
|
if (loadResults.isNoteReloaded(this.noteId, this.componentId)
|
||||||
|
&& (this.type !== await this.getWidgetType() || this.mime !== this.note.mime)) {
|
||||||
|
|
||||||
|
this.triggerEvent('noteTypeMimeChanged', {noteId: this.noteId});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const attrs = loadResults.getAttributes();
|
const attrs = loadResults.getAttributes();
|
||||||
@ -294,7 +298,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||||||
if (label || relation) {
|
if (label || relation) {
|
||||||
// probably incorrect event
|
// probably incorrect event
|
||||||
// calling this.refresh() is not enough since the event needs to be propagated to children as well
|
// calling this.refresh() is not enough since the event needs to be propagated to children as well
|
||||||
this.handleEvent('noteTypeMimeChanged', {noteId: this.noteId});
|
this.triggerEvent('noteTypeMimeChanged', {noteId: this.noteId});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user