mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
Reimplement sticky field saving
This commit is contained in:
parent
723b54830b
commit
bc26b283a0
3 changed files with 38 additions and 6 deletions
|
@ -812,6 +812,7 @@ exposed_backend_list = [
|
|||
"get_notetype_names",
|
||||
"get_change_notetype_info",
|
||||
"get_cloze_field_ords",
|
||||
"update_notetype",
|
||||
# StatsService
|
||||
"card_stats",
|
||||
"get_review_logs",
|
||||
|
|
|
@ -52,7 +52,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
<script lang="ts">
|
||||
import * as tr from "@generated/ftl";
|
||||
import { bridgeCommand } from "@tslib/bridgecommand";
|
||||
import { onMount, tick } from "svelte";
|
||||
import { onDestroy, onMount, tick } from "svelte";
|
||||
import { get, writable } from "svelte/store";
|
||||
import { nodeIsCommonElement } from "@tslib/dom";
|
||||
|
||||
|
@ -212,6 +212,23 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
stickies = stckies;
|
||||
}
|
||||
|
||||
async function toggleStickyAll() {
|
||||
const values: boolean[] = [];
|
||||
const notetype = await getNotetype({ ntid: notetypeMeta.id });
|
||||
const anySticky = notetype.fields.some((f) => f.config!.sticky);
|
||||
for (const field of notetype.fields) {
|
||||
const sticky = field.config!.sticky;
|
||||
if (!anySticky || sticky) {
|
||||
field.config!.sticky = !sticky;
|
||||
}
|
||||
values.push(field.config!.sticky);
|
||||
}
|
||||
await updateNotetype(notetype);
|
||||
setSticky(values);
|
||||
}
|
||||
|
||||
let deregisterSticky: () => void;
|
||||
|
||||
export function focusField(index: number | null): void {
|
||||
tick().then(() => {
|
||||
if (typeof index === "number") {
|
||||
|
@ -539,6 +556,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
noteFieldsCheck,
|
||||
addNote,
|
||||
addMediaFromPath,
|
||||
updateNotetype,
|
||||
} from "@generated/backend";
|
||||
import { wrapInternal } from "@tslib/wrap";
|
||||
import { getProfileConfig, getMeta, setMeta, getColConfig } from "@tslib/profile";
|
||||
|
@ -561,6 +579,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import PreviewButton from "./PreviewButton.svelte";
|
||||
import { NoteFieldsCheckResponse_State, type Note } from "@generated/anki/notes_pb";
|
||||
import { setupContextMenu } from "./context-menu.svelte";
|
||||
import { registerShortcut } from "@tslib/shortcuts";
|
||||
|
||||
$: isIOImageLoaded = false;
|
||||
$: ioImageLoadedStore.set(isIOImageLoaded);
|
||||
|
@ -863,6 +882,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
}
|
||||
|
||||
onMount(() => {
|
||||
if (mode === "add") {
|
||||
deregisterSticky = registerShortcut(toggleStickyAll, "Shift+F9");
|
||||
}
|
||||
|
||||
function wrap(before: string, after: string): void {
|
||||
if (!$focusedInput || !editingInputIsRichText($focusedInput)) {
|
||||
return;
|
||||
|
@ -920,6 +943,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
return () => document.removeEventListener("visibilitychange", saveOnPageHide);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
deregisterSticky();
|
||||
});
|
||||
|
||||
let apiPartial: Partial<NoteEditorAPI> = {};
|
||||
export { apiPartial as api };
|
||||
|
||||
|
@ -1067,6 +1094,7 @@ components and functionality for general note editing.
|
|||
<StickyBadge
|
||||
bind:active={stickies[index]}
|
||||
{index}
|
||||
{note}
|
||||
show={fields[index] === $hoveredField ||
|
||||
fields[index] === $focusedField}
|
||||
/>
|
||||
|
|
|
@ -4,7 +4,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
-->
|
||||
<script lang="ts">
|
||||
import * as tr from "@generated/ftl";
|
||||
import { bridgeCommand } from "@tslib/bridgecommand";
|
||||
import { getPlatformString, registerShortcut } from "@tslib/shortcuts";
|
||||
import { onEnterOrSpace } from "@tslib/keys";
|
||||
import { onMount } from "svelte";
|
||||
|
@ -15,6 +14,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import { stickyIconSolid } from "$lib/components/icons";
|
||||
|
||||
import { context as editorFieldContext } from "./EditorField.svelte";
|
||||
import type { Note } from "@generated/anki/notes_pb";
|
||||
import { getNotetype, updateNotetype } from "@generated/backend";
|
||||
|
||||
const animated = !document.body.classList.contains("reduce-motion");
|
||||
|
||||
|
@ -25,11 +26,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
const keyCombination = "F9";
|
||||
|
||||
export let index: number;
|
||||
export let note: Note;
|
||||
|
||||
function toggle() {
|
||||
bridgeCommand(`toggleSticky:${index}`, (value: boolean) => {
|
||||
active = value;
|
||||
});
|
||||
async function toggle() {
|
||||
active = !active;
|
||||
const notetype = await getNotetype({ ntid: note.notetypeId });
|
||||
notetype.fields[index].config!.sticky = active;
|
||||
await updateNotetype(notetype);
|
||||
}
|
||||
|
||||
function shortcut(target: HTMLElement): () => void {
|
||||
|
|
Loading…
Reference in a new issue