From 21cc284abe99169e3107d02c8b51b236ef863f02 Mon Sep 17 00:00:00 2001 From: phwoo <31812171+phwoo@users.noreply.github.com> Date: Fri, 5 Aug 2022 14:47:38 +1000 Subject: [PATCH 1/5] Updated permalink to architecture visualization (#2001) * updated permalink to architecture visualization * updated architecture visualization link --- docs/architecture.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index e0d13c081..990137b2b 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -6,9 +6,9 @@ Very brief notes for now. At the highest level, Anki is logically separated into two parts. -A neat visualization -of the file layout is available here: - +A neat visualization of the file layout is available here: + +(or go to and enter `ankitects/anki`). ### Library (rslib & pylib) From a338271d55a45eb37a2d5af8987cb9a27be56607 Mon Sep 17 00:00:00 2001 From: phwoo <31812171+phwoo@users.noreply.github.com> Date: Fri, 5 Aug 2022 14:48:07 +1000 Subject: [PATCH 2/5] Narrow typehints within pylib (#2003) * narrowed type hints * narrowed type Any * narrowed type Any * narrow type Any --- pylib/anki/exporting.py | 4 ++-- pylib/anki/latex.py | 3 +-- pylib/anki/media.py | 4 ++-- pylib/anki/notes.py | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pylib/anki/exporting.py b/pylib/anki/exporting.py index 7e61aaa35..410a6f145 100644 --- a/pylib/anki/exporting.py +++ b/pylib/anki/exporting.py @@ -313,7 +313,7 @@ class AnkiExporter(Exporter): # such as update the deck description pass - def removeSystemTags(self, tags: str) -> Any: + def removeSystemTags(self, tags: str) -> str: return self.src.tags.rem_from_str("marked leech", tags) def _modelHasMedia(self, model, fname) -> bool: @@ -464,7 +464,7 @@ class AnkiCollectionPackage21bExporter(AnkiCollectionPackageExporter): def exporters(col: Collection) -> list[tuple[str, Any]]: - def id(obj): + def id(obj) -> tuple[str, Exporter]: if callable(obj.key): key_str = obj.key(col) else: diff --git a/pylib/anki/latex.py b/pylib/anki/latex.py index 56d7415a9..c2033523b 100644 --- a/pylib/anki/latex.py +++ b/pylib/anki/latex.py @@ -7,7 +7,6 @@ import html import os import re from dataclasses import dataclass -from typing import Any import anki import anki.collection @@ -168,7 +167,7 @@ def _save_latex_image( log.close() -def _err_msg(col: anki.collection.Collection, type: str, texpath: str) -> Any: +def _err_msg(col: anki.collection.Collection, type: str, texpath: str) -> str: msg = f"{col.tr.media_error_executing(val=type)}
" msg += f"{col.tr.media_generated_file(val=texpath)}
" try: diff --git a/pylib/anki/media.py b/pylib/anki/media.py index 86e3589cf..a571f03b0 100644 --- a/pylib/anki/media.py +++ b/pylib/anki/media.py @@ -8,7 +8,7 @@ import pprint import re import sys import time -from typing import Any, Callable +from typing import Callable from anki import media_pb2 from anki._legacy import DeprecatedNamesMixin, deprecated_keywords @@ -142,7 +142,7 @@ class MediaManager(DeprecatedNamesMixin): files.append(fname) return files - def transform_names(self, txt: str, func: Callable) -> Any: + def transform_names(self, txt: str, func: Callable) -> str: for reg in self.regexps: txt = re.sub(reg, func, txt) return txt diff --git a/pylib/anki/notes.py b/pylib/anki/notes.py index 9e6d6f153..1ca6f60ef 100644 --- a/pylib/anki/notes.py +++ b/pylib/anki/notes.py @@ -4,7 +4,7 @@ from __future__ import annotations import copy -from typing import Any, NewType, Sequence +from typing import NewType, Sequence import anki # pylint: disable=unused-import import anki.cards @@ -182,7 +182,7 @@ class Note(DeprecatedNamesMixin): "Add tag. Duplicates will be stripped on save." self.tags.append(tag) - def string_tags(self) -> Any: + def string_tags(self) -> str: return self.col.tags.join(self.tags) def set_tags_from_str(self, tags: str) -> None: From 4ea370959ba0e880e6ff3988d7ae81be2a1b2a17 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sun, 7 Aug 2022 17:01:25 +0200 Subject: [PATCH 3/5] Fix flicker when remapping imported notetype field (#2005) --- ts/import-csv/FieldMapper.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ts/import-csv/FieldMapper.svelte b/ts/import-csv/FieldMapper.svelte index 4a80367f0..26c9ed09e 100644 --- a/ts/import-csv/FieldMapper.svelte +++ b/ts/import-csv/FieldMapper.svelte @@ -13,10 +13,21 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let columnOptions: ColumnOption[]; export let tagsColumn: number; export let globalNotetype: ImportExport.CsvMetadata.MappedNotetype | null; + + let lastNotetypeId: number | undefined = -1; + let fieldNamesPromise: Promise; + + $: if (globalNotetype?.id !== lastNotetypeId) { + lastNotetypeId = globalNotetype?.id; + fieldNamesPromise = + globalNotetype === null + ? Promise.resolve([]) + : getNotetypeFields(globalNotetype.id); + } {#if globalNotetype} - {#await getNotetypeFields(globalNotetype.id) then fieldNames} + {#await fieldNamesPromise then fieldNames} {#each fieldNames as label, idx} Date: Mon, 8 Aug 2022 10:55:21 +1000 Subject: [PATCH 4/5] Fix {{CardFlags}} not working with flags 5-7 https://forums.ankiweb.net/t/please-activate-flags-5-7-on-the-cardflag/22143 --- rslib/src/notetype/render.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/rslib/src/notetype/render.rs b/rslib/src/notetype/render.rs index 2ef54cb07..9083d9080 100644 --- a/rslib/src/notetype/render.rs +++ b/rslib/src/notetype/render.rs @@ -161,14 +161,8 @@ impl Collection { } } -fn flag_name(n: u8) -> &'static str { - match n { - 1 => "flag1", - 2 => "flag2", - 3 => "flag3", - 4 => "flag4", - _ => "", - } +fn flag_name(n: u8) -> String { + format!("flag{n}") } fn fill_empty_fields(note: &mut Note, qfmt: &str, nt: &Notetype, tr: &I18n) { From 9f0322d17e73fbfb9dc63d676813b71ee714e354 Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Mon, 8 Aug 2022 23:58:02 +0200 Subject: [PATCH 5/5] Reduce field height by a few pixels --- ts/editor/LabelContainer.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/editor/LabelContainer.svelte b/ts/editor/LabelContainer.svelte index cbd7edeae..048cd8bfa 100644 --- a/ts/editor/LabelContainer.svelte +++ b/ts/editor/LabelContainer.svelte @@ -56,7 +56,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html background-color: var(--label-color, transparent); - padding: 2px 0; + padding-bottom: 1px; } .clickable { cursor: pointer;