fix: assign active tag when creating a new note
This commit is contained in:
@@ -152,10 +152,20 @@ export class AppState {
|
|||||||
*/
|
*/
|
||||||
async createEditor(title?: string) {
|
async createEditor(title?: string) {
|
||||||
const activeEditor = this.getActiveEditor();
|
const activeEditor = this.getActiveEditor();
|
||||||
|
const activeTagUuid = this.selectedTag
|
||||||
|
? this.selectedTag.isSmartTag()
|
||||||
|
? undefined
|
||||||
|
: this.selectedTag.uuid
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (!activeEditor || this.multiEditorEnabled) {
|
if (!activeEditor || this.multiEditorEnabled) {
|
||||||
this.application.editorGroup.createEditor(undefined, title);
|
this.application.editorGroup.createEditor(
|
||||||
|
undefined,
|
||||||
|
title,
|
||||||
|
activeTagUuid
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await activeEditor.reset(title);
|
await activeEditor.reset(title, activeTagUuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { SNNote, ContentType, PayloadSource } from 'snjs';
|
import { SNNote, ContentType, PayloadSource, UuidString, TagMutator } from 'snjs';
|
||||||
import { WebApplication } from './application';
|
import { WebApplication } from './application';
|
||||||
|
|
||||||
export class Editor {
|
export class Editor {
|
||||||
@@ -12,15 +12,16 @@ export class Editor {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
application: WebApplication,
|
application: WebApplication,
|
||||||
noteUuid?: string,
|
noteUuid: string | undefined,
|
||||||
noteTitle?: string
|
noteTitle: string | undefined,
|
||||||
|
noteTag: UuidString | undefined
|
||||||
) {
|
) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
if (noteUuid) {
|
if (noteUuid) {
|
||||||
this.note = application.findItem(noteUuid) as SNNote;
|
this.note = application.findItem(noteUuid) as SNNote;
|
||||||
this.streamItems();
|
this.streamItems();
|
||||||
} else {
|
} else {
|
||||||
this.reset(noteTitle)
|
this.reset(noteTitle, noteTag)
|
||||||
.then(() => this.streamItems())
|
.then(() => this.streamItems())
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,10 @@ export class Editor {
|
|||||||
* Reverts the editor to a blank state, removing any existing note from view,
|
* Reverts the editor to a blank state, removing any existing note from view,
|
||||||
* and creating a placeholder note.
|
* and creating a placeholder note.
|
||||||
*/
|
*/
|
||||||
async reset(noteTitle = '') {
|
async reset(
|
||||||
|
noteTitle = '',
|
||||||
|
noteTag?: UuidString,
|
||||||
|
) {
|
||||||
const note = await this.application.createTemplateItem(
|
const note = await this.application.createTemplateItem(
|
||||||
ContentType.Note,
|
ContentType.Note,
|
||||||
{
|
{
|
||||||
@@ -74,6 +78,11 @@ export class Editor {
|
|||||||
references: []
|
references: []
|
||||||
}
|
}
|
||||||
) as SNNote;
|
) as SNNote;
|
||||||
|
if (noteTag) {
|
||||||
|
await this.application.changeItem<TagMutator>(noteTag, (m) => {
|
||||||
|
m.addItemAsRelationship(note);
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!this.isTemplateNote || this.note.title !== note.title) {
|
if (!this.isTemplateNote || this.note.title !== note.title) {
|
||||||
this.setNote(note as SNNote, true);
|
this.setNote(note as SNNote, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { removeFromArray } from 'snjs';
|
import { removeFromArray, UuidString } from 'snjs';
|
||||||
import { Editor } from './editor';
|
import { Editor } from './editor';
|
||||||
import { WebApplication } from './application';
|
import { WebApplication } from './application';
|
||||||
|
|
||||||
@@ -21,8 +21,12 @@ export class EditorGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createEditor(noteUuid?: string, noteTitle?: string) {
|
createEditor(
|
||||||
const editor = new Editor(this.application, noteUuid, noteTitle);
|
noteUuid?: string,
|
||||||
|
noteTitle?: string,
|
||||||
|
noteTag?: UuidString
|
||||||
|
) {
|
||||||
|
const editor = new Editor(this.application, noteUuid, noteTitle, noteTag);
|
||||||
this.editors.push(editor);
|
this.editors.push(editor);
|
||||||
this.notifyObservers();
|
this.notifyObservers();
|
||||||
}
|
}
|
||||||
@@ -72,4 +76,4 @@ export class EditorGroup {
|
|||||||
observer();
|
observer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user