From 0f5627bb7a67770f51ad49ee378c0be8b72c9dbf Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 2 Jun 2021 11:01:30 +1000 Subject: [PATCH] limit custom study to 100 tags The hard limit from sqlite may be larger, but things slow down as more tags are selected. https://forums.ankiweb.net/t/unable-to-create-custom-test/10467 There are a number of things that could be improved here: - we should show a live count so users are aware of the limit - we should be filling in the parent tags when they're not explicitly listed on a card - we should reconsider disabling the 'tags to include' by default It may make sense to defer these changes until we can move this screen into Svelte/handle the processing in the backend. --- ftl/core/errors.ftl | 4 ++++ pylib/anki/lang.py | 4 ++++ qt/aqt/taglimit.py | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ftl/core/errors.ftl b/ftl/core/errors.ftl index a00923d4c..c2cfe9e82 100644 --- a/ftl/core/errors.ftl +++ b/ftl/core/errors.ftl @@ -3,3 +3,7 @@ errors-invalid-input-details = Invalid input: { $details } errors-parse-number-fail = A number was invalid or out of range. errors-filtered-parent-deck = Filtered decks can not have child decks. errors-filtered-deck-required = This action can only be used on a filtered deck. +errors-100-tags-max = + A maximum of 100 tags can be selected. Listing the + tags you want instead of the ones you don't want is usually simpler, and there + is no need to select child tags if you have selected a parent tag. diff --git a/pylib/anki/lang.py b/pylib/anki/lang.py index 32fdbcdc1..fb7539f30 100644 --- a/pylib/anki/lang.py +++ b/pylib/anki/lang.py @@ -211,3 +211,7 @@ def is_rtl(lang: str) -> bool: # for testing purposes def without_unicode_isolation(s: str) -> str: return s.replace("\u2068", "").replace("\u2069", "") + + +def with_collapsed_whitespace(s: str) -> str: + return re.sub(r"\s+", " ", s) diff --git a/qt/aqt/taglimit.py b/qt/aqt/taglimit.py index 64459a7f1..d0d4706a8 100644 --- a/qt/aqt/taglimit.py +++ b/qt/aqt/taglimit.py @@ -3,10 +3,11 @@ from typing import List, Optional import aqt +from anki.lang import with_collapsed_whitespace from aqt.customstudy import CustomStudy from aqt.main import AnkiQt from aqt.qt import * -from aqt.utils import disable_help_button, restoreGeom, saveGeom +from aqt.utils import disable_help_button, restoreGeom, saveGeom, showWarning, tr class TagLimit(QDialog): @@ -73,7 +74,6 @@ class TagLimit(QDialog): QDialog.reject(self) def accept(self) -> None: - self.hide() # gather yes/no tags yes = [] no = [] @@ -89,6 +89,10 @@ class TagLimit(QDialog): idx = self.dialog.inactiveList.indexFromItem(item) if self.dialog.inactiveList.selectionModel().isSelected(idx): no.append(self.tags_list[c]) + if (len(yes) + len(no)) > 100: + showWarning(with_collapsed_whitespace(tr.errors_100_tags_max())) + return + self.hide() # save in the deck for future invocations self.deck["activeTags"] = yes self.deck["inactiveTags"] = no