Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 11 additions & 3 deletions packages/common-all/data/dendron-yml.validator.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@
"maxNoteLength": {
"type": "number",
"description": "Notes that are too large can cause serious slowdowns for Dendron. For notes longer than this many characters, some features like backlinks will be disabled to avoid slowdowns. Other functionality like note lookups will continue to function.\n\nDefaults to 204800 characters, which is about 200 KiB."
},
"maxNoteDecoratedLength": {
"type": "number",
"description": "Notes that are too large can cause slowdowns when editing them. For notes longer than this many characters, some editor decorations like tag colors and broken link highlighting will be disabled. Other decorations will continue to function.\n\nDefaults to 4096 characters, which is about 4 KiB."
}
},
"required": [
Expand Down Expand Up @@ -214,14 +218,14 @@
},
"siteIndex": {
"type": "string",
"description": "By default, the domain of your `siteHiearchies` page"
"description": "By default, the domain of your `siteHierarchies` page"
},
"siteHierarchies": {
"type": "array",
"items": {
"type": "string"
},
"description": "Hiearchies to publish"
"description": "Hierarchies to publish"
},
"siteLastModified": {
"type": "boolean",
Expand Down Expand Up @@ -545,10 +549,14 @@
"properties": {
"selectionType": {
"$ref": "#/definitions/LookupSelectionType"
},
"leaveTrace": {
"type": "boolean"
}
},
"required": [
"selectionType"
"selectionType",
"leaveTrace"
],
"additionalProperties": false
},
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
14 changes: 11 additions & 3 deletions packages/dendron-next-server/data/dendron-yml.validator.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@
"maxNoteLength": {
"type": "number",
"description": "Notes that are too large can cause serious slowdowns for Dendron. For notes longer than this many characters, some features like backlinks will be disabled to avoid slowdowns. Other functionality like note lookups will continue to function.\n\nDefaults to 204800 characters, which is about 200 KiB."
},
"maxNoteDecoratedLength": {
"type": "number",
"description": "Notes that are too large can cause slowdowns when editing them. For notes longer than this many characters, some editor decorations like tag colors and broken link highlighting will be disabled. Other decorations will continue to function.\n\nDefaults to 4096 characters, which is about 4 KiB."
}
},
"required": [
Expand Down Expand Up @@ -214,14 +218,14 @@
},
"siteIndex": {
"type": "string",
"description": "By default, the domain of your `siteHiearchies` page"
"description": "By default, the domain of your `siteHierarchies` page"
},
"siteHierarchies": {
"type": "array",
"items": {
"type": "string"
},
"description": "Hiearchies to publish"
"description": "Hierarchies to publish"
},
"siteLastModified": {
"type": "boolean",
Expand Down Expand Up @@ -545,10 +549,14 @@
"properties": {
"selectionType": {
"$ref": "#/definitions/LookupSelectionType"
},
"leaveTrace": {
"type": "boolean"
}
},
"required": [
"selectionType"
"selectionType",
"leaveTrace"
],
"additionalProperties": false
},
Expand Down
9 changes: 7 additions & 2 deletions packages/dendron-next-server/pages/workspace/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
Switch,
useToast,
} from "@chakra-ui/react";
import { NoteAddBehavior, DendronConfig, LookupSelectionType } from "@dendronhq/common-all";
import {
NoteAddBehavior,
DendronConfig,
LookupSelectionType,
} from "@dendronhq/common-all";
import { Field, FieldArray, Form, Formik } from "formik";
import _, { get } from "lodash";
import Head from "next/head";
Expand All @@ -37,7 +41,8 @@ const genDefaultConfig = (): DendronConfig => ({
lookup: {
note: {
selectionType: LookupSelectionType.selectionExtract,
}
leaveTrace: false,
},
},
journal: {
dailyDomain: "daily",
Expand Down
1 change: 1 addition & 0 deletions packages/engine-server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class DConfig {
lookup: {
note: {
selectionType: LookupSelectionType.selectionExtract,
leaveTrace: false,
},
},
journal: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -130,6 +131,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -210,6 +212,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -257,6 +260,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -321,6 +325,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -124,6 +125,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -204,6 +206,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -251,6 +254,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -315,6 +319,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -386,6 +391,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down Expand Up @@ -444,6 +450,7 @@ dev:
lookup:
note:
selectionType: selectionExtract
leaveTrace: false
journal:
dailyDomain: daily
name: journal
Expand Down
24 changes: 22 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, getEngine, getExtension } from "../../workspace";
import {
DendronQuickPickerV2,
LookupEffectType,
Expand Down Expand Up @@ -96,13 +97,32 @@ 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();
const link = NoteUtils.createWikiLink({
note,
useVaultPrefix: DendronClientUtilsV2.shouldUseVaultPrefix(
getEngine()
),
alias: { mode: "title" },
});
await editor?.edit((builder) => {
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 @@ -164,6 +164,7 @@ suite("Extension", function () {
lookup: {
note: {
selectionType: "selectionExtract",
leaveTrace: false,
},
},
journal: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,52 @@ suite("NoteLookupCommand", function () {
},
});
});
test("leave trace on selectionExtract", (done) => {
runLegacyMultiWorkspaceTest({
ctx,
preSetupHook: async ({ wsRoot, vaults }) => {
await ENGINE_HOOKS.setupBasic({ wsRoot, vaults });
},
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"]);

// selects "foo body"
fooNoteEditor.selection = new vscode.Selection(7, 0, 7, 12);
const { text } = VSCodeUtils.getSelection();
expect(text).toEqual("foo body");

await cmd.run({
selectionType: "selectionExtract",
initialValue: "foo.extracted",
noConfirm: true,
});

// should create foo.extracted.md with an selected text as body.
expect(getActiveEditorBasename().endsWith("foo.extracted.md"));
const newNoteEditor = VSCodeUtils.getActiveTextEditorOrThrow();
const newNote = VSCodeUtils.getNoteFromDocument(
newNoteEditor.document
);
expect(newNote?.body.trim()).toEqual("foo body");
// should remove selection
const changedText = fooNoteEditor.document.getText();
expect(
changedText.includes(`![[${newNote?.title}|${newNote?.fname}]]`)
).toBeTruthy();
expect(changedText.includes("foo body")).toBeFalsy();
done();
},
});
});

test("selectionExtract from file not in known vault", (done) => {
runLegacyMultiWorkspaceTest({
Expand Down