diff --git a/CliClient/app/gui/FolderListWidget.js b/CliClient/app/gui/FolderListWidget.js index 45097791c..f8751c493 100644 --- a/CliClient/app/gui/FolderListWidget.js +++ b/CliClient/app/gui/FolderListWidget.js @@ -7,6 +7,8 @@ class FolderListWidget extends ListWidget { super(); this.selectedFolderId_ = 0; + this.updateIndexFromSelectedFolderId_ = false; + this.itemRenderer = (item) => { return item.title; }; @@ -17,10 +19,18 @@ class FolderListWidget extends ListWidget { } set selectedFolderId(v) { - if (v === this.selectedFolderId_) return; + this.updateIndexFromSelectedFolderId_ = true; this.selectedFolderId_ = v; - const index = this.itemIndexByKey('id', this.selectedFolderId_); - this.currentIndex = index >= 0 ? index : 0; + } + + render() { + if (this.updateIndexFromSelectedFolderId_) { + const index = this.itemIndexByKey('id', this.selectedFolderId_); + this.currentIndex = index >= 0 ? index : 0; + this.updateIndexFromSelectedFolderId_ = false; + } + + super.render(); } } diff --git a/CliClient/app/gui/NoteListWidget.js b/CliClient/app/gui/NoteListWidget.js index 22995489e..517f5dcc9 100644 --- a/CliClient/app/gui/NoteListWidget.js +++ b/CliClient/app/gui/NoteListWidget.js @@ -19,7 +19,6 @@ class NoteListWidget extends ListWidget { } set selectedNoteId(v) { - if (v === this.selectedNoteId_) return; this.updateIndexFromSelectedNoteId_ = true; this.selectedNoteId_ = v; } diff --git a/ReactNativeClient/lib/reducer.js b/ReactNativeClient/lib/reducer.js index 1f4b353f4..41778452a 100644 --- a/ReactNativeClient/lib/reducer.js +++ b/ReactNativeClient/lib/reducer.js @@ -158,12 +158,14 @@ const reducer = (state = defaultState, action) => { const modNote = action.note; + let noteFolderHasChanged = false; let newNotes = state.notes.slice(); var found = false; for (let i = 0; i < newNotes.length; i++) { let n = newNotes[i]; if (n.id == modNote.id) { + // Note is still in the same folder if (!('parent_id' in modNote) || modNote.parent_id == n.parent_id) { // Merge the properties that have changed (in modNote) into // the object we already have. @@ -174,8 +176,9 @@ const reducer = (state = defaultState, action) => { newNotes[i][n] = modNote[n]; } - } else { + } else { // Note has moved to a different folder newNotes.splice(i, 1); + noteFolderHasChanged = true; } found = true; break; @@ -187,6 +190,10 @@ const reducer = (state = defaultState, action) => { newNotes = Note.sortNotes(newNotes, state.notesOrder, newState.settings.uncompletedTodosOnTop); newState = Object.assign({}, state); newState.notes = newNotes; + + if (noteFolderHasChanged) { + newState.selectedNoteId = newNotes.length ? newNotes[0].id : null; + } break; case 'NOTES_DELETE':