From 5bd35a5797cb4b5431fdf399b50a1913d7fb83ab Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Tue, 18 Aug 2020 17:32:50 +0200 Subject: [PATCH] fix: correctly select displayable note --- .../javascripts/views/notes/notes_view.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/views/notes/notes_view.ts b/app/assets/javascripts/views/notes/notes_view.ts index 86407d73e..c6a5b4783 100644 --- a/app/assets/javascripts/views/notes/notes_view.ts +++ b/app/assets/javascripts/views/notes/notes_view.ts @@ -337,12 +337,15 @@ class NotesViewCtrl extends PureViewCtrl { return; } const notes = this.application.getDisplayableItems(ContentType.Note) as SNNote[]; + let renderedNotes: SNNote[]; 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({ notes, - renderedNotes: notes.slice(0, this.notesToDisplay) + renderedNotes, }); this.reloadPanelTitle(); } @@ -572,16 +575,7 @@ class NotesViewCtrl extends PureViewCtrl { getFirstNonProtectedNote() { const displayableNotes = this.displayableNotes(); - let index = 0; - let note = displayableNotes[index]; - while (note && note.protected) { - index++; - if (index >= displayableNotes.length) { - break; - } - note = displayableNotes[index]; - } - return note; + return displayableNotes.find(note => !note.protected); } selectFirstNote() {