Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/common-all/data/dendron-yml.validator.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@
"properties": {
"selectionType": {
"$ref": "#/definitions/LookupSelectionType"
},
"leaveTrace" : {
"type": "boolean"
}
},
"required": [
Expand Down
1 change: 1 addition & 0 deletions packages/common-all/src/types/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export enum LookupSelectionType {

export type NoteLookupConfig = {
selectionType: LookupSelectionType;
leaveTrace?: boolean;
};

export type LookupConfig = {
Expand Down
3 changes: 3 additions & 0 deletions packages/dendron-next-server/data/dendron-yml.validator.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@
"properties": {
"selectionType": {
"$ref": "#/definitions/LookupSelectionType"
},
"leaveTrace": {
"type": "boolean"
}
},
"required": [
Expand Down
18 changes: 16 additions & 2 deletions packages/plugin-core/src/components/lookup/buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
NoteQuickInput,
NoteUtils,
} from "@dendronhq/common-all";
import { DConfig } from "@dendronhq/engine-server";
import _ from "lodash";
import * as vscode from "vscode";
import { QuickInputButton, ThemeIcon } from "vscode";
import { clipboard, DendronClientUtilsV2, VSCodeUtils } from "../../utils";
import { getExtension } from "../../workspace";
import { getDWorkspace, getExtension } from "../../workspace";
import {
DendronQuickPickerV2,
LookupEffectType,
Expand Down Expand Up @@ -96,13 +97,26 @@ const selectionToNoteProps = async (opts: {
switch (selectionType) {
case "selectionExtract": {
if (!_.isUndefined(document)) {
const ws = getDWorkspace();
const leaveTrace =
DConfig.getProp(ws.config, "lookup").note.leaveTrace || false;
const body = "\n" + document.getText(range).trim();
note.body = body;
// don't delete if original file is not in workspace
if (!ext.workspaceService?.isPathInWorkspace(document.uri.fsPath)) {
return note;
}
await VSCodeUtils.deleteRange(document, range as vscode.Range);
if (leaveTrace) {
const editor = VSCodeUtils.getActiveTextEditor();
await editor?.edit((builder) => {
const link = note.fname;
if (!_.isUndefined(selection) && !selection.isEmpty) {
builder.replace(selection, `![[${link}]]`);
}
});
} else {
await VSCodeUtils.deleteRange(document, range as vscode.Range);
}
}
return note;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,14 @@ suite("NoteLookupCommand", function () {
preSetupHook: async ({ wsRoot, vaults }) => {
await ENGINE_HOOKS.setupBasic({ wsRoot, vaults });
},
onInit: async ({ vaults, engine }) => {
onInit: async ({ wsRoot, vaults, engine }) => {
withConfig(
(config) => {
config.lookup.note.leaveTrace = true;
return config;
},
{ wsRoot }
);
const cmd = new NoteLookupCommand();
stubVaultPick(vaults);
const fooNoteEditor = await VSCodeUtils.openNote(engine.notes["foo"]);
Expand All @@ -1143,9 +1150,9 @@ suite("NoteLookupCommand", function () {
newNoteEditor.document
);
expect(newNote?.body.trim()).toEqual("foo body");

// should remove selection
const changedText = fooNoteEditor.document.getText();
expect(changedText.includes(`![[${newNote?.fname}]]`)).toBeTruthy();
expect(changedText.includes("foo body")).toBeFalsy();
done();
},
Expand Down