Skip to content

Commit

Permalink
fix: add selection2link button for CreateScratchNoteCommand (#2496)
Browse files Browse the repository at this point in the history
* fix: add selection2link button for CreateScratchNoteCommand

* chore: add test
  • Loading branch information
hikchoi committed Feb 28, 2022
1 parent 2524589 commit a881757
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/plugin-core/src/commands/CreateScratchNoteCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CopyNoteLinkBtn,
HorizontalSplitBtn,
ScratchBtn,
Selection2LinkBtn,
} from "../components/lookup/buttons";
import { CommandRunOpts as NoteLookupRunOpts } from "./NoteLookupCommand";
import { AutoCompletableRegistrar } from "../utils/registers/AutoCompletableRegistrar";
Expand Down Expand Up @@ -44,6 +45,7 @@ export class CreateScratchNoteCommand extends BasicCommand<
vaultButtonPressed,
extraButtons: [
ScratchBtn.create({ pressed: true, canToggle: false }),
Selection2LinkBtn.create(true),
CopyNoteLinkBtn.create(false),
HorizontalSplitBtn.create(false),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ suite("CreateScratchNoteCommand", function () {

expect(activeNote.fname.startsWith("scratch.")).toBeTruthy();
});
test("THEN selection2link is applied.", async () => {
const ext = ExtensionProvider.getExtension();
const wsUtils = ext.wsUtils;
const cmd = new CreateScratchNoteCommand(ext);
const { vaults, engine } = ext.getDWorkspace();
const note = NoteUtils.getNoteByFnameFromEngine({
fname: "foo",
vault: vaults[0],
engine,
}) as NoteProps;
const fooNoteEditor = await wsUtils.openNote(note);
fooNoteEditor.selection = new vscode.Selection(7, 0, 7, 12);
await cmd.run({ noConfirm: true });
const activeNote = getNoteFromTextEditor();
expect(activeNote.fname.endsWith(".foo-body")).toBeTruthy();
const changedFooNoteText = fooNoteEditor.document.getText();
expect(changedFooNoteText.endsWith(".foo-body]]\n"));
});
}
);
});

0 comments on commit a881757

Please sign in to comment.