Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/docs/en/flashcards/reviewing.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Although you may want to review or cram all cards across all decks, you often ma
2 | Reset | Reset the review schedule information - the review interval is set to 1 day, and the ease is set to the default value
3 | Info | Shows the scheduling information for the card
4 | Skip | Skip the current card without reviewing
5 | Delete | Delete the card from the note (Ctrl/Cmd + Click to force delete without confirmation)

### Context

Expand Down
1 change: 1 addition & 0 deletions src/data-stores/base/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IDataStore {
questionRemoveScheduleInfo(questionText: string): string;
questionWrite(question: Question): Promise<void>;
questionWriteSchedule(question: Question): Promise<void>;
questionDelete(question: Question): Promise<void>;
}

export class DataStore {
Expand Down
17 changes: 17 additions & 0 deletions src/data-stores/notes/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RepItemStorageInfo } from "src/data-stores/base/rep-item-storage-info";
import { Question } from "src/question";
import { SRSettings } from "src/settings";
import { DateUtil, formatDateYYYYMMDD, globalDateProvider } from "src/utils/dates";
import { MultiLineTextFinder } from "src/utils/strings";

export class StoreInNotes implements IDataStore {
private settings: SRSettings;
Expand Down Expand Up @@ -67,4 +68,20 @@ export class StoreInNotes implements IDataStore {
await question.note.file.write(newText);
question.hasChanged = false;
}

async questionDelete(question: Question): Promise<void> {
const fileText: string = await question.note.file.read();
const originalText: string = question.questionText.original;
const newText = MultiLineTextFinder.findAndReplace(fileText, originalText, "");
if (newText) {
await question.note.file.write(newText);
} else {
console.error(
`questionDelete: Text not found: ${originalText.substring(
0,
100,
)} in note: ${fileText.substring(0, 100)}`,
);
}
}
}
8 changes: 8 additions & 0 deletions src/flashcard-review-sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IFlashcardReviewSequencer {
determineCardSchedule(response: ReviewResponse, card: Card): RepItemScheduleInfo;
processReview(response: ReviewResponse): Promise<void>;
updateCurrentQuestionText(text: string): Promise<void>;
deleteCurrentCardFromNote(): Promise<void>;
}

