Skip to content

Commit

Permalink
fix: tree view stub
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinslin committed Dec 13, 2020
1 parent 02fc08a commit ea0e17e
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 294 deletions.
7 changes: 5 additions & 2 deletions packages/engine-server/src/drivers/file/storev2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,11 @@ export class FileStorageV2 implements DStoreV2 {
notes: this.notes,
vault: note.vault,
});
// don't count as delete if we're updating existing note
let noDelete = false;
if (maybeNote?.stub || opts?.updateExisting) {
note = { ...maybeNote, ...note };
noDelete = true;
} else {
changed = await this._writeNewNote({ note, maybeNote, opts });
}
Expand All @@ -711,7 +714,7 @@ export class FileStorageV2 implements DStoreV2 {
notePath: note.fname,
schemaModDict: this.schemas,
});
// order matters - only write file after parents are established
// order matters - only write file after parents are established @see(_writeNewNote)
await note2File({
note,
vault: note.vault,
Expand All @@ -731,7 +734,7 @@ export class FileStorageV2 implements DStoreV2 {
status: "update" as const,
})) as NoteChangeEntry[];
changedEntries.push({ note, status: "create" });
if (maybeNote && !maybeNote.stub) {
if (maybeNote && !noDelete) {
changedEntries.push({ note: maybeNote, status: "delete" });
}
return {
Expand Down
4 changes: 3 additions & 1 deletion packages/engine-server/src/enginev2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,20 @@ export class DendronEngineV2 implements DEngineV2 {
let noteNew: NotePropsV2 | undefined = maybeNote;
let changed: NoteChangeEntry[] = [];
let error = null;
let updateExisting = false;
if ((!maybeNote || maybeNote.stub) && createIfNew) {
this.logger.debug({ ctx, maybeNote, msg: "create-new" });
if (maybeNote?.stub) {
noteNew = maybeNote;
delete noteNew.stub;
updateExisting = true;
} else {
noteNew = NoteUtilsV2.createWithSchema({
noteOpts: { fname: npath, vault },
engine: this,
});
}
changed = (await this.writeNote(noteNew, { newNode: true })).data;
changed = (await this.writeNote(noteNew, { updateExisting })).data;
}
if (!createIfNew && !maybeNote) {
error = new DendronError({ status: "no_note_found" });
Expand Down
11 changes: 0 additions & 11 deletions packages/engine-server/src/markdown/__tests__/utils.spec.ts

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from "./dendronLinksPlugin";
export * from "./replaceRefs";
export * from "./dendronNoteRefPlugin";
export * from "./enrichNode";
export * from "./types";
41 changes: 24 additions & 17 deletions packages/plugin-core/src/commands/GotoNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,30 @@ export class GotoNoteCommand extends BasicCommand<CommandOpts, CommandOutput> {
let pos: undefined | Position;
if (opts.mode === "note") {
const client = DendronWorkspace.instance().getEngine();
const { data } = await client.getNoteByPath({
npath: qs,
createIfNew: true,
vault,
});
const note = data?.note as NotePropsV2;
const npath = NoteUtilsV2.getPathV4({ note, wsRoot: DendronWorkspace.wsRoot() });
const uri = Uri.file(npath);
const editor = await VSCodeUtils.openFileInEditor(uri);
this.L.info({ ctx, opts, msg: "exit" });
if (opts.anchor && editor) {
const text = editor.document.getText();
const pos = findHeaderPos({ anchor: opts.anchor.value, text });
editor.selection = new Selection(pos, pos);
editor.revealRange(editor.selection);
}
return { note, pos };
return DendronWorkspace.instance().pauseWatchers<CommandOutput>(
async () => {
const { data } = await client.getNoteByPath({
npath: qs,
createIfNew: true,
vault,
});
const note = data?.note as NotePropsV2;
const npath = NoteUtilsV2.getPathV4({
note,
wsRoot: DendronWorkspace.wsRoot(),
});
const uri = Uri.file(npath);
const editor = await VSCodeUtils.openFileInEditor(uri);
this.L.info({ ctx, opts, msg: "exit" });
if (opts.anchor && editor) {
const text = editor.document.getText();
const pos = findHeaderPos({ anchor: opts.anchor.value, text });
editor.selection = new Selection(pos, pos);
editor.revealRange(editor.selection);
}
return { note, pos };
}
);
} else {
throw new DendronError({ msg: "goto schema not implemented" });
}
Expand Down
Loading

0 comments on commit ea0e17e

Please sign in to comment.