mirror of
https://github.com/ankitects/anki.git
synced 2026-01-07 02:53:54 -05:00
Added: Undo state
This commit is contained in:
parent
7c683819a2
commit
9f47d7beb1
4 changed files with 27 additions and 3 deletions
|
|
@ -756,6 +756,7 @@ exposed_backend_list = [
|
|||
"get_custom_colours",
|
||||
"set_config_json",
|
||||
"get_config_json",
|
||||
"get_undo_status",
|
||||
"undo",
|
||||
"redo",
|
||||
# DeckService
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Copyright: Ankitects Pty Ltd and contributors
|
||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import "./index.scss";
|
||||
|
||||
import { onMount } from "svelte";
|
||||
|
|
@ -10,13 +10,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import ReviewerBottom from "./reviewer-bottom/ReviewerBottom.svelte";
|
||||
import Reviewer from "./Reviewer.svelte";
|
||||
import { _blockDefaultDragDropBehavior } from "../../reviewer";
|
||||
import type { PageData } from "./$types";
|
||||
|
||||
export let data: PageData;
|
||||
const state = new ReviewerState();
|
||||
|
||||
onMount(() => {
|
||||
updateNightMode();
|
||||
globalThis.anki ??= {};
|
||||
globalThis.anki.changeReceived = () => state.showQuestion(null);
|
||||
_blockDefaultDragDropBehavior();
|
||||
state.undoStatus = data.initialUndoStatus;
|
||||
});
|
||||
$: cardData = state.cardData;
|
||||
$: flag = $cardData?.queue?.cards[0].card?.flags;
|
||||
|
|
|
|||
9
ts/routes/reviewer/+page.ts
Normal file
9
ts/routes/reviewer/+page.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
import { getUndoStatus } from "@generated/backend";
|
||||
import type { PageLoad } from "./$types";
|
||||
|
||||
export const load = (async () => {
|
||||
const initialUndoStatus = await getUndoStatus({});
|
||||
return { initialUndoStatus };
|
||||
}) satisfies PageLoad;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
import type { UndoStatus } from "@generated/anki/collection_pb";
|
||||
import {
|
||||
BuryOrSuspendCardsRequest_Mode,
|
||||
CardAnswer,
|
||||
|
|
@ -59,6 +60,7 @@ export class ReviewerState {
|
|||
tooltipMessageTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
readonly tooltipMessage = writable("");
|
||||
readonly tooltipShown = writable(false);
|
||||
undoStatus: UndoStatus | undefined = undefined;
|
||||
|
||||
iframe: HTMLIFrameElement | undefined = undefined;
|
||||
|
||||
|
|
@ -222,12 +224,16 @@ export class ReviewerState {
|
|||
}
|
||||
case "z": {
|
||||
if (ctrl) {
|
||||
if (shift) {
|
||||
if (shift && this.undoStatus?.redo) {
|
||||
const op = await redo({});
|
||||
this.showTooltip(tr.undoActionRedone({ action: op.operation }));
|
||||
} else {
|
||||
this.undoStatus = op.newStatus;
|
||||
} else if (this.undoStatus?.undo) {
|
||||
const op = await undo({});
|
||||
this.showTooltip(tr.undoActionUndone({ action: op.operation }));
|
||||
this.undoStatus = op.newStatus;
|
||||
} else {
|
||||
this.showTooltip(shift ? tr.actionsNothingToRedo() : tr.actionsNothingToUndo());
|
||||
}
|
||||
this.refresh();
|
||||
}
|
||||
|
|
@ -261,6 +267,10 @@ export class ReviewerState {
|
|||
}
|
||||
|
||||
async showQuestion(answer: CardAnswer | null) {
|
||||
if (answer !== null && this.undoStatus) {
|
||||
this.undoStatus.undo = tr.actionsAnswerCard();
|
||||
}
|
||||
|
||||
const resp = await nextCardData({
|
||||
answer: answer || undefined,
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue