Commit Graph

9248 Commits

Author SHA1 Message Date
RumovZ
a4d61fe7d9
Original position (#1677)
* Replace Card.data with .original_position

* Use and update original position in v3

* Show original position in card info

* Revert restoring original position for now

* Fix pb card to/from pylib card

* Try original_position as the last pb field

* minor wording tweaks (dae)
2022-02-22 22:48:21 +10:00
Henrik Giesel
8b84368e3a
Move all buttons to our custom inline surrounding (#1682)
* Clarify some comments

* Don't destructure insertion trigger

* Make superscript and subscript use domlib/surround

* Create new {Text,Highlight}ColorButton

* Use domlib/surround for textcolor

- However there's still a crucial bug, when you're breaking existing
  colored span when unsurrounding, their color is not restored

* Add underline format to removeFormats

* Simplify type of ElementMatcher and ElementClearer for end users

* Add some comments for normalize-insertion-ranges

* Split normalize-insertion-ranges into remove-adjacent and remove-within

* Factor out find-remove from unsurround.ts

* Rename merge-mach, simplify remove-within

* Clarify some comments

* Refactor first reduce

* Refactor reduceRight

* Flatten functions in merge-ranges

* Move some functionality to merge-ranges and do not export

* Refactor merge-ranges

* Remove createInitialMergeMatch

* Finish refactoring of merge-ranges

* Refactor merge-ranges to minimal-ranges and add some unit testing

* Move more logic into text-node

* Remove most most of the logic from remove-adjacent

- remove-adjacent is still part of the "merging" logic, as it increases
  the scope of the child node ranges

* Add some tests for edge cases

* Merge remove-adjacent logic into minimal-ranges

* Refactor unnecessary list destructuring

* Add some TODOs

* Put removing nodes and adding new nodes into sequence

* Refactor MatchResult to MatchType and return clear from matcher

* Inline surround/helpers

* Shorten name of param

* Add another edge case test

* Add an example where commonAncestorContainer != normalization level

* Fix bug in find-adjacent when find more than one nested nodes

* Allow comments for Along type

* Simplify find-adjacent by removing intermediate and/or curried functions

* Remove extend-adjacent

* Add more tests when find-adjacent finds by descension

* Fix find-adjacent descending into block-level elements

* Add clarifying comment to refusing to descend into block-level elements

* Move shifting logic into find-adjacent

* Rename file matcher to match-type

* Give a first implemention of TreeVertex

* Remove MatchType.ALONG

- findAdjacent now directly modifies the range

* Rename MatchType.MATCH into MatchType.REMOVE

* Implement a version of find-within that utilizies match-tree

* Turn child node range into a class

* Fix bug in new find-adjacent function

* Make all find-adjacent tests test for ranges

* Surrounding within farthestMatchingAncestor when available

* Fix an issue with negligable elements

- also rename "along" elements to "negligable"

* Add two TODOs to SurroundFormat interface

* Have a messy first implementation of the new tree-node algorithm

* Maintain whether formatting nodes are covered or within user selection

* Move covered and insideRange into TreeNode superclass

* Reimplement findAdjacent logic

* Add extension logic

* Add an evaluate method to nodes

* Introduce BlockNode

* Add a first evaluate implementation

* Add left shift and inner shift logic

* Implement SurroundFormatUser

* Allow pass in formatter, ascender and merger from outside

* Fix insideRange and covered switch-up

* Fix MatchNode.prototype.isAscendable

* Fix another switch-up of covered and insideRange...

* Remove a lot of old code

* Have surround functions only return the range

- I still cannot think of a good reason why we should return addedNodes
  and removedNodes, except for testing.

* Create formatting-tree directory

* Create build-tree directory + Move find-above up to /domlib

* Remove range-anchors

* Move unsurround logic into no-splitting

* Fix extend-merge

* Fix inner shift being eroneusly returned as left shift

* Fix oversight in SplitRange

* Redefine how ranges are recreated

* Rename covered to insideMatch and put as fourth parameter instead of third

* Keep track of match holes and match leaves

* Rename ChildNodeRange to FlatRange

* Change signature of matcher

* Fix bug in extend-merge

* Improve Match class

* Utilize cache in TextColorButton

* Implement getBaseSurrounder for TextColorButton

* Add matchAncestors field to FormattingNode

* Introduce matchAncestors and getCache

* Do clearing during parsing already

- This way, you know whether elements will be removed before getting to
  Formatting nodes

* Make HighlightColorButton use our surround mechanism

* Fix a bug with calling .removeAttribute and .hasAttribute

* Add side button to RemoveFormat button

* Add disabled to remove format side button

* Expose remove formats on RemoveFormat button

* Reinvent editor/surround as Surrounder class

* Fix split-text when working with insert trigger

* Try counteracting the contenteditable's auto surrounding

* Remove matching elements before normalizing

* Rewrite match-type

* Move setting match leaves into build

* Change editing strings

- So that color strings match bold/italic strings better

* Fix border radius of List options menu

* Implement extensions functionality

* Remove some unnecessary code

* Fix split range endOffset

* Type MatchType

* Reformat MatchType + add docs

* Fix domlib/surround/apply

* Satisfy last tests

* Register Surrounder as package

* Clarify some comments

* Correctly implement reformat

* Reformat with inactive eraser formats

* Clear empty spans with RemoveFormatButton

* Fix Super/Subscript button

* Use ftl string for hardcoded tooltip

* Adjust wording
2022-02-22 22:17:22 +10:00
Hikaru Y
eafe426622
Fix new deck not being selected (#1681)
* Improve type annotations in studydeck.py

* Use `super()`

* Explicitly delete widget after closing dialog if parent is None

* Consolidate common cleanup tasks into a function

..., and connect it to `finished` signal

* Fix new deck not being selected

* Remove redundant assignments
2022-02-22 21:51:23 +10:00
RumovZ
131a94dd85
Config for burying interday learning cards (#1680)
* Add config for burying interday learning cards

* Expose bury interday learning config in GUI
2022-02-22 21:37:59 +10:00
RumovZ
337f96fce8
Fix/improve flicker when opening browser (#1679) 2022-02-22 20:33:50 +10:00
RumovZ
ad44dc304d
Fix bury count (#1678) 2022-02-22 20:33:11 +10:00
RumovZ
52865cf284
Cleanup (#1676)
* Pass parents to timer() in mediasync.py

* Fix typo

* Fix deleted widget in `closeTooltip()`

* Pass parent in recursive `progress.timer()`
2022-02-22 20:09:43 +10:00
RumovZ
5e1432ff6b
Mention some PowerShell specific issues (#1675)
* Mention Git for Windows as alternative

* Mention powershell path issue
2022-02-18 19:34:44 +10:00
RumovZ
7741475ae0
Fix various leaks (#1672)
* Fix wrong hook being torn down

* Fix item models not being destroyed

* Add missing gc for FilteredDeckConfigDialog

* Add missing type annotation

* Pass calling widget as parent to QTimer

Implicitly passing `self.mw` as the parent means that the QTimer won't
get destroyed before quitting the app, which also thwarts garbage
collection of any data captured by a passed closure.

* Make `Editor._links` an instance variable

Browser is inserting a closure into this dict capturing itself. As a class
variable, it won't get destroyed, so neither will the browser.

* Make `Editor._links` funcs take instance again

* Deprecate calling progress.timer() without parent

* show caller location when printing deprecation warning (dae)
2022-02-18 19:00:12 +10:00
roxgib
14af96d580
Remove .exec() from QMenus in Deck Browser, Reviewer, and Card Template screens (#1674)
* Call StudyDeck with callback

* StudyDeck w/ callback, remove redundant assignment

* Replace exec() with show() for various dialogs

* Update super init args for Models.__init__

* Make StudyDialog ApplicationModal

* Remove .exec() from various dialogs and menus
2022-02-18 17:18:29 +10:00
Damien Elmes
79df188e2a update bundled Python for Linux builds
removes dependency on libcrypt:
https://forums.ankiweb.net/t/issue-building-2-1-50beta3/17630/8
2022-02-18 15:52:41 +10:00
Damien Elmes
cf247a9053 add some more suggested VS Code extensions 2022-02-18 11:33:54 +10:00
RumovZ
700fc50f7a
View menu (#1668)
* Add main view menu

* Add browser view menu

* Use standard keys for zooming and full screen

* Capitalise menu item names

* Toggle Showing Cards/Notes -> Toggle Cards/Notes

* Explicitly set linux full screen key

on_toggle_fullscreen -> on_toggle_full_screen
2022-02-17 16:31:46 +10:00
Abdo
fd6a78e7cf
Add option to ignore accents in search by default (#1667)
* Add option to ignore accents in unqualified search

* Support ignoring accents in word boundary search

* Update ftl/core/preferences.ftl
2022-02-17 16:30:52 +10:00
Damien Elmes
d1d71ffdbb add back support for custom mount point in congrats screen
This was inadvertently dropped in 478b3a53f1,
but AnkiWeb requires it.

In the future we will need to give these index pages a bit more thought,
as it's not very helpful to be exporting a creation function if we're
automatically mounting as the module is imported. Dropping the automatic
mounting would give us more flexibility, but currently that leads to
a FOUC in night mode, as the webview is revealed prior to a subsequent
web.eval() call being able to fire.
2022-02-17 16:28:48 +10:00
Damien Elmes
9bac5b4cb6 disable automatic mypy invocation in VS Code
The default settings don't understand our folder layout (leading to
errors), and place cache files in the root folder. While there is a
setting to provide extra arguments to mypy which we could use to address
the former, paths like ~/.cache do not appear to be supported. Easier
to just rely on pyright for in-IDE linting, and invoke mypy either
via bazel, or via tools/mypy-watch

+ remove unused dist/ exclude
2022-02-17 13:25:22 +10:00
gnnoh
d29a0beb40
Fix ValueError when exported files have wrong mtime (#1666)
* Fix ValueError when exported files have wrong mtime

Set the `strict_timestamps` argument to `False`, so the media files which have a wrong mtime can be normally added to the zipfile.

* Update CONTRIBUTORS (ankitects#1666)

* Reformat exporting.py
2022-02-16 11:17:20 +10:00
Damien Elmes
94846dc4e3 add label to learning column in deck browser
'Learn' rather than 'Learning' to reduce the width of the column.

Closes #1634
2022-02-16 10:23:57 +10:00
Damien Elmes
91e8f73b69 Fully revert "update to (Py)Qt 6.2.3"
This reverts commit 2c4db58013.

Reverting just the WebEngine component introduced a new bug:
f61c64dd34 (commitcomment-66745823)
2022-02-16 10:13:09 +10:00
Damien Elmes
bf1d81aacc fix cyclic import when importing anki.collection directly
Could be triggered with:
PYTHONPATH=.bazel/bin/qt/runanki.runfiles/ankidesktop/pylib python -c 'import anki.collection'
2022-02-15 19:08:29 +10:00
Damien Elmes
4b941d9461 older Safari does not support Blob.arrayBuffer() 2022-02-15 15:02:45 +10:00
Damien Elmes
b652e3b895 add class to 'show timer' switch 2022-02-14 20:04:19 +10:00
RumovZ
098881741b
Show buried until daily limits in overview screen (#1664)
* Show buried until daily limits in overview screen

This explains differences between the counts shown in the deck tree and
those shown in the overview screen.

Closes #1633.

* interday learning cards can be buried too (dae)

* add 'buried' tooltip to bury counts; generate row in helper fn (dae)

* Use grey for buried counts
2022-02-14 18:57:01 +10:00
Damien Elmes
d4f27d1d56 update translations 2022-02-14 18:54:19 +10:00
Damien Elmes
c41e455554 fix reviewer_extras 2022-02-14 18:46:50 +10:00
Damien Elmes
ac4a1cd8e0 strip fully qualified bazel tools path
tentative fix for https://forums.ankiweb.net/t/anki-2-1-50-beta-3/17501/17
2022-02-14 18:46:50 +10:00
Damien Elmes
1871b57663 don't put flag changes in the undo queue, and don't bump mtime
This is not ideal, but I struggled to come up with a better solution.

Background:

- The scheduler records the mtime of cards as it's building the queues,
and will throw an error in get_queued_cards() if the card on the DB
has a different mtime. This is to catch bugs - any operation that modifies
cards should be triggering a queue rebuild, or should adjust the queues
appropriately.
- The review screen skips the usual queue rebuild redraw, and directly
updates the flag icon. This is because a rebuild could cause a different
card to appear, or the answer side to switch back to the question side,
neither of which the user expects when they flag a card.

The current behaviour was broken: the queue rebuilding was still happening
on the backend, and the frontend was just failing to reflect it.

I initially tried to special-case Op::SetFlag, having it skip the queue
rebuild, and having set_card_flag() update the mtimes in the active
queue. But those mutations weren't captured by the undo log, so they
didn't get undone when undoing the set flag operation. We could perhaps
work around it by adding a separate undo entry to capture the mutation,
but it started to feel like it would be a pain to maintain moving forward.

By skipping the undo queue and retaining the same mtime, no queue
rebuild is required. Because we're setting usn, the cards will still
sync, but as mtime is not bumped, in the case of a conflict, an older
unsynced change from another client may revert the flag change.

Fixes https://forums.ankiweb.net/t/anki-2-1-50-beta-1-2/15608/145
2022-02-13 16:27:33 +10:00
Damien Elmes
1253dc3a3b drop the bug: lines in v2.py
IIRC, it was triggered when the user doesn't have a valid current
deck selected. currentRevLimit() sets default=False, but it is ignored
and the default deck is returned instead.
2022-02-13 14:11:15 +10:00
RumovZ
8ca2fa6476
Handle multiple languages in TTS code on Windows (#1663)
Closes  #1615.
2022-02-13 13:51:59 +10:00
RumovZ
9c54f85be6
Import submodules directly (#1662)
* Use submodule imports in aqt

* Use submodule imports in pylib

* More submodule imports in pylib

These required removing some direct imports to get rid of import cycles.
2022-02-13 13:40:47 +10:00
RumovZ
6a21261c84
Round calculated Hard days (#1661)
* Round calculated Hard days

* clarify docstring (dae)
2022-02-13 13:37:52 +10:00
Abdo
af93d8a124
Fix setup-env.bat (#1659)
* Do not assume bazel is in the C drive

* Quote PATH

* make path separator consistent (dae)
2022-02-12 10:10:24 +10:00
Damien Elmes
f61c64dd34 roll back qtwebengine to 6.2.2 to fix broken copy&paste on Windows
https://forums.ankiweb.net/t/anki-2-1-50-beta-3/17501/2
https://forums.ankiweb.net/t/is-this-a-bug-anki-2-1-50-beta3/17528
2022-02-11 23:27:16 +10:00
Damien Elmes
b6d7ef506e tweak insertion order tip 2022-02-11 23:27:15 +10:00
Damien Elmes
6ab221bda5 fix broken Windows tests 2022-02-11 19:46:38 +10:00
Damien Elmes
a8939e7938 serialize black invocations
On a Linux machine here, the tests consistently fail when two copies
of black are run at once:

% bazel test //qt:format_check //pylib:format_check --cache_test_results=no
==================== Test output for //qt:format_check:
Process SyncManager-1:
Traceback (most recent call last):
  File "/home/dae/.cache/bazel/_bazel_dae/fc22e40cbbf8b7d16ac57a00991b1ef1/external/python/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/dae/.cache/bazel/_bazel_dae/fc22e40cbbf8b7d16ac57a00991b1ef1/external/python/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/dae/.cache/bazel/_bazel_dae/fc22e40cbbf8b7d16ac57a00991b1ef1/external/python/lib/python3.9/multiprocessing/managers.py", line 583, in _run_server
    server = cls._Server(registry, address, authkey, serializer)
  File "/home/dae/.cache/bazel/_bazel_dae/fc22e40cbbf8b7d16ac57a00991b1ef1/external/python/lib/python3.9/multiprocessing/managers.py", line 156, in __init__
    self.listener = Listener(address=address, backlog=16)
  File "/home/dae/.cache/bazel/_bazel_dae/fc22e40cbbf8b7d16ac57a00991b1ef1/external/python/lib/python3.9/multiprocessing/connection.py", line 453, in __init__
    self._listener = SocketListener(address, family, backlog)
  File "/home/dae/.cache/bazel/_bazel_dae/fc22e40cbbf8b7d16ac57a00991b1ef1/external/python/lib/python3.9/multiprocessing/connection.py", line 596, in __init__
    self._socket.bind(address)
OSError: [Errno 98] Address already in use

I dug briefly into Black's code, but suspect this is actually an issue
with the multiprocessing library. Didn't have time to investigate it
further; this workaround will do for now.

(One day I'll get around to merging those separate scripts into a single
one. One day. :-))
2022-02-11 14:47:05 +10:00
Damien Elmes
02112e68bd fix "Identifier 'style' has already been declared"
https://github.com/ankitects/anki/issues/1516
2022-02-11 14:34:00 +10:00
Damien Elmes
6a28e458ff add import to addons.py for vscode
For #1631
2022-02-11 13:07:42 +10:00
Damien Elmes
62426279ff fix error when opening old deck options in python 3.10
Closes #1616
2022-02-11 10:59:04 +10:00
RumovZ
6c8cdc0a0c
Keep cwd and pass dir to player subprocess instead (#1656) 2022-02-11 10:35:48 +10:00
RumovZ
cc91017bf1
Remove unused actions from ui files (#1655)
* Remove redundant actions in add dialog

* Remove unused actions from main and browser
2022-02-11 10:15:36 +10:00
Damien Elmes
95dbf30fb9 updates to the build process and binary bundles
All platforms:

- rename scripts/ to tools/: Bazelisk expects to find its wrapper script
(used by the Mac changes below) in tools/. Rather than have a separate
scripts/ and tools/, it's simpler to just move everything into tools/.
- wheel outputs and binary bundles now go into .bazel/out/dist. While
not technically Bazel build products, doing it this way ensures they get
cleaned up when 'bazel clean' is run, and it keeps them out of the source
folder.
- update to the latest Bazel

Windows changes:

- bazel.bat has been removed, and tools\setup-env.bat has been added.
Other scripts like .\run.bat will automatically call it to set up the
environment.
- because Bazel is now on the path, you can 'bazel test ...' from any
folder, instead of having to do \anki\bazel.
- the bat files can handle being called from any working directory,
so things like running "\anki\tools\python" from c:\ will work.
- build installer as part of bundling process

Mac changes:

- `arch -arch x86_64 bazel ...` will now automatically use a different
build root, so that it is cheap to switch back and forth between archs
on a new Mac.
- tools/run-qt* will now automatically use Rosetta
- disable jemalloc in Mac x86 build for now, as it won't build under
Rosetta (perhaps due to its build scripts using $host_cpu instead of
$target_cpu)
- create app bundle as part of bundling process

Linux changes:

- remove arm64 orjson workaround in Linux bundle, as without a
readily-available, relatively distro-agonstic PyQt/Qt build
we can use, the arm64 Linux bundle is of very limited usefulness.
- update Docker files for release build
- include fcitx5 in both the qt5 and qt6 bundles
- create tarballs as part of the bundling process
2022-02-10 19:23:07 +10:00
RumovZ
d55f080733
V3 parent limits (#1638)
* avoid repinning Rust deps by default

* add id_tree dependency

* Respect intermediate child limits in v3

* Test new behaviour of v3 counts

* Rework v3 queue building to respect parent limits

* Add missing did field to SQL query

* Fix `LimitTreeMap::is_exhausted()`

* Rework tree building logic

https://github.com/ankitects/anki/pull/1638#discussion_r798328734

* Add timer for build_queues()

* `is_exhausted()` -> `limit_reached()`

* Move context and limits into `QueueBuilder`

This allows for moving more logic into QueueBuilder, so less passing
around of arguments. Unfortunately, some tests will require additional
work to set up.

* Fix stop condition in new_cards_by_position

* Fix order gather order of new cards by deck

* Add scheduler/queue/builder/burying.rs

* Fix bad tree due to unsorted child decks

* Fix comment

* Fix `cap_new_to_review_rec()`

* Add test for new card gathering

* Always sort `child_decks()`

* Fix deck removal in `cap_new_to_review_rec()`

* Fix sibling ordering in new card gathering

* Remove limits for deck total count with children

* Add random gather order

* Remove bad sibling order handling

All routines ensure ascending order now.
Also do some other minor refactoring.

* Remove queue truncating

All routines stop now as soon as the root limit is reached.

* Move deck fetching into `QueueBuilder::new()`

* Rework new card gather and sort options

https://github.com/ankitects/anki/pull/1638#issuecomment-1032173013

* Disable new sort order choices ...

depending on set gather order.

* Use enum instead of numbers

* Ensure valid sort order setting

* Update new gather and sort order tooltips

* Warn about random insertion order with v3

* Revert "Add timer for build_queues()"

This reverts commit c9f5fc6ebe87953c17a0c842990b009b5596c69c.

* Update rslib/src/storage/card/mod.rs (dae)

* minor wording tweaks to the tooltips (dae)

+ move legacy strings to bottom
+ consistent capitalization (our leech action still needs fixing,
but that will require introducing a new 'suspend card' string as the
existing one is used elsewhere as well)
2022-02-10 09:55:43 +10:00
roxgib
4b9b923775
Make dialogs non-blocking (#1650)
* Call StudyDeck with callback

* StudyDeck w/ callback, remove redundant assignment

* Replace exec() with show() for various dialogs

* Update super init args for Models.__init__

* Make StudyDialog ApplicationModal
2022-02-10 09:53:13 +10:00
Damien Elmes
4653873db9 add file layout visualization from aracelix
https://github.com/ankitects/anki/issues/1010#issuecomment-1032248683
2022-02-09 13:24:07 +10:00
Damien Elmes
b64c179609 change notes/cards toggle shortcut to ctrl+alt+t
Closes #1652
2022-02-09 12:59:45 +10:00
RumovZ
4909302147
Intersperse more evenly, mainly at start and end (#1651)
Closes #1645.
2022-02-09 12:45:37 +10:00
Henrik Giesel
30427fb540
Fix editor dropdowns (#1649) 2022-02-08 14:13:55 +10:00
Henrik Giesel
c0d47e18b7
Fix CommandIconButton (#1648)
- It did not respect shortcuts
2022-02-08 14:13:18 +10:00
Henrik Giesel
16e9e56ad8
Make sure initial comments are preserved in HTML editor (#1647) 2022-02-08 14:07:09 +10:00