Commit graph

1302 commits

Author SHA1 Message Date
Damien Elmes
96ff27d1fb
Ensure media files are passed relative to the media folder (#4041)
We were (partially) doing this for MpvManager, but not for
Windows' SimpleMpvPlayer. By passing a media file starting
with a special scheme, a malicious actor could have caused a file to
be written to the filesystem on Windows.

Thanks once again to Michael Lappas for the report.
2025-06-01 13:16:04 +07:00
Jarrett Ye
1124a63798
expose decay of Card object in Python (#3985) 2025-05-06 23:32:58 +03:00
Arthur Milchior
efaaae8ce4
Cloze button get disabled outside of cloze field (#3879)
* NF: replace `disabled` by `enabled`

This allows to remove the negations and, in my opinion, make the code
easier to understand and edit.

* Cloze button get disabled outside of cloze field

More specifically, if the user focus in a field that is not a cloze
field, the button are still there but appear as disabled. The shortcut
instead of adding the cloze context shows an alert explaining why this
can't be done.

While this message is already displayed when the user tries to add a
note with cloze in non-cloze field, I suspect it will save time to
stop the user as soon as possible from making mistake. This should
make very clear what is authorized and what is not.

It'll also be a reminder of whether the current field is a cloze or
not.

In order to do this, I added a back-end method (that I expect we may
reuse in ankidroid) to get the index of the fields used in cloze. This
set is sent to the note editor, which propagates it where needed.

In mathjax, the cloze symbol is removed when the selected field is not
a cloze field.
2025-04-24 18:37:41 +10:00
user1823
e546c6d11f
Improve natural unit conversion for a time b/w 360 to 365 days (#3901)
* Improve natural unit conversion for a time b/w 360 to 365 days

Previously, 363 days would be converted to 12.1 months, which is quite confusing because
- a user would think that if the value is more than 12 months, why it isn't displayed in years
- the value is actually less than a year, which is counterintuitive as 12.1 m suggests a value more than a year.

* precise

* Update time.ts to match timespan.rs

* Add another test

* Use average duration of a month instead

* Update time.ts

* Update test_schedv3.py

* Update time.test.ts
2025-04-13 14:26:34 +10:00
llama
ccab18b7ba
Modify card rendering output to specify if rendered card is empty (#3890)
* modify render_card to return whether card was empty

* plumbing

* add flag to proto message

* plumbing: pass flag along to PartiallyRenderedCard

* add tests

* Use a custom return type for clarity (dae)
2025-03-31 17:51:28 +07:00
Yuki
acdf486b29
Refactor: Make Load Balancer Optional Throughout Codebase (#3860)
* Refactoring: load balancer

* Update about.py

* Refactoring: load balancer

* Update about.py

* Clean the code

* Remove config check from get_scheduling_states

* Backend method for the load balancer

* Refactor backend method for the load balancer
2025-03-26 23:19:28 +10:00
Abdo
f4a0598f2f
Return a copy of note type in ModelManager.get() (#3865)
* Return a copy of note type in ModelManager.get()

* Update tests

* Revert "Return a copy of note type in ModelManager.get()"

This reverts commit 04ef186336.

* Add note to .get()
2025-03-26 15:11:34 +10:00
Kris Cherven
938c55ca01
Fix broken window decorations on unpackaged GNOME instances (#3858)
* Fix broken window decorations on unpackaged GNOME instances

* Fix CONTRIBUTORS detection

* Fix CONTRIBUTORS
2025-03-19 17:58:42 +07:00
Arthur Milchior
6ef24739fc
NF: sligthly optimize cards.py (#3870)
As AnkiDroid wants to be similar to Anki, instead of making AnkiDroid
slightly less efficient, I prefer to slightly improve Anki.

AnkiDroid related PR:
https://github.com/ankidroid/Anki-Android/pull/18112.
2025-03-19 04:14:13 +03:00
Damien Elmes
92b1144d97 Bump Rust to 1.84
+ fix new warnings/lints
+ update pyo3 to fix some other warnings
2025-01-26 18:51:21 +11:00
GithubAnon0000
e32292585b
FIX lang selection resetting to en_US for some langs (#3744)
* FIX lang selection resetting to en_US for some langs

Fixes https://forums.ankiweb.net/t/anki-25-01-beta/54490/17?u=anon_0000.

# Issue
Set a hand full of certain languages in the preferences screen and see that the translations have been applied after reboot. The language selection in preferences wrongly shows en_US though, not the current active language. If you wanted to switch to `en_US` in this case, then you'd have to first switch to a working language (like de_DE) and then switch to en_US.

# Solution
`anki/qt/aqt/preferences.py` has the functions `setup_language()` and `current_lang_index()`. I noticed that it defaults to en_US, if the language is not in `compatMap` and it couldn’t return the index of the current language. No idea if this code is faulty but I headed over to `anki/pylib/anki/lang.py` afterwards.

Here, in `compatMap`, I added e.g. `"la": "la_LA"`. I knew the code since I could get it with `print("––– lang is ", lang)` in `preferences.py` (`current_lang_index()` retrieves `la` for latin).

After adding those code changes from my PR, the problem for those selected languages had gone away.

No idea if that's best practices though or if something else should be fixed instead.

* UPDATE CONTRIBUTORS adding myself to the list
2025-01-25 19:14:50 +11:00
llama
873c4e617d
Recognise and check for media referenced in <source> tags (#3763)
* recognise and check <source> tags for media

* add test
2025-01-25 10:16:24 +03:00
Ben Nguyen
9d09c32ece
Enable strict_optional for aqt/tagedit, utils, sync (#3578)
* Enable strict_optional for tagedit

* Fix mypy errors

* Enable strict_optional for utils

* Fix mypy errors

* Enable strict_optional for sync

* Fix mypy errors

---------

Co-authored-by: Abdo <abdo@abdnh.net>
2024-11-15 16:29:19 +03:00
Damien Elmes
b4ae7ce907 Remove unused link 2024-11-07 08:37:32 +10:00
Damien Elmes
6adbd922f7 Rename remaining 'weights' references to 'params' 2024-10-21 18:13:23 +10:00
Jarrett Ye
6ff309e08f
Feat/option to enable FSRS short-term scheduler when (re)learning steps run out && speed up features based on simulation (#3505)
* Update to FSRS-rs v1.3.2

* add fsrs_short_term_with_steps_enabled to config

* ./ninja fix:minilints

* fix defaults_for_testing

* if current parameters are invalid, skip comparison

fix #3498

* fix redundant_field_names

* cargo clippy --fix

* Update to FSRS-rs v1.3.3

* Update to FSRS-rs v1.3.4

* Avoid an extra config lookup on each card answer (dae)
2024-10-21 15:09:07 +10:00
Jarrett Ye
b09326cddd
Feat/export dataset for research (#3511)
* Feat/export dataset for research

* add comment

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* target_path is required

* format

* improve efficiency to look up parent_id

* move `use` down
2024-10-18 18:57:06 +10:00
Jarrett Ye
f00211df35
add get_revlogs API && fix the style of tooltipText of ReviewsGraph (#3490)
* add get_revlogs API

* fix tooltipText of ReviewsGraph

the style of true-retention shouldn't affect the style of tooltipText of ReviewsGraph

* More verbose wording (dae)
2024-10-12 14:49:14 +10:00
Ben Nguyen
931e1d80f2
Enable strict_optional in aqt/. and aqt/browser (#3486)
* Boolean naming convention

* Rename no_strict_optional -> strict_optional

* Update CONTRIBUTORS

* Enable strict optional for aqt module

* Fix errors

* Enable strict optional for aqt browser

* Fix layout.py errors

* Fix find_duplicates.py errors

* Fix browser.py errors

* Revert a0 a1 names

* Fix tree.py errors

* Fix previewer.py errors

* Fix model.py errors

* Fix find_and_replace.py errors

* Fix item.py errors

* Fix toolbar.py errors

* Fix table/__init__.py errors

* Fix model.py errors

* Fix state.py errors

* Fix table.py errors

* Fix errors in card_info.py

* Fix searchbar.py errors

* Fix name

* Fix assert in browser.py

* Formatting

* Fix assert vh

* assert is not None instead of truthy

* Split _move_current() up to correct type signature (dae)

We want either index or direction, but not both.
2024-10-11 23:12:48 +10:00
a.r
e2124cd790
typeanswer: [type:nc] – ignores combining characters (#3422)
* typeanswer: fix cleanup

Fix: Add prepare_expected back in for the 'nothing typed' & 'correctly typed' cases. This also makes expected_original redundant again.

Style: %s/provided/typed/g

Style: rename one ch → c

Testcase: whitespace_is_trimmed: added a check for the "correctly typed" path and renamed it to tags_removed (there's no whitespace?)

Testcase: empty_input_shows_as_code: changed to also check that tags get trimmed

* [type:nc] – ignores combining characters

Adds a comparison variant to [type] which ignores when combining characters of the expected field are missing from the provided input. It still shows these characters in the 'expected' line for reference.

It's useful for languages with e.g. diacritics that are required for reference (such as in dictionaries), but rarely actually learned or used in everyday writing. Among these languages: Arabic, Hebrew, Persian, Urdu.

The bool 'combining' controls it as new final parameter of both relevant compare_answer functions. On the Python side, it's set to true by default.

Use on the note templates: [type:nc:field] (only the front needs to include :nc)

This also removes the need to have both variants of words/sentences present as separate fields, to show them redundantly, etc.

* typeanswer: simplify by using nfkd throughout

Requires adjusting two testcases, but both render exactly the same in Anki itself.

On NFC vs. NKFD: https://stackoverflow.com/a/77432079

* typeanswer: 'simplify' by removing normalize_typed (requiring a bool parameter)

I'd prefer to keep this extra method.

* typeanswer: micro-optimize vectors

Should get rid of most relocations, at the expense of over-allocating.

On Vec's (String's) behavior: https://stackoverflow.com/a/72787776

* Mark `combining` as private

typeCorrect is not marked as private either, but we can at least do
the right thing for newly-added code.

* Revert "typeanswer: micro-optimize vectors"

This reverts commit 9fbacbfd19.

* Revert "typeanswer: 'simplify' by removing normalize_typed (requiring a bool parameter)"

This reverts commit df2dd3394e.
2024-09-30 23:11:51 +10:00
Ben Nguyen
77fb0fb708
Possible to show “last” subdeck name in Browser? (#3387)
* elide middle of deck names

* Update CONTRIBUTORS

* made elide mode enum

* add elide mode field

* fix enum number

* remove dataclass decorator

* Update CONTRIBUTORS

* format rust code

* Update CONTRIBUTORS

* formatting

* Update CONTRIBUTORS

* fix type hint

* Update CONTRIBUTORS
2024-09-20 20:33:28 +10:00
Damien Elmes
b241ab9492
Dependency updates (#3403)
* Bump Python deps

Primarily for flask-cors CVE

* Bump TS deps; pin license checker

Current checker is missing the binary
https://github.com/RSeidelsohn/license-checker-rseidelsohn/issues/118

* Update Rust deps

Hyper and axum are held back as we currently make use of the older
http library that reqwest pulls in
2024-09-04 12:21:50 +07:00
Arthur Milchior
ce2f4136ea
Empty cards become undoable (#3386)
* Empty cards is undoable

If there was a reason for this operation not to be undoable, I can't easily guess it. My main hyposhesis was that the number of deleted card may be too big. But I realized that deleting a deck is undoable and may delete as many note.

As you may know, I realized that only the undoable operations triggered notification in AnkiDroid that we may have to update the UI. And while I just wanted to trigger more notifications, some reviewers thought it would be nicer if the operation were returning a OpChanges. So here it's done. If you would please consider merging it.

I decided to introduce a new string because the closest strings I could find currently are "Empty cards..." and the trailing commas don't seem nice in "undo". And the title, which we may not be able to reuse in all language

* Don't count cards that have already been removed (dae)
2024-08-29 20:06:41 +07:00
David Culley
a6d5c94997
python: add missing type annotations for None values (#3364)
* refactor: explicitly add NoneType to type hints

If variable can be `None`, don't be implicit. Be explicit.
2024-08-22 16:03:44 +07:00
Jake Probst
c6cb4e4373
load balancer! (#3230)
* start of load balancer

* add configuration options; option to load balance per deck

* formatting

* clippy

* add myself to contributors

* cleanup

* cargo fmt

* copyright header on load_balancer.rs

* remove extra space

* more formatting

* python formatting

* ignore this being None

only doing this cause python has awful lambdas and can't
loop in a meaningful way without doing this

* only calculate notes on each day if we are trying to avoid siblings

* don't fuzz intervals if the load balancer is enabled

* force generator to eval so this actually happens

* load balance instead of fuzzing, rather than in addition to

* use builtin fuzz_bounds rather than reinvent something new

* print some debug info on how its load balancing

* clippy

* more accurately load balance only when we want to fuzz

* incorrectly doublechecking the presence of the load balancer

* more printfs for debugging

* avoid siblings -> disperse siblings

* load balance learning graduating intervals

* load balancer: respect min/max intervals; graduating easy should be at least +1 good

* filter out after-days under minimum interval

* this is an inclusive check

* switch load balancer to caching instead of on the fly calculation

* handle case where load balancer would balance outside of its bounds

* disable lb when unselecting it in preferences

* call load_balancer in StateContext::with_review_fuzz instead of next to

* rebuild load balancer when card queue is rebuilt

* remove now-unused configuration options

* add note option to notetype to enable/disable sibling dispersion

* add options to exclude decks from load balancing

* theres a lint checking that the link actually exists so I guess I'll add the anchor back in later?

* how did I even update this

* move load balancer to cardqueue

* remove per-deck balancing options

* improve determining whether to disperse siblings when load balancing

* don't recalculate notes on days every time

* remove debug code

* remove all configuration; load balancer enabled by default; disperse siblings if bury_reviews is set

* didn't fully remove caring about decks from load balancer sql query

* load balancer should only count cards in the same preset

* fuzz interval if its outside of load balancer's range

* also check minimum when bailing out of load balancer

* cleanup; make tests happy

* experimental weight-based load balance fuzzing

* take into account interval when weighting as it seems to help

* if theres no cards the interval weight is just 1.0

* make load balancer disableable through debug console

* remove debug prints

* typo

* remove debugging print

* explain a bit how load balancer works

* properly balance per preset

* use inclusive range rather than +1

* -1 type cast

* move type hint somewhere less ugly; fix comment typo

* Reuse existing deck list from parent function (dae)

Minor optimisation
2024-08-17 12:50:54 +07:00
Abdo
520564da11
Integrate AnkiHub Sign-in (#3232)
* Add AnkiHub section to preferences screen

* Add short intro for AnkiWeb and AnkiHub to syncing section

* Add AnkiHub login screen

* Implement login methods in backend

* Set minimum dialog width

* Add missing colon

* Respect the ANKIHUB_APP_URL env var

This is used by the add-on.

* Simplify login error reporting

* Fix from_prefs_screen not passed to subcall

* Add missing ankihub_pb2 import

* Install AnkiHub add-on after sign-in

* Avoid .exec()

* Update ftl/core/sync.ftl

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* Split translation string

* Support login by username/email

* Fix entered username/email not being passed back to on_done

* Remove unused import

* Move to 'Third-party services' section

* Tweak login dialog's heading

* Remove 'third-party' from intro text

* Tweak copy

* Prefix profile keys

* Tweak strings

* Remove description from login dialog

* Remove signup links

* Clear credentials in ankihub_logout()

* Call .adjustSize()

* Title Case

* Add padding to third-party services, and fix tab order from other PR
2024-08-17 10:58:23 +07:00
David Culley
4fb6fa81ac
refactor: use not in and is not as recommended (#3351)
- https://docs.astral.sh/ruff/rules/not-is-test/
- https://docs.astral.sh/ruff/rules/not-in-test/
2024-08-10 17:55:26 +07:00
David Culley
bab83ffce0
fix: add proper imports (#3296)
Co-authored-by: Damien Elmes <dae@users.noreply.github.com>
2024-08-05 11:34:46 +07:00
David Culley
c0349ea9da
Improve exception handling (#3290)
* fix: except only non-system-exiting exceptions

see https://youtu.be/zrVfY9SuO64

* chore: add myself to CONTRIBUTORS file

* refactor: explicitly specify possible exceptions

If an exception is not an Exception, there are only three options left.
see https://docs.python.org/3/library/exceptions.html#exception-hierarchy

* refactor: use BaseException for fallback

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* chore: add myself to contributors
2024-08-04 20:51:13 +07:00
David Culley
0743e6e40e
Update type annotations to use | operator (#3323)
* refactor: update to `|` operator

* refactor: add missing type hint

* refactor: enable `|` operator for older versions

* refactor: remove obsolete import
2024-07-26 18:15:39 +07:00
David Culley
3f66f995f7
style: reformat with black (#3324) 2024-07-26 17:58:57 +07:00
David Culley
363a52526e
Update type annotations (#3322)
* refactor: update Callable type hint

* refactor: update type annotations for hooks
2024-07-26 17:57:25 +07:00
David Culley
6c0857395f
Refactor getting the index of a user's language (#3311)
* refactor: rename variables of tuple

* refactor: rename function argument

* refactor: use function to get index of language

* refactor: replace for-loop

* refactor: use variable

* refactor: assert values are not None

To satisfy the type checker.

* refactor: change generator expression to for-loop
2024-07-25 12:46:59 +07:00
Abdo
b05c9d1598
Fix change_notetype_of_notes's docstring (#3304) 2024-07-21 15:26:10 +07:00
David Culley
aa6583cdd1
Refactor ephemeral_card of notes (#3307)
* refactor: fix type annotation

* fix: properly check if argument is None

Don't use Boolean expressions to implement a default value.

* fix: ensure that 'model' is not None

Don't use exceptions to control the flow.

* refactor: simplify if-else construct
2024-07-21 15:25:48 +07:00
David Culley
e213c0a6d1
refactor: use list comprehension (#3308) 2024-07-21 15:21:41 +07:00
David Culley
63afb0f8c6
Update type annotation syntax (#3283)
* chore: add myself to CONTRIBUTORS file

* refactor: use newer type hints for Union/Optional

* refactor: fix deprecated type annotations

use collections.abc rather than typing

* refactor: use lower letter type annotations

* style: reformat with black

* refactor: remove unused imports

* refactor: add missing imports for type hints

* fixup! refactor: use newer type hints for Union/Optional

* fix: add missing imports for type annotations

* fixup! refactor: use newer type hints for Union/Optional

* fixup! style: reformat with black

* refactor: fix remaining imports re: type hints
2024-07-21 14:00:52 +07:00
Damien Elmes
cd885098f7 Bump Python deps
A few tweaks were required for PyLint
2024-07-06 18:40:37 +07:00
Damien Elmes
ec96bfe315 Uyghur is RTL
https://forums.ankiweb.net/t/rlt-ui-bug-uyghur-language-gui-direction/46610
2024-07-02 19:03:29 +07:00
Abdo
55d68c01d8
Shuffle identical values in filtered deck sort (#3259)
* Shuffle identical values in filtered deck sort

* Update test
2024-06-28 18:53:16 +07:00
Damien Elmes
e4326ce801 Add Uyghur to language list 2024-06-24 14:55:16 +07:00
Abdo
06f7aa393d
Add a preference to toggle LaTeX generation (#3218)
* Add a preference to toggle LaTeX generation

* Fix test

* Remove LaTeX security restrictions

* Show existing LaTeX images regardless of preference

* Lift config check out of loop (dae)

* Shift option to review settings; display warning when disabled (dae)
2024-06-01 09:26:28 +01:00
Damien Elmes
17a20067f3 Fix set_due_date docstring
Closes #3207
2024-05-25 16:08:45 +07:00
Damien Elmes
7efae4d95d Mnemosyne importer now handles float values for due date and interval 2024-05-17 12:34:01 +07:00
Abdo
00248665d7
Avoid locale.getdefaultlocale() if possible (#3143)
* Avoid locale.getdefaultlocale() if possible

* Suppress warning

* Add comment

* Apply suggestions from code review
2024-04-19 19:52:02 +10:00
Jarrett Ye
10d567f937
Update to FSRS-rs v0.6.1 (#3106)
* update to FSRS-rs 0.6.0

* update to crates.io version

* format

* update to FSRS-rs v0.6.01

* ./ninja fix:minilints

* update python backend code
2024-04-05 13:04:50 +01:00
Damien Elmes
9f55cf26fc
Switch to SvelteKit (#3077)
* Update to latest Node LTS

* Add sveltekit

* Split tslib into separate @generated and @tslib components

SvelteKit's path aliases don't support multiple locations, so our old
approach of using @tslib to refer to both ts/lib and out/ts/lib will no
longer work. Instead, all generated sources and their includes are
placed in a separate out/ts/generated folder, and imported via @generated
instead. This also allows us to generate .ts files, instead of needing
to output separate .d.ts and .js files.

* Switch package.json to module type

* Avoid usage of baseUrl

Incompatible with SvelteKit

* Move sass into ts; use relative links

SvelteKit's default sass support doesn't allow overriding loadPaths

* jest->vitest, graphs example working with yarn dev

* most pages working in dev mode

* Some fixes after rebasing

* Fix/silence some svelte-check errors

* Get image-occlusion working with Fabric types

* Post-rebase lock changes

* Editor is now checked

* SvelteKit build integrated into ninja

* Use the new SvelteKit entrypoint for pages like congrats/deck options/etc

* Run eslint once for ts/**; fix some tests

* Fix a bunch of issues introduced when rebasing over latest main

* Run eslint fix

* Fix remaining eslint+pylint issues; tests now all pass

* Fix some issues with a clean build

* Latest bufbuild no longer requires @__PURE__ hack

* Add a few missed dependencies

* Add yarn.bat to fix Windows build

* Fix pages failing to show when ANKI_API_PORT not defined

* Fix svelte-check and vitest on Windows

* Set node path in ./yarn

* Move svelte-kit output to ts/.svelte-kit

Sadly, I couldn't figure out a way to store it in out/ if out/ is
a symlink, as it breaks module resolution when SvelteKit is run.

* Allow HMR inside Anki

* Skip SvelteKit build when HMR is defined

* Fix some post-rebase issues

I should have done a normal merge instead.
2024-03-31 09:16:31 +01:00
snowtimeglass
ddccfb805f
Use "importing-added" string in importing detail table (#3104)
Supplement to the task of commit 184ad80 (Clone "added" string for importing)
2024-03-31 07:33:31 +01:00
RumovZ
36287888cc
Reset original id when cloning notetypes (#3089) 2024-03-24 08:18:59 +00:00
Jarrett Ye
055b6e30f8
update FSRS-rs to 0.5.0 & export benchmark API (#3056)
* update fsrs to 0.4.5

* update to fsrs 0.4.6

* add benchmark API

* update fsrs to 0.5.0

* cargo fmt

* ./ninja fix:minilints

* ./ninja format

* Add a brief comment about the new method (dae)
2024-03-08 12:37:06 +00:00