fix(commands): hide rebuild index from user entrypoints

中文: 从命令面板和设置页命令说明中移除重建卡片索引入口,保留底层维护代码。

English: Removes the rebuild index entry from command palette registration and the settings command guide while keeping the underlying maintenance code.
This commit is contained in:
Dusk 2026-04-26 10:50:02 +08:00
parent 2b366bbf1d
commit 9d0e47e0ca
5 changed files with 43 additions and 11 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";
import { registerCommands } from "./registerCommands";
describe("registerCommands", () => {
it("does not expose the maintenance-only rebuild index command", () => {
const commands: Array<{ id: string; name: string; callback: () => void }> = [];
const plugin = {
addCommand(command: { id: string; name: string; callback: () => void }): void {
commands.push(command);
},
};
registerCommands(plugin as never);
expect(commands.map((command) => command.id)).toEqual([
"sync-current-file-to-anki",
"sync-vault-to-anki",
"clear-current-file-synced-cards",
"cleanup-empty-decks",
]);
expect(commands.map((command) => command.id)).not.toContain("rebuild-card-index");
});
});

View file

@ -18,14 +18,6 @@ export function registerCommands(plugin: AnkiHeadingSyncPlugin): void {
},
});
plugin.addCommand({
id: "rebuild-card-index",
name: t("commands.rebuildCardIndex"),
callback: () => {
void plugin.runRebuildCardIndex();
},
});
plugin.addCommand({
id: "clear-current-file-synced-cards",
name: t("commands.clearCurrentFileSyncedCards"),
@ -41,4 +33,4 @@ export function registerCommands(plugin: AnkiHeadingSyncPlugin): void {
void plugin.runCleanupEmptyDecks();
},
});
}
}

View file

@ -1475,4 +1475,21 @@ describe("PluginSettingTab", () => {
"向当前文件插入牌组模板",
]);
});
it("does not show the maintenance-only rebuild index command in the command guide", async () => {
const plugin = new FakePlugin();
const tab = new AnkiHeadingSyncSettingTab(plugin as never);
tab.display();
await queryByDataset(tab.containerEl, "settingsCardToggle", "commands").trigger("click");
const commandsBody = queryByDataset(tab.containerEl, "settingsCardBody", "commands");
const commandCopy = collectTexts(commandsBody).join("\n");
expect(commandCopy).toContain("同步当前文件到 Anki");
expect(commandCopy).toContain("同步全库到 Anki");
expect(commandCopy).toContain("清空当前文件已同步卡片");
expect(commandCopy).toContain("清理空牌组");
expect(commandCopy).not.toContain("重建卡片索引");
expect(commandCopy).not.toContain("只重建本地卡片索引,不创建或更新远端笔记。");
});
});

View file

@ -828,7 +828,6 @@ export class AnkiHeadingSyncSettingTab extends PluginSettingTab {
for (const [name, description] of [
[t("commands.syncCurrentFileToAnki"), t("settings.cards.commands.items.syncCurrentFile")],
[t("commands.syncVaultToAnki"), t("settings.cards.commands.items.syncVault")],
[t("commands.rebuildCardIndex"), t("settings.cards.commands.items.rebuildIndex")],
[t("commands.clearCurrentFileSyncedCards"), t("settings.cards.commands.items.clearCurrentFile")],
[t("commands.cleanupEmptyDecks"), t("settings.cards.commands.items.cleanupDecks")],
]) {