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
6 changes: 3 additions & 3 deletions src/quickAddApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ describe("utility selection helpers", () => {
expect(api.utility.getSelection()).toBe("");
});

it("getSelectedText reports an error and returns undefined with no view", () => {
it("getSelectedText reports an error and returns '' with no view", () => {
const { api } = getApi();
expect(api.utility.getSelectedText()).toBeUndefined();
expect(api.utility.getSelectedText()).toBe("");
expect(mocks.reportError).toHaveBeenCalled();
});

Expand All @@ -544,7 +544,7 @@ describe("utility selection helpers", () => {
},
});
const { api } = getApi(app);
expect(api.utility.getSelectedText()).toBeUndefined();
expect(api.utility.getSelectedText()).toBe("");
expect(mocks.reportError).toHaveBeenCalled();
});

Expand Down
4 changes: 2 additions & 2 deletions src/quickAddApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,15 @@ export class QuickAddApi {
new Error("No active view"),
"Could not get selected text",
);
return;
return "";
}

if (!activeView.editor.somethingSelected()) {
reportError(
new Error("No text selected"),
"Could not get selected text",
);
return;
return "";
}

return activeView.editor.getSelection();
Expand Down
17 changes: 17 additions & 0 deletions src/services/choiceService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,23 @@ describe("choiceService", () => {
expect(copy.id).not.toBe(original.id);
});

it("preserves command and onePageInput when duplicating a Multi", () => {
const original = createChoice("Multi", "M") as IMultiChoice;
(original as unknown as { command: boolean }).command = true;
(original as unknown as { onePageInput: string }).onePageInput =
"always";
original.choices = [createChoice("Capture", "Child")];

const copy = duplicateChoice(original) as IMultiChoice;

expect(copy.command).toBe(true);
expect(
(copy as unknown as { onePageInput?: string }).onePageInput,
).toBe("always");
// children still duplicated with fresh ids
expect(copy.choices[0].id).not.toBe(original.choices[0].id);
});

it("deep clones a Macro's macro and regenerates ids", () => {
const original = createChoice("Macro", "Mac") as IMacroChoice;
original.macro.commands.push({
Expand Down
6 changes: 4 additions & 2 deletions src/services/choiceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ export function duplicateChoice(choice: IChoice): IChoice {
if (choice.type === "Multi") {
const newMulti = newChoice as IMultiChoice;
const sourceMulti = choice as IMultiChoice;
// Preserve command/onePageInput/placeholder/collapsed etc. (symmetry with
// the other choice types). `choices` is excluded here and set via the
// recursive map below so children get fresh ids, not the source's.
Object.assign(newMulti, excludeKeys(sourceMulti, ["id", "name", "choices"]));
newMulti.choices = sourceMulti.choices.map(duplicateChoice);
newMulti.placeholder = sourceMulti.placeholder;
newMulti.collapsed = sourceMulti.collapsed;
return newMulti;
}

Expand Down
8 changes: 4 additions & 4 deletions src/services/packageImportService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ describe("parseQuickAddPackage", () => {
);
});

it("throws when schema version is newer than supported", () => {
// isQuickAddPackage requires schemaVersion === current, so a too-new
// version is rejected by the validator before the explicit version check.
it("throws a version-specific error when the schema version is newer than supported", () => {
const future = {
...makePackage(),
schemaVersion: QUICKADD_PACKAGE_SCHEMA_VERSION + 1,
};
expect(() => parseQuickAddPackage(JSON.stringify(future))).toThrow();
expect(() => parseQuickAddPackage(JSON.stringify(future))).toThrow(
/newer than this plugin supports/,
);
});

it("rejects a package whose choices are missing required fields", () => {
Expand Down
9 changes: 7 additions & 2 deletions src/types/packages/QuickAddPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface QuickAddPackageChoice {
}

export interface QuickAddPackage {
schemaVersion: typeof QUICKADD_PACKAGE_SCHEMA_VERSION;
schemaVersion: number;
quickAddVersion: string;
createdAt: string;
rootChoiceIds: string[];
Expand Down Expand Up @@ -85,8 +85,13 @@ export function isQuickAddPackage(value: unknown): value is QuickAddPackage {
assets,
} = value;

// Structural check only — parseQuickAddPackage owns the version-range check so
// a too-new package gets a specific "newer than supported" error instead of
// this generic one.
const schemaMatches =
schemaVersion === QUICKADD_PACKAGE_SCHEMA_VERSION;
typeof schemaVersion === "number" &&
Number.isInteger(schemaVersion) &&
schemaVersion >= 1;

return (
schemaMatches &&
Expand Down
Loading