1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

All: Fixes #2803: Remember last selected note (#2809)

* Fix : Remember last selected note

Fixes #2803

* Add unit test
This commit is contained in:
Naveen M V 2020-03-21 16:59:22 +05:30 committed by GitHub
parent 42498842b5
commit 3ecd29d0b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -462,6 +462,36 @@ describe('Reducer', function() {
expect(getIds(state.forwardHistoryNotes)).toEqual([]); expect(getIds(state.forwardHistoryNotes)).toEqual([]);
})); }));
it('should remember the last seen note of a notebook', asyncTest(async () => {
const folders = await createNTestFolders(2);
const notes = [];
for (let i = 0; i < folders.length; i++) {
notes.push(...await createNTestNotes(5, folders[i]));
}
let state = initTestState(folders, 0, notes.slice(0,5), [0]);
state = goToNote(notes, [1], state);
state = goToNote(notes, [2], state);
state = goToNote(notes, [3], state);
state = goToNote(notes, [4], state); // last seen note is notes[4]
// go to second folder
state = reducer(state, { type: 'FOLDER_SELECT', id: folders[1].id, historyAction: 'goto' });
state = goToNote(notes, [5], state);
state = goToNote(notes, [6], state);
// return to first folder
state = reducer(state, { type: 'FOLDER_SELECT', id: folders[0].id, historyAction: 'goto' });
expect(state.lastSelectedNotesIds.Folder[folders[0].id]).toEqual([notes[4].id]);
// return to second folder
state = reducer(state, { type: 'FOLDER_SELECT', id: folders[1].id, historyAction: 'goto' });
expect(state.lastSelectedNotesIds.Folder[folders[1].id]).toEqual([notes[6].id]);
}));
}); });

View File

@ -365,8 +365,6 @@ function changeSelectedNotes(state, action, options = null) {
newState.backwardHistoryNotes = backwardHistoryNotes; newState.backwardHistoryNotes = backwardHistoryNotes;
newState.forwardHistoryNotes = forwardHistoryNotes; newState.forwardHistoryNotes = forwardHistoryNotes;
return newState;
} else if (action.type === 'NOTE_SELECT_ADD') { } else if (action.type === 'NOTE_SELECT_ADD') {
if (!noteIds.length) return state; if (!noteIds.length) return state;
newState.selectedNoteIds = ArrayUtils.unique(newState.selectedNoteIds.concat(noteIds)); newState.selectedNoteIds = ArrayUtils.unique(newState.selectedNoteIds.concat(noteIds));