mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Fixed selection in note and folder list
This commit is contained in:
parent
3d8327ae0b
commit
03facc93f5
@ -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;
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.updateIndexFromSelectedFolderId_) {
|
||||
const index = this.itemIndexByKey('id', this.selectedFolderId_);
|
||||
this.currentIndex = index >= 0 ? index : 0;
|
||||
this.updateIndexFromSelectedFolderId_ = false;
|
||||
}
|
||||
|
||||
super.render();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ class NoteListWidget extends ListWidget {
|
||||
}
|
||||
|
||||
set selectedNoteId(v) {
|
||||
if (v === this.selectedNoteId_) return;
|
||||
this.updateIndexFromSelectedNoteId_ = true;
|
||||
this.selectedNoteId_ = v;
|
||||
}
|
||||
|
@ -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':
|
||||
|
Loading…
Reference in New Issue
Block a user