Merge branch 'develop' into feature/multiple-selection
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
||||
STRING_ELLIPSES,
|
||||
STRING_DELETE_PLACEHOLDER_ATTEMPT,
|
||||
STRING_DELETE_LOCKED_ATTEMPT,
|
||||
STRING_EDIT_LOCKED_ATTEMPT,
|
||||
StringDeleteNote,
|
||||
StringEmptyTrash,
|
||||
} from '@/strings';
|
||||
@@ -88,11 +89,15 @@ type EditorState = {
|
||||
};
|
||||
|
||||
type EditorValues = {
|
||||
title?: string;
|
||||
text?: string;
|
||||
title: string;
|
||||
text: string;
|
||||
tagsInputValue?: string;
|
||||
};
|
||||
|
||||
function copyEditorValues(values: EditorValues) {
|
||||
return Object.assign({}, values);
|
||||
}
|
||||
|
||||
function sortAlphabetically(array: SNComponent[]): SNComponent[] {
|
||||
return array.sort((a, b) =>
|
||||
a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1
|
||||
@@ -110,7 +115,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
private saveTimeout?: ng.IPromise<void>;
|
||||
private statusTimeout?: ng.IPromise<void>;
|
||||
private lastEditorFocusEventSource?: EventSource;
|
||||
public editorValues: EditorValues = {};
|
||||
public editorValues: EditorValues = { title: '', text: '' };
|
||||
onEditorLoad?: () => void;
|
||||
|
||||
private tags: SNTag[] = [];
|
||||
@@ -198,9 +203,12 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
if (!this.editorValues.text) {
|
||||
this.editorValues.text = note.text;
|
||||
}
|
||||
if (note.lastSyncBegan) {
|
||||
if (note.lastSyncBegan || note.dirty) {
|
||||
if (note.lastSyncEnd) {
|
||||
if (note.lastSyncBegan!.getTime() > note.lastSyncEnd!.getTime()) {
|
||||
if (
|
||||
note.dirty ||
|
||||
note.lastSyncBegan!.getTime() > note.lastSyncEnd!.getTime()
|
||||
) {
|
||||
this.showSavingStatus();
|
||||
} else if (
|
||||
note.lastSyncEnd!.getTime() > note.lastSyncBegan!.getTime()
|
||||
@@ -301,6 +309,9 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
this.reloadPreferences();
|
||||
this.reloadStackComponents();
|
||||
this.reloadNoteTagsComponent();
|
||||
if (note.dirty) {
|
||||
this.showSavingStatus();
|
||||
}
|
||||
if (note.safeText().length === 0 && !showProtectedWarning) {
|
||||
this.focusTitle();
|
||||
}
|
||||
@@ -408,6 +419,10 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
if (this.appState.getActiveEditor()?.isTemplateNote) {
|
||||
await this.appState.getActiveEditor().insertTemplatedNote();
|
||||
}
|
||||
if (this.note.locked) {
|
||||
this.application.alertService.alert(STRING_EDIT_LOCKED_ATTEMPT);
|
||||
return;
|
||||
}
|
||||
if (!component) {
|
||||
if (!this.note.prefersPlainEditor) {
|
||||
await this.application.changeItem(this.note.uuid, (mutator) => {
|
||||
@@ -464,26 +479,30 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
* close the editor (if we closed the editor before sync began, we'd get an exception,
|
||||
* since the debouncer will be triggered on a non-existent editor)
|
||||
*/
|
||||
async saveNote(
|
||||
async save(
|
||||
note: SNNote,
|
||||
editorValues: EditorValues,
|
||||
bypassDebouncer = false,
|
||||
isUserModified = false,
|
||||
dontUpdatePreviews = false,
|
||||
customMutate?: (mutator: NoteMutator) => void,
|
||||
closeAfterSync = false
|
||||
) {
|
||||
const title = editorValues.title;
|
||||
const text = editorValues.text;
|
||||
const isTemplate = this.editor.isTemplateNote;
|
||||
const selectedTag = this.appState.selectedTag;
|
||||
if (document.hidden) {
|
||||
this.application.alertService!.alert(STRING_SAVING_WHILE_DOCUMENT_HIDDEN);
|
||||
this.application.alertService.alert(STRING_SAVING_WHILE_DOCUMENT_HIDDEN);
|
||||
return;
|
||||
}
|
||||
const note = this.note;
|
||||
if (note.deleted) {
|
||||
this.application.alertService!.alert(STRING_DELETED_NOTE);
|
||||
this.application.alertService.alert(STRING_DELETED_NOTE);
|
||||
return;
|
||||
}
|
||||
if (this.editor.isTemplateNote) {
|
||||
if (isTemplate) {
|
||||
await this.editor.insertTemplatedNote();
|
||||
}
|
||||
const selectedTag = this.appState.selectedTag;
|
||||
if (
|
||||
!selectedTag?.isSmartTag &&
|
||||
!selectedTag?.hasRelationshipWithItem(note)
|
||||
@@ -493,7 +512,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
});
|
||||
}
|
||||
if (!this.application.findItem(note.uuid)) {
|
||||
this.application.alertService!.alert(STRING_INVALID_NOTE);
|
||||
this.application.alertService.alert(STRING_INVALID_NOTE);
|
||||
return;
|
||||
}
|
||||
await this.application.changeItem(
|
||||
@@ -503,12 +522,12 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
if (customMutate) {
|
||||
customMutate(noteMutator);
|
||||
}
|
||||
noteMutator.title = this.editorValues.title!;
|
||||
noteMutator.text = this.editorValues.text!;
|
||||
noteMutator.title = title;
|
||||
noteMutator.text = text;
|
||||
if (!dontUpdatePreviews) {
|
||||
const text = this.editorValues.text || '';
|
||||
const truncate = text.length > NOTE_PREVIEW_CHAR_LIMIT;
|
||||
const substring = text.substring(0, NOTE_PREVIEW_CHAR_LIMIT);
|
||||
const noteText = text || '';
|
||||
const truncate = noteText.length > NOTE_PREVIEW_CHAR_LIMIT;
|
||||
const substring = noteText.substring(0, NOTE_PREVIEW_CHAR_LIMIT);
|
||||
const previewPlain = substring + (truncate ? STRING_ELLIPSES : '');
|
||||
noteMutator.preview_plain = previewPlain;
|
||||
noteMutator.preview_html = undefined;
|
||||
@@ -541,7 +560,8 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
syncTakingTooLong: false,
|
||||
});
|
||||
this.setStatus({
|
||||
message: 'All changes saved' + (this.application.noAccount() ? ' offline' : ''),
|
||||
message:
|
||||
'All changes saved' + (this.application.noAccount() ? ' offline' : ''),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -583,7 +603,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
}
|
||||
|
||||
contentChanged() {
|
||||
this.saveNote(false, true);
|
||||
this.save(this.note, copyEditorValues(this.editorValues), false, true);
|
||||
}
|
||||
|
||||
onTitleEnter($event: Event) {
|
||||
@@ -593,7 +613,13 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
}
|
||||
|
||||
onTitleChange() {
|
||||
this.saveNote(false, true, true);
|
||||
this.save(
|
||||
this.note,
|
||||
copyEditorValues(this.editorValues),
|
||||
false,
|
||||
true,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
focusEditor() {
|
||||
@@ -653,9 +679,16 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
if (permanently) {
|
||||
this.performNoteDeletion(this.note);
|
||||
} else {
|
||||
this.saveNote(true, false, true, (mutator) => {
|
||||
mutator.trashed = true;
|
||||
});
|
||||
this.save(
|
||||
this.note,
|
||||
copyEditorValues(this.editorValues),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
(mutator) => {
|
||||
mutator.trashed = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -665,7 +698,9 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
}
|
||||
|
||||
restoreTrashedNote() {
|
||||
this.saveNote(
|
||||
this.save(
|
||||
this.note,
|
||||
copyEditorValues(this.editorValues),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
@@ -698,15 +733,31 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
}
|
||||
|
||||
togglePin() {
|
||||
this.saveNote(true, false, true, (mutator) => {
|
||||
mutator.pinned = !this.note.pinned;
|
||||
});
|
||||
const note = this.note;
|
||||
this.save(
|
||||
note,
|
||||
copyEditorValues(this.editorValues),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
(mutator) => {
|
||||
mutator.pinned = !note.pinned;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
toggleLockNote() {
|
||||
this.saveNote(true, false, true, (mutator) => {
|
||||
mutator.locked = !this.note.locked;
|
||||
});
|
||||
const note = this.note;
|
||||
this.save(
|
||||
note,
|
||||
copyEditorValues(this.editorValues),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
(mutator) => {
|
||||
mutator.locked = !note.locked;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async toggleProtectNote() {
|
||||
@@ -723,29 +774,40 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
}
|
||||
|
||||
toggleNotePreview() {
|
||||
this.saveNote(true, false, true, (mutator) => {
|
||||
mutator.hidePreview = !this.note.hidePreview;
|
||||
});
|
||||
const note = this.note;
|
||||
this.save(
|
||||
note,
|
||||
copyEditorValues(this.editorValues),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
(mutator) => {
|
||||
mutator.hidePreview = !note.hidePreview;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
toggleArchiveNote() {
|
||||
if (this.note.locked) {
|
||||
const note = this.note;
|
||||
if (note.locked) {
|
||||
alertDialog({
|
||||
text: this.note.archived
|
||||
text: note.archived
|
||||
? STRING_UNARCHIVE_LOCKED_ATTEMPT
|
||||
: STRING_ARCHIVE_LOCKED_ATTEMPT,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.saveNote(
|
||||
this.save(
|
||||
note,
|
||||
copyEditorValues(this.editorValues),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
(mutator) => {
|
||||
mutator.archived = !this.note.archived;
|
||||
mutator.archived = !note.archived;
|
||||
},
|
||||
/** If we are unarchiving, and we are in the archived tag, close the editor */
|
||||
this.note.archived && this.appState.selectedTag?.isArchiveTag
|
||||
note.archived && this.appState.selectedTag?.isArchiveTag
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1176,7 +1238,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
editor.selectionStart = editor.selectionEnd = start + 4;
|
||||
}
|
||||
this.editorValues.text = editor.value;
|
||||
this.saveNote(true);
|
||||
this.save(this.note, copyEditorValues(this.editorValues), true);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
.sk-button.contrast.wide(
|
||||
ng-click='self.createNewNote()',
|
||||
title='Create a new note in the selected tag'
|
||||
)
|
||||
aria-label="Create new note"
|
||||
)
|
||||
.sk-label
|
||||
i.icon.ion-plus.add-button
|
||||
.filter-section(role='search')
|
||||
|
||||
Reference in New Issue
Block a user