1
0
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:
Laurent Cozic 2017-10-15 12:38:22 +01:00
parent 3d8327ae0b
commit 03facc93f5
3 changed files with 21 additions and 5 deletions

View File

@ -7,6 +7,8 @@ class FolderListWidget extends ListWidget {
super(); super();
this.selectedFolderId_ = 0; this.selectedFolderId_ = 0;
this.updateIndexFromSelectedFolderId_ = false;
this.itemRenderer = (item) => { this.itemRenderer = (item) => {
return item.title; return item.title;
}; };
@ -17,10 +19,18 @@ class FolderListWidget extends ListWidget {
} }
set selectedFolderId(v) { set selectedFolderId(v) {
if (v === this.selectedFolderId_) return; this.updateIndexFromSelectedFolderId_ = true;
this.selectedFolderId_ = v; 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();
} }
} }

View File

@ -19,7 +19,6 @@ class NoteListWidget extends ListWidget {
} }
set selectedNoteId(v) { set selectedNoteId(v) {
if (v === this.selectedNoteId_) return;
this.updateIndexFromSelectedNoteId_ = true; this.updateIndexFromSelectedNoteId_ = true;
this.selectedNoteId_ = v; this.selectedNoteId_ = v;
} }

View File

@ -158,12 +158,14 @@ const reducer = (state = defaultState, action) => {
const modNote = action.note; const modNote = action.note;
let noteFolderHasChanged = false;
let newNotes = state.notes.slice(); let newNotes = state.notes.slice();
var found = false; var found = false;
for (let i = 0; i < newNotes.length; i++) { for (let i = 0; i < newNotes.length; i++) {
let n = newNotes[i]; let n = newNotes[i];
if (n.id == modNote.id) { if (n.id == modNote.id) {
// Note is still in the same folder
if (!('parent_id' in modNote) || modNote.parent_id == n.parent_id) { if (!('parent_id' in modNote) || modNote.parent_id == n.parent_id) {
// Merge the properties that have changed (in modNote) into // Merge the properties that have changed (in modNote) into
// the object we already have. // the object we already have.
@ -174,8 +176,9 @@ const reducer = (state = defaultState, action) => {
newNotes[i][n] = modNote[n]; newNotes[i][n] = modNote[n];
} }
} else { } else { // Note has moved to a different folder
newNotes.splice(i, 1); newNotes.splice(i, 1);
noteFolderHasChanged = true;
} }
found = true; found = true;
break; break;
@ -187,6 +190,10 @@ const reducer = (state = defaultState, action) => {
newNotes = Note.sortNotes(newNotes, state.notesOrder, newState.settings.uncompletedTodosOnTop); newNotes = Note.sortNotes(newNotes, state.notesOrder, newState.settings.uncompletedTodosOnTop);
newState = Object.assign({}, state); newState = Object.assign({}, state);
newState.notes = newNotes; newState.notes = newNotes;
if (noteFolderHasChanged) {
newState.selectedNoteId = newNotes.length ? newNotes[0].id : null;
}
break; break;
case 'NOTES_DELETE': case 'NOTES_DELETE':