/**
Expand Down Expand Up @@ -329,4 +330,11 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {

await DataStore.getInstance().questionWrite(this.currentQuestion);
}

async deleteCurrentCardFromNote(): Promise<void> {
const question = this.currentQuestion;
await DataStore.getInstance().questionDelete(question);
this._originalDeckTree.deleteQuestionFromAllDecks(question, false);
this.cardSequencer.deleteCurrentQuestionFromAllDecks();
}
}
34 changes: 34 additions & 0 deletions src/gui/card-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class CardUI {
public resetButton: HTMLButtonElement;
public infoButton: HTMLButtonElement;
public skipButton: HTMLButtonElement;
public deleteButton: HTMLButtonElement;

public response: HTMLDivElement;
public hardButton: HTMLButtonElement;
Expand Down Expand Up @@ -257,6 +258,9 @@ export class CardUI {
this._createResetButton();
this._createCardInfoButton();
this._createSkipButton();
if (this.settings.showDeleteButton) {
this._createDeleteButton();
}
}

private _createEditButton() {
Expand Down Expand Up @@ -304,6 +308,36 @@ export class CardUI {
await this._showNextCard();
}

private _createDeleteButton() {
this.deleteButton = this.controls.createEl("button");
this.deleteButton.addClasses(["sr-button", "sr-delete-button"]);
setIcon(this.deleteButton, "trash");
this.deleteButton.setAttribute("aria-label", t("DELETE_CARD"));
this.deleteButton.addEventListener("click", async (e) => {
await this._deleteCurrentCard(e.ctrlKey || e.metaKey);
});
}

private async _deleteCurrentCard(force: boolean = false): Promise<void> {
const timeNow = now();
if (
this.lastPressed &&
timeNow - this.lastPressed < this.plugin.data.settings.reviewButtonDelay
) {
return;
}
this.lastPressed = timeNow;

if (!force) {
if (!window.confirm(t("DELETE_CARD_CONFIRMATION"))) {
return;
}
}

await this.reviewSequencer.deleteCurrentCardFromNote();
await this._showNextCard();
}

private _displayCurrentCardInfoNotice() {
const schedule = this._currentCard.scheduleInfo;

Expand Down
12 changes: 12 additions & 0 deletions src/gui/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,18 @@ export class SRSettingTab extends PluginSettingTab {
}),
);

new Setting(containerEl)
.setName(t("SHOW_DELETE_BUTTON"))
.setDesc(t("SHOW_DELETE_BUTTON_DESC"))
.addToggle((toggle) =>
toggle
.setValue(this.plugin.data.settings.showDeleteButton)
.onChange(async (value) => {
this.plugin.data.settings.showDeleteButton = value;
await this.plugin.savePluginData();
}),
);

new Setting(containerEl)
.setName(t("CARD_MODAL_HEIGHT_PERCENT"))
.setDesc(t("CARD_MODAL_SIZE_PERCENT_DESC"))
Expand Down
4 changes: 4 additions & 0 deletions src/lang/locale/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/cz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default {
CURRENT_EASE_HELP_TEXT: "Current Ease: ",
CURRENT_INTERVAL_HELP_TEXT: "Current Interval: ",
CARD_GENERATED_FROM: "Generated from: ${notePath}",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",

// main.ts
OPEN_NOTE_FOR_REVIEW: "Open a note for review",
Expand Down Expand Up @@ -99,6 +101,8 @@ export default {
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
CARD_MODAL_HEIGHT_PERCENT: "Flashcard Height Percentage",
CARD_MODAL_SIZE_PERCENT_DESC:
"Should be set to 100% on mobile or if you have very large images",
Expand Down
4 changes: 4 additions & 0 deletions src/lang/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,8 @@ export default {
SEARCH: "Zoeken",
PREVIOUS: "Vorige",
NEXT: "Volgende",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
4 changes: 4 additions & 0 deletions src/lang/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default {
CURRENT_EASE_HELP_TEXT: "目前掌握程度:",
CURRENT_INTERVAL_HELP_TEXT: "目前间隔:",
CARD_GENERATED_FROM: "生成自:${notePath}",
DELETE_CARD: "删除卡片",
DELETE_CARD_CONFIRMATION: "你确定要删除这张卡片吗?",

// main.ts
OPEN_NOTE_FOR_REVIEW: "打开一个笔记开始复习",
Expand Down Expand Up @@ -94,6 +96,8 @@ export default {
SHOW_CARD_CONTEXT_DESC: "例如:标题 > 副标题 > 小标题 > ... > 小标题",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "将下次复习时间显示在复习按钮",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC: "了解你的卡片被推迟了多久对你很有用",
SHOW_DELETE_BUTTON: "显示删除按钮",
SHOW_DELETE_BUTTON_DESC: "在卡片复习界面添加删除按钮。",
CARD_MODAL_HEIGHT_PERCENT: "卡片高度百分比",
CARD_MODAL_SIZE_PERCENT_DESC: "请在移动端使用并需要浏览较大图片时设为100%",
RESET_DEFAULT: "重置为默认",
Expand Down
4 changes: 4 additions & 0 deletions src/lang/locale/zh-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,8 @@ export default {
SEARCH: "Search",
PREVIOUS: "Previous",
NEXT: "Next",
DELETE_CARD: "Delete Card",
DELETE_CARD_CONFIRMATION: "Are you sure you want to delete this card?",
SHOW_DELETE_BUTTON: "Show Delete button",
SHOW_DELETE_BUTTON_DESC: "Add a delete button to the card review UI.",
};
2 changes: 2 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface SRSettings {
flashcardGoodText: string;
flashcardHardText: string;
reviewButtonDelay: number;
showDeleteButton: boolean;
openViewInNewTab: boolean;

// algorithm
Expand Down Expand Up @@ -105,6 +106,7 @@ export const DEFAULT_SETTINGS: SRSettings = {
flashcardGoodText: t("GOOD"),
flashcardHardText: t("HARD"),
reviewButtonDelay: 0,
showDeleteButton: false,
openViewInNewTab: false,

// algorithm
Expand Down
Loading