fix: better protected notes handling and allow shift-clicking note up in the list
This commit is contained in:
@@ -69,6 +69,42 @@ export class NotesState {
|
||||
return Object.keys(this.selectedNotes).length;
|
||||
}
|
||||
|
||||
async selectNotesRange(selectedNote: SNNote): Promise<void> {
|
||||
const notes = this.application.getDisplayableItems(
|
||||
ContentType.Note
|
||||
) as SNNote[];
|
||||
const lastSelectedNoteIndex = notes.findIndex(
|
||||
(note) => note.uuid == this.lastSelectedNote?.uuid
|
||||
);
|
||||
const selectedNoteIndex = notes.findIndex((note) => note.uuid == selectedNote.uuid);
|
||||
let protectedNotesAccessRequest: Promise<boolean>;
|
||||
let notesToSelect = [];
|
||||
|
||||
if (selectedNoteIndex > lastSelectedNoteIndex) {
|
||||
notesToSelect = notes
|
||||
.slice(lastSelectedNoteIndex, selectedNoteIndex + 1);
|
||||
} else {
|
||||
notesToSelect = notes
|
||||
.slice(selectedNoteIndex, lastSelectedNoteIndex + 1);
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
notesToSelect.map(async note => {
|
||||
const requestAccess = note.protected && this.application.hasProtectionSources();
|
||||
if (requestAccess) {
|
||||
if (!protectedNotesAccessRequest) {
|
||||
protectedNotesAccessRequest = this.application.authorizeNoteAccess(note);
|
||||
}
|
||||
}
|
||||
if (!requestAccess || await protectedNotesAccessRequest) {
|
||||
this.selectedNotes[note.uuid] = note;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this.lastSelectedNote = selectedNote;
|
||||
}
|
||||
|
||||
async selectNote(uuid: UuidString): Promise<void> {
|
||||
const note = this.application.findItem(uuid) as SNNote;
|
||||
if (
|
||||
@@ -78,27 +114,20 @@ export class NotesState {
|
||||
) {
|
||||
if (this.selectedNotes[uuid]) {
|
||||
delete this.selectedNotes[uuid];
|
||||
} else {
|
||||
} else if (await this.application.authorizeNoteAccess(note)) {
|
||||
this.selectedNotes[uuid] = note;
|
||||
this.lastSelectedNote = note;
|
||||
}
|
||||
} else if (this.io.activeModifiers.has(KeyboardModifier.Shift)) {
|
||||
const notes = this.application.getDisplayableItems(
|
||||
ContentType.Note
|
||||
) as SNNote[];
|
||||
const lastSelectedNoteIndex = notes.findIndex(
|
||||
(note) => note.uuid == this.lastSelectedNote?.uuid
|
||||
);
|
||||
const selectedNoteIndex = notes.findIndex((note) => note.uuid == uuid);
|
||||
notes
|
||||
.slice(lastSelectedNoteIndex, selectedNoteIndex + 1)
|
||||
.forEach((note) => (this.selectedNotes[note.uuid] = note));
|
||||
await this.selectNotesRange(note);
|
||||
} else {
|
||||
this.selectedNotes = {
|
||||
[uuid]: note,
|
||||
};
|
||||
this.lastSelectedNote = note;
|
||||
await this.openEditor(uuid);
|
||||
if (await this.application.authorizeNoteAccess(note)) {
|
||||
this.selectedNotes = {
|
||||
[uuid]: note,
|
||||
};
|
||||
await this.openEditor(uuid);
|
||||
this.lastSelectedNote = note;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,17 +142,15 @@ export class NotesState {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await this.application.authorizeNoteAccess(note)) {
|
||||
if (!this.activeEditor) {
|
||||
this.application.editorGroup.createEditor(noteUuid);
|
||||
} else {
|
||||
this.activeEditor.setNote(note);
|
||||
}
|
||||
await this.onActiveEditorChanged();
|
||||
if (!this.activeEditor) {
|
||||
this.application.editorGroup.createEditor(noteUuid);
|
||||
} else {
|
||||
this.activeEditor.setNote(note);
|
||||
}
|
||||
await this.onActiveEditorChanged();
|
||||
|
||||
if (note.waitingForKey) {
|
||||
this.application.presentKeyRecoveryWizard();
|
||||
}
|
||||
if (note.waitingForKey) {
|
||||
this.application.presentKeyRecoveryWizard();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -298,10 +298,12 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
|
||||
));
|
||||
}
|
||||
|
||||
private openNotesContextMenu(e: MouseEvent, note: SNNote) {
|
||||
private async openNotesContextMenu(e: MouseEvent, note: SNNote) {
|
||||
e.preventDefault();
|
||||
this.selectNote(note);
|
||||
if (!note.protected) {
|
||||
if (!this.state.selectedNotes[note.uuid]) {
|
||||
await this.selectNote(note);
|
||||
}
|
||||
if (this.state.selectedNotes[note.uuid]) {
|
||||
this.application.getAppState().notes.setContextMenuPosition({
|
||||
top: e.clientY,
|
||||
left: e.clientX,
|
||||
@@ -330,8 +332,8 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
|
||||
}
|
||||
for (const note of this.state.renderedNotes) {
|
||||
if (!this.rightClickListeners.has(note.uuid)) {
|
||||
const listener = (e: MouseEvent): void => {
|
||||
return this.openNotesContextMenu(e, note);
|
||||
const listener = async (e: MouseEvent): Promise<void> => {
|
||||
return await this.openNotesContextMenu(e, note);
|
||||
};
|
||||
document
|
||||
.getElementById(`note-${note.uuid}`)
|
||||
|
||||
Reference in New Issue
Block a user