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_notetype_names",
|
||||||
"get_change_notetype_info",
|
"get_change_notetype_info",
|
||||||
"get_cloze_field_ords",
|
"get_cloze_field_ords",
|
||||||
|
"update_notetype",
|
||||||
# StatsService
|
# StatsService
|
||||||
"card_stats",
|
"card_stats",
|
||||||
"get_review_logs",
|
"get_review_logs",
|
||||||
|
|
|
@ -52,7 +52,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "@generated/ftl";
|
import * as tr from "@generated/ftl";
|
||||||
import { bridgeCommand } from "@tslib/bridgecommand";
|
import { bridgeCommand } from "@tslib/bridgecommand";
|
||||||
import { onMount, tick } from "svelte";
|
import { onDestroy, onMount, tick } from "svelte";
|
||||||
import { get, writable } from "svelte/store";
|
import { get, writable } from "svelte/store";
|
||||||
import { nodeIsCommonElement } from "@tslib/dom";
|
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;
|
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 {
|
export function focusField(index: number | null): void {
|
||||||
tick().then(() => {
|
tick().then(() => {
|
||||||
if (typeof index === "number") {
|
if (typeof index === "number") {
|
||||||
|
@ -539,6 +556,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
noteFieldsCheck,
|
noteFieldsCheck,
|
||||||
addNote,
|
addNote,
|
||||||
addMediaFromPath,
|
addMediaFromPath,
|
||||||
|
updateNotetype,
|
||||||
} from "@generated/backend";
|
} from "@generated/backend";
|
||||||
import { wrapInternal } from "@tslib/wrap";
|
import { wrapInternal } from "@tslib/wrap";
|
||||||
import { getProfileConfig, getMeta, setMeta, getColConfig } from "@tslib/profile";
|
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 PreviewButton from "./PreviewButton.svelte";
|
||||||
import { NoteFieldsCheckResponse_State, type Note } from "@generated/anki/notes_pb";
|
import { NoteFieldsCheckResponse_State, type Note } from "@generated/anki/notes_pb";
|
||||||
import { setupContextMenu } from "./context-menu.svelte";
|
import { setupContextMenu } from "./context-menu.svelte";
|
||||||
|
import { registerShortcut } from "@tslib/shortcuts";
|
||||||
|
|
||||||
$: isIOImageLoaded = false;
|
$: isIOImageLoaded = false;
|
||||||
$: ioImageLoadedStore.set(isIOImageLoaded);
|
$: ioImageLoadedStore.set(isIOImageLoaded);
|
||||||
|
@ -863,6 +882,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
if (mode === "add") {
|
||||||
|
deregisterSticky = registerShortcut(toggleStickyAll, "Shift+F9");
|
||||||
|
}
|
||||||
|
|
||||||
function wrap(before: string, after: string): void {
|
function wrap(before: string, after: string): void {
|
||||||
if (!$focusedInput || !editingInputIsRichText($focusedInput)) {
|
if (!$focusedInput || !editingInputIsRichText($focusedInput)) {
|
||||||
return;
|
return;
|
||||||
|
@ -920,6 +943,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
return () => document.removeEventListener("visibilitychange", saveOnPageHide);
|
return () => document.removeEventListener("visibilitychange", saveOnPageHide);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
deregisterSticky();
|
||||||
|
});
|
||||||
|
|
||||||
let apiPartial: Partial<NoteEditorAPI> = {};
|
let apiPartial: Partial<NoteEditorAPI> = {};
|
||||||
export { apiPartial as api };
|
export { apiPartial as api };
|
||||||
|
|
||||||
|
@ -1067,6 +1094,7 @@ components and functionality for general note editing.
|
||||||
<StickyBadge
|
<StickyBadge
|
||||||
bind:active={stickies[index]}
|
bind:active={stickies[index]}
|
||||||
{index}
|
{index}
|
||||||
|
{note}
|
||||||
show={fields[index] === $hoveredField ||
|
show={fields[index] === $hoveredField ||
|
||||||
fields[index] === $focusedField}
|
fields[index] === $focusedField}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -4,7 +4,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "@generated/ftl";
|
import * as tr from "@generated/ftl";
|
||||||
import { bridgeCommand } from "@tslib/bridgecommand";
|
|
||||||
import { getPlatformString, registerShortcut } from "@tslib/shortcuts";
|
import { getPlatformString, registerShortcut } from "@tslib/shortcuts";
|
||||||
import { onEnterOrSpace } from "@tslib/keys";
|
import { onEnterOrSpace } from "@tslib/keys";
|
||||||
import { onMount } from "svelte";
|
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 { stickyIconSolid } from "$lib/components/icons";
|
||||||
|
|
||||||
import { context as editorFieldContext } from "./EditorField.svelte";
|
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");
|
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";
|
const keyCombination = "F9";
|
||||||
|
|
||||||
export let index: number;
|
export let index: number;
|
||||||
|
export let note: Note;
|
||||||
|
|
||||||
function toggle() {
|
async function toggle() {
|
||||||
bridgeCommand(`toggleSticky:${index}`, (value: boolean) => {
|
active = !active;
|
||||||
active = value;
|
const notetype = await getNotetype({ ntid: note.notetypeId });
|
||||||
});
|
notetype.fields[index].config!.sticky = active;
|
||||||
|
await updateNotetype(notetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortcut(target: HTMLElement): () => void {
|
function shortcut(target: HTMLElement): () => void {
|
||||||
|
|
Loading…
Reference in a new issue