fix: correctly select displayable note

This commit is contained in:
Baptiste Grob
2020-08-18 17:32:50 +02:00
parent fd26bde812
commit 5bd35a5797

View File

@@ -337,12 +337,15 @@ class NotesViewCtrl extends PureViewCtrl {
return; return;
} }
const notes = this.application.getDisplayableItems(ContentType.Note) as SNNote[]; const notes = this.application.getDisplayableItems(ContentType.Note) as SNNote[];
let renderedNotes: SNNote[];
if (this.appState.getActiveEditor()?.isTemplateNote) { if (this.appState.getActiveEditor()?.isTemplateNote) {
notes.unshift(this.appState.getActiveEditor()!.note); renderedNotes = [this.appState.getActiveEditor().note, ...notes.slice(0, this.notesToDisplay)];
} else {
renderedNotes = notes.slice(0, this.notesToDisplay);
} }
await this.setNotesState({ await this.setNotesState({
notes, notes,
renderedNotes: notes.slice(0, this.notesToDisplay) renderedNotes,
}); });
this.reloadPanelTitle(); this.reloadPanelTitle();
} }
@@ -572,16 +575,7 @@ class NotesViewCtrl extends PureViewCtrl {
getFirstNonProtectedNote() { getFirstNonProtectedNote() {
const displayableNotes = this.displayableNotes(); const displayableNotes = this.displayableNotes();
let index = 0; return displayableNotes.find(note => !note.protected);
let note = displayableNotes[index];
while (note && note.protected) {
index++;
if (index >= displayableNotes.length) {
break;
}
note = displayableNotes[index];
}
return note;
} }
selectFirstNote() { selectFirstNote() {