Skip to content

Commit 5395d57

Browse files
authored
Desktop: Support "select all" in the note list (#2403)
* Select all notes in note list, block select all in folder and tags lists. * Adjust key mappings. * Adjust key mappings.
1 parent 8a7e3fe commit 5395d57

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

CliClient/tests/reducer.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function createNTestFolders(n) {
1919
async function createNTestNotes(n, folder) {
2020
let notes = [];
2121
for (let i = 0; i < n; i++) {
22-
let note = await Note.save({ title: 'note', parent_id: folder.id });
22+
let note = await Note.save({ title: 'note', parent_id: folder.id, is_conflict: 0 });
2323
notes.push(note);
2424
}
2525
return notes;
@@ -36,12 +36,13 @@ async function createNTestTags(n) {
3636

3737
function initTestState(folders, selectedFolderIndex, notes, selectedIndexes, tags=null, selectedTagIndex=null) {
3838
let state = defaultState;
39-
if (folders != null) {
40-
state = reducer(state, { type: 'FOLDER_UPDATE_ALL', items: folders });
41-
}
39+
4240
if (selectedFolderIndex != null) {
4341
state = reducer(state, { type: 'FOLDER_SELECT', id: folders[selectedFolderIndex].id });
4442
}
43+
if (folders != null) {
44+
state = reducer(state, { type: 'FOLDER_UPDATE_ALL', items: folders });
45+
}
4546
if (notes != null) {
4647
state = reducer(state, { type: 'NOTE_UPDATE_ALL', notes: notes, noteSource: 'test' });
4748
}
@@ -347,4 +348,28 @@ describe('Reducer', function() {
347348
expect(getIds(state.tags)).toEqual(getIds(expected.items));
348349
expect(state.selectedTagId).toEqual(expected.selectedIds[0]);
349350
}));
351+
352+
it('should select all notes', asyncTest(async () => {
353+
let folders = await createNTestFolders(2);
354+
let notes = [];
355+
for (let i = 0; i < folders.length; i++) {
356+
notes.push(...await createNTestNotes(3, folders[i]));
357+
}
358+
359+
let state = initTestState(folders, 0, notes.slice(0,3), [0]);
360+
361+
let expected = createExpectedState(notes, [0,1,2], [0]);
362+
363+
expect(state.notes.length).toEqual(expected.items.length);
364+
expect(getIds(state.notes.slice(0,4))).toEqual(getIds(expected.items));
365+
expect(state.selectedNoteIds).toEqual(expected.selectedIds);
366+
367+
// test action
368+
state = reducer(state, {type: 'NOTE_SELECT_ALL'});
369+
370+
expected = createExpectedState(notes.slice(0,3), [0,1,2], [0,1,2]);
371+
expect(getIds(state.notes)).toEqual(getIds(expected.items));
372+
expect(state.selectedNoteIds).toEqual(expected.selectedIds);
373+
}));
374+
350375
});

ElectronClient/app/gui/NoteList.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,15 @@ class NoteListComponent extends React.Component {
364364
});
365365
}
366366
}
367+
368+
if (event.keyCode === 65 && (event.ctrlKey || event.metaKey)) {
369+
// Ctrl+A key
370+
event.preventDefault();
371+
372+
this.props.dispatch({
373+
type: 'NOTE_SELECT_ALL',
374+
});
375+
}
367376
}
368377

369378
focusNoteId_(noteId) {

ElectronClient/app/gui/SideBar.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,11 @@ class SideBarComponent extends React.Component {
680680
id: selectedItem.id,
681681
});
682682
}
683+
684+
if (keyCode === 65 && (event.ctrlKey || event.metaKey)) {
685+
// Ctrl+A key
686+
event.preventDefault();
687+
}
683688
}
684689

685690
onHeaderClick_(key, event) {

ReactNativeClient/lib/reducer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ const reducer = (state = defaultState, action) => {
394394
}
395395
break;
396396

397+
case 'NOTE_SELECT_ALL':
398+
newState = Object.assign({}, state);
399+
newState.selectedNoteIds = newState.notes.map(n => n.id);
400+
break;
401+
397402
case 'FOLDER_SELECT':
398403
newState = changeSelectedFolder(state, action, { clearSelectedNoteIds: true });
399404
break;

0 commit comments

Comments
 (0)