Commit Graph

1497 Commits

Author SHA1 Message Date
Damien Elmes
52676f1555 fix a panic when browser encounters a filtered card outside filtered deck
the -99999 due date overflows the i32, yielding to a stuck interface
when running in a debug build
2021-05-25 13:44:42 +10:00
Damien Elmes
adcdb422c5 config updates by the frontend now skip undo by default 2021-05-24 14:50:46 +10:00
Damien Elmes
ea20c31b53 suppress some tests around the daily rollover 2021-05-24 14:18:07 +10:00
Damien Elmes
29f9717c84 fix new ease not being applied to card on lapse
+ zero remaining steps when graduating (they shouldn't have been doing
any harm, but this is neater)
+ add some more tests that cover these cases
2021-05-24 10:04:56 +10:00
Damien Elmes
3d4cf26758 expose undoable config changes to frontend; refresh sidebar
The browser header handling still needs updating
2021-05-21 17:50:41 +10:00
Damien Elmes
99b7da49a9 report changed cards when changing deck/flag
+ fix repeated flag shortcut not toggling
2021-05-21 16:03:05 +10:00
Damien Elmes
9aba412b44
Merge pull request #1180 from RumovZ/say-blank
Pronounce "[...]" as "blank" with TTS
2021-05-20 18:48:10 +10:00
RumovZ
b5c29fb498 Pronounce "[...]" as "blank" with TTS 2021-05-20 09:42:38 +02:00
Damien Elmes
b412bf97fb add a separate DeckId search for decks with children
- The "unbury deck" option was broken, as it was ignoring child
decks. It would be nice if we could use active_decks instead, but
plugging that into the old scheduler without breaking undo seems a bit
tricky.
- Remove the implicit From impl for decks, so we need to be forced to
think about whether we want child decks or not.
2021-05-20 11:44:37 +10:00
Damien Elmes
581480191a show note about old options screen if any add-ons are installed 2021-05-19 16:20:25 +10:00
Damien Elmes
1f77be01e7 fix accidental schema bump in undo that was forcing full sync 2021-05-19 14:17:49 +10:00
RumovZ
c1066167fa Adjust search syntax for filtered deck presets 2021-05-17 12:14:02 +02:00
Damien Elmes
1f16ce2096 shift learning fuzz into answering stage in test scheduler
When shown on the answer buttons, it's too distracting
2021-05-17 13:05:42 +10:00
RumovZ
92aa5404c9 Preserve formatting of regex error 2021-05-16 21:07:35 +02:00
RumovZ
9b2cd52b97 Remove SearchErrorKind::Regex as it's never used 2021-05-16 21:07:03 +02:00
Damien Elmes
13519a929c rework various aspects of the test scheduler
- Daily limits are no longer inherited - each deck limits its own
cards, and the selected deck enforces a maximum limit.
- Fetching of review cards now uses a single query, and sorts in advance.
In collections with a large number of overdue cards and decks, this is
faster than iterating over each deck in turn.
- Include interday learning count in review count & review limit, and
allow them to be buried.
- Warn when parent review limit is lower than child deck in deck options.
- Cap the new card limit to the review limit.
- Add option to control whether new card fetching short-circuits.
2021-05-16 20:23:07 +10:00
Damien Elmes
35063316d3 remove some duplicate code & add deck.or() helper 2021-05-14 22:35:52 +10:00
Damien Elmes
390a8421aa fix test scheduler undo + implement look-ahead
Instead of using a separate undo queue, the code now defers checking for
newly-due learning cards until the answering stage, and logs the updated
cutoff time as an undoable change, so that any newly-due learning cards
won't appear instead of a new/review card that was just undone.

Queue redo now uses a similar approach to undo, instead of rebuilding the
queues.
2021-05-14 22:16:53 +10:00
Damien Elmes
9990a10161 drop binary heap in test scheduler
The original rationale was avoiding a possible O(n) insertion if
the learning card was due outside the cutoff, but the increased code
complexity doesn't seem worth it, given that learning cards will
rarely grow above 1000.

Also added a currently-disabled test that demonstrates the current undo
handling behaviour is yielding incorrect counts; that will be reworked
in the next commit, and this change will make that easier.
2021-05-14 16:19:46 +10:00
Damien Elmes
dbbcb3e38c expose new sorting options in test scheduler options; move things around 2021-05-13 15:23:16 +10:00
Damien Elmes
a1bd6b481d pass sort options into test scheduler
- split new card fetch order and subsequent sort order; use latter
when building queues
- default to spacing siblings when burying is off, with options to
show each sibling in turn, and shuffle the fetched cards
2021-05-13 15:21:20 +10:00
Damien Elmes
b64f7a9456 fix burying in test scheduler
The bury new/review flags are now pulled from each card's home deck,
instead of using a global setting that had not been hooked up. This
unfortunately means we need to fetch the map of all decks up front, as
we need to be able to look up a deck configuration for cards that are
in filtered decks.

Fixes a "card was modified" error caused by cards being buried during
review, when they weren't removed up-front.
2021-05-12 12:00:15 +10:00
Damien Elmes
e737eb3088 is_stale() doesn't need to be passed deck
Deck changes will trigger a queue rebuild via requires_study_queue_rebuild()
2021-05-12 09:44:10 +10:00
Damien Elmes
49a1580566 use new API for test scheduler
Avoids duplicate work, and is a step towards allowing the next
states to be modified by third-party code.

Also:

- fixed incorrect underlined count, due to reviews being labeled as
learning cards
- fixed reviewer not refreshing when undoing a test review, by splitting
up backend queue rebuilding from frontend reviewer refresh
- moved answering into a CollectionOp
2021-05-11 13:06:03 +10:00
Damien Elmes
6775002709 better leech tag handling for test scheduler 2021-05-10 14:58:04 +10:00
Damien Elmes
3736e63a57 expose step counter and undone op changes in hook 2021-05-08 17:51:36 +10:00
Damien Elmes
e9e1edc64d move action names out of undo.ftl into actions.ftl 2021-05-08 17:11:54 +10:00
Damien Elmes
dfba66faa9 update Rust deps 2021-05-07 18:22:27 +10:00
Damien Elmes
d878de54c0 default to the v2 scheduler in new collections
ported from 53d9433d94
2021-05-06 19:09:28 +10:00
Damien Elmes
be994f4102 add support for custom undo steps, and merging multiple actions
Allows add-on authors to define their own label for a group of undoable
operations. For example:

def mark_and_bury(
    *,
    parent: QWidget,
    card_id: CardId,
) -> CollectionOp[OpChanges]:
    def op(col: Collection) -> OpChanges:
        target = col.add_custom_undo_entry("Mark and Bury")
        col.sched.bury_cards([card_id])
        card = col.get_card(card_id)
        col.tags.bulk_add(note_ids=[card.nid], tags="marked")
        return col.merge_undo_entries(target)

    return CollectionOp(parent, op)

The .add_custom_undo_entry() is for adding your own custom actions.
When extending a standard Anki action, instead store `target = 
col.undo_status().last_step` after executing the standard operation.

This started out as a bigger refactor that required a separate
.commit_undoable() call to be run after each operation, instead of
having each operation return changes directly. But that proved to be
somewhat cumbersome in unit tests, and ran the risk of unexpected
behaviour if the caller invoked an operation without remembering to
finalize it.
2021-05-06 16:39:06 +10:00
Damien Elmes
0fb745cdb9 add a valid, empty file so the check action works in Rust Analyzer 2021-05-05 15:53:27 +10:00
Damien Elmes
abab4826bb support undo for (renamed) unbury_deck() action 2021-04-30 20:03:20 +10:00
Damien Elmes
d0f3007fad remove some unneeded transactions from tests 2021-04-30 19:18:02 +10:00
Damien Elmes
449e3cc79d fix invalid outer transaction in clear_unused_tags() 2021-04-30 19:09:02 +10:00
Damien Elmes
cfb2a382b1 empty/restore media trash shouldn't clear undo 2021-04-30 19:07:30 +10:00
Damien Elmes
9a46ad6352 undoing of notetype fields
- fix stale cache issue
- update add cards screen in response to op changes
2021-04-30 17:15:59 +10:00
Damien Elmes
ea758f0092 update GUI to allow notetype addition undo
- backend now updates current notetype as part of addition
- frontend no longer implicitly adds, so we can assign a new name and
add in a single operation
2021-04-30 15:58:08 +10:00
Damien Elmes
2ff8c20686 update backend to support undoing of notetype changes 2021-04-30 12:54:59 +10:00
Damien Elmes
9d604f1ad0 make it more ergonomic to search directly via nodes in Rust 2021-04-30 11:37:55 +10:00
Damien Elmes
2902b64e82 move note/card removal for notetype out of storage layer 2021-04-29 19:44:09 +10:00
Damien Elmes
57eab0e33d make config prefix removal undoable 2021-04-29 19:16:02 +10:00
Damien Elmes
610f0b5254 use aux var when retrieving last deck for notetype
The adding case was already covered by defaults_for_adding(), but we
the code was using the old variable when adding new cards to an existing
note.
2021-04-29 19:15:27 +10:00
Damien Elmes
b160c2d85c move pub functions to top of notetype/mod.rs 2021-04-29 15:32:59 +10:00
Damien Elmes
86cf8949ea move pub functions to top of notes/mod.rs 2021-04-29 14:08:15 +10:00
Damien Elmes
07b5c35e90 confirm deletion is requiring a full sync 2021-04-28 22:21:16 +10:00
Damien Elmes
b22e851137 add some unit tests to deck config updating 2021-04-28 22:00:39 +10:00
Damien Elmes
a95cbb8515 DeckConfId -> DeckConfigId 2021-04-28 21:09:26 +10:00
Damien Elmes
1df86b28e8 sort deck on config update; fix id not being updated after deletion 2021-04-28 21:08:09 +10:00
Damien Elmes
92e4de16cf report pinned package issues upstream 2021-04-27 23:11:22 +10:00
Damien Elmes
cf2613e869 update Rust deps
- tokio 1.0
- updated reqwest, thanks to Rumo
- other minor dep updates

the reqwest build file has been split into two, as it was awkward
to manually update the combined file, and the platform gate is now
on the target in rslib/
2021-04-27 22:18:12 +10:00
Damien Elmes
f6a1a35113 update translations 2021-04-25 22:06:05 +10:00
Damien Elmes
30f5269304 hook new deck config screen up behind an env var 2021-04-22 10:59:16 +10:00
Damien Elmes
fd81700679 deckconf -> deckconfig 2021-04-20 21:54:24 +10:00
Damien Elmes
b448afdc57 change detection needs to ignore collection mtime bump 2021-04-20 19:52:47 +10:00
Damien Elmes
42d5d8071d check if deck changed before saving 2021-04-20 19:50:31 +10:00
Damien Elmes
4d1cedc8b2 implement deck config updating 2021-04-20 14:57:44 +10:00
Damien Elmes
4d4603c078 remove some imports duplicated by prelude 2021-04-19 18:22:43 +10:00
Damien Elmes
2cc23ce2bc
Merge pull request #1138 from RumovZ/introduced
Add search keyword for "first review in x days"
2021-04-19 18:22:15 +10:00
RumovZ
cac507b979 Use arg name instead of repeating it in format!() 2021-04-19 08:58:33 +02:00
RumovZ
194d251004 Use timestamp adding for writing cutoff 2021-04-19 08:44:13 +02:00
RumovZ
11cd1d9a26 Add sql condition for speedup in write_introduced 2021-04-19 08:43:32 +02:00
RumovZ
3cecc7157b Add sidebar filter "first review today" 2021-04-18 13:27:10 +02:00
RumovZ
e274ff26ab Add sqlwriter test for introduced 2021-04-18 12:32:02 +02:00
RumovZ
699437df0f Add cutoff_in_secs_from_days() helper method 2021-04-18 12:25:44 +02:00
RumovZ
5ec2e11de3 Add search keyword introduced
Filters for cards that had their first review within the last x days.
2021-04-18 12:14:18 +02:00
Damien Elmes
64ebc32b3d tidy up Rust imports
rustfmt can do this automatically, but only when run with a nightly
toolchain, so it needs to be manually done for now - see rslib/rusfmt.toml
2021-04-18 18:38:54 +10:00
Damien Elmes
262b50445c start on making deck config and schema/mod changes undoable
+ move timestamps into a struct in a separate file for convenience
2021-04-18 17:33:12 +10:00
Damien Elmes
76eb119870 add schema change prompt to removal, tweak return struct 2021-04-18 17:33:12 +10:00
RumovZ
fece39ca74 Maybe normalize name when preparing deck update 2021-04-18 09:16:43 +02:00
RumovZ
5e3e194289 Remove redundant imports 2021-04-18 08:43:46 +02:00
Damien Elmes
e71f7714ad as_str() -> as_native_str() 2021-04-18 09:33:39 +10:00
Damien Elmes
1acc679e8f hide NativeName inner value, and require explicit accessors 2021-04-18 09:29:35 +10:00
Damien Elmes
f924539574 create_missing_parents() can take a native name directly 2021-04-18 09:20:23 +10:00
RumovZ
20bd207f00 Give deck.name the newtype NativeDeckName
The deck name must be constructed by calling associated functions of
NativeDeckName, unless the name is guaranteed to be valid machine
name (like "Default").
NativeDeckName exposes methods to mutate the deck name and return
the human name.
The storage routines take &strs, but those should be slices of
NativeDeckNames to ensure machine form and normalization.
2021-04-17 22:47:04 +02:00
Damien Elmes
ac46d40db3
Merge pull request #1132 from RumovZ/refactor-decks
Refactor decks/mod.rs
2021-04-17 18:21:56 +10:00
Damien Elmes
8cf8c901fe fix parent limit handling
We can't calculate it on the backend, as adjusting a config may alter
the parent limit.

Also fix hidden deck name and missing separator.
2021-04-17 12:53:59 +10:00
RumovZ
c03acf832b Split Col impls in decks in pub and private blocks 2021-04-16 08:30:16 +02:00
RumovZ
5931631d76 Remove some imports in decks which are in prelude 2021-04-15 20:07:16 +02:00
RumovZ
3138fccaca Create decks/stats.rs 2021-04-15 20:06:16 +02:00
RumovZ
d2337e4cd3 Move some methods into decks/counts.rs 2021-04-15 19:53:11 +02:00
RumovZ
9dac8e2b5f Tidy up blocks and imports in decks/mod.rs 2021-04-15 19:43:35 +02:00
RumovZ
a1617760d4 Create decks/remove.rs 2021-04-15 19:35:54 +02:00
RumovZ
7225b7e4dc Create decks/add.rs 2021-04-15 19:29:52 +02:00
RumovZ
3f36db4f81 Create decks/reparent.rs 2021-04-15 19:17:43 +02:00
RumovZ
9c3671cf3f Create decks/name.rs 2021-04-15 18:46:01 +02:00
Damien Elmes
2953a821e5 don't let manual rescheduling affect card stats average
https://forums.ankiweb.net/t/set-due-date-has-a-weird-effect-on-cards-table/9289/2
2021-04-15 18:51:39 +10:00
Damien Elmes
7f738c11a2 deck config prototype work in progress
Still in the early stages, and not hooked up yet.
2021-04-14 22:33:10 +10:00
Damien Elmes
14ce1cccbb
Merge pull request #1126 from RumovZ/normalising-tweaks
Drop ANDs and optional double quotes when writing searches
2021-04-14 19:15:52 +10:00
Damien Elmes
c49d6ce49f run black/isort on Python scripts 2021-04-14 18:22:02 +10:00
RumovZ
2554e80ce8 Drop ANDs and optional quotes when normalising 2021-04-14 09:53:45 +02:00
Damien Elmes
28fdbd67ae add missing copyright headers to *.rs 2021-04-13 18:59:16 +10:00
Damien Elmes
dac990e4c2 fix misnamed timer property in deck config
The old JSON stored it as an int, but it's used as a boolean
2021-04-13 14:04:33 +10:00
RumovZ
fadec3dc5b Merge branch 'master' into backend-columns 2021-04-11 11:18:15 +02:00
RumovZ
801f52df40 Remove from_config variant in pb SortOrder
Instead, fetch the config order on the frontend and pass a builtin
variant into the backend.
That makes the following unnecessary:
* Resolving the config sort in search/mod.rs
* Deserializing the Column enum
* Config accessors for the sort columns
2021-04-10 11:13:42 +02:00
RumovZ
5982a777aa Rename SearchItems to ReturnItemtype 2021-04-10 10:14:41 +02:00
RumovZ
331df75b72 Remove internal clones of pb BrowserRow structs 2021-04-10 09:49:29 +02:00
RumovZ
48b70873cb Rename column label fields 2021-04-10 09:14:20 +02:00
RumovZ
b723159b3b Remove unused Serialize 2021-04-10 09:13:48 +02:00
RumovZ
d7f7deafd4 Store active browser columns in col state 2021-04-09 22:53:02 +02:00
RumovZ
769b5ac833 Remove superfluous muts 2021-04-09 22:51:18 +02:00
RumovZ
f04ea5a2c7 Move Column logic into main rslib 2021-04-09 19:09:48 +02:00
RumovZ
055a5e8a04 Remove pb SortKind enum and use pb Columns instead 2021-04-09 18:50:30 +02:00
RumovZ
bdd257e140 Merge SortKind enum into Column enum 2021-04-09 18:03:29 +02:00
RumovZ
c74078ea9e Unify state columns
* Remove duplicate backend columns
* Remove duplicate column routines
* Move columns on frontend from state to model
* Generate available columns from Colum enum
* Add second column label for notes mode
2021-04-08 23:48:24 +02:00
RumovZ
dd56dc6650 Rename columns for future mode-independent use 2021-04-08 23:43:48 +02:00
RumovZ
7a0cb08ac2 Merge browser row str methods 2021-04-08 20:45:47 +02:00
RumovZ
4692a48ef3 Add card mod column for notes mode 2021-04-08 20:14:10 +02:00
RumovZ
2350cd6e91 Add deck column for notes mode 2021-04-08 19:46:06 +02:00
RumovZ
c6ebb9b441 Merge row contexts 2021-04-08 13:51:46 +02:00
RumovZ
8a131da9a2 Add enum for column sorting 2021-04-08 11:40:24 +02:00
RumovZ
d8a0aa922c Add enum for column alignment 2021-04-08 11:28:29 +02:00
RumovZ
6c3c479906 Move BrowserColumn into BrowserColumns message 2021-04-08 10:16:06 +02:00
RumovZ
ee0ad6f5d6 Fix deck column serialization string 2021-04-06 23:03:30 +02:00
RumovZ
11bdeb9ca4 Add column logic on backend 2021-04-06 19:46:12 +02:00
RumovZ
929b7dc15b Make Column a strum 2021-04-06 16:54:09 +02:00
Damien Elmes
6e954e82a5 current deck change is now undoable
- make sure we set flag in changes when config var changed
- move current deck get/set into backend
- set_config() now returns a bool indicating whether a change was
made, so other operations can be gated off it
- active decks generation is deferred until sched.reset()
2021-04-06 21:52:06 +10:00
Damien Elmes
5676ad5101 update find&replace, and remove perform_op() 2021-04-06 17:07:38 +10:00
Damien Elmes
84fe309583 update scheduling ops
- migrate to CollectionOp()
- return actual change count when suspending/burying
- add helper to convert vec to vec of newtype
2021-04-06 16:38:42 +10:00
Damien Elmes
2de8cc1a94 update note ops
remove_note() now returns the count of removed cards, allowing us
to unify the tooltip between browser and review screen

I've left the old translation in - we'll need to write a script at
one point that gathers all references to translations in the code,
and shows ones that are unused.
2021-04-06 14:56:36 +10:00
Damien Elmes
3f62f54f14 more perform_op() tweaks
- pass the handler directly
- reviewer special-cases for flags and notes are now applied at
call site
- drop the kind attribute on OpChanges which is not needed
2021-04-06 10:14:11 +10:00
Damien Elmes
097121424b cache scheduling info
Saves us having to recalculate it for each browser row
2021-04-05 17:09:53 +10:00
Damien Elmes
ebf7cc61d4 switch next_day_at to a newtype 2021-04-05 16:17:26 +10:00
Damien Elmes
8d6b9d15a5 avoid fetching decks for each row
Like notetypes, there is a col.get_deck() routine which caches
fetches, so that successive fetches are cheap. This makes it simpler
to just fetch the deck at the start.

We were also attempting to fetch a deck with id 0 for each row; I've
changed this so that we only fetch it if the id is non-zero.

I18n uses an Arc internally, so it is cheap to clone. This allow us
to drop the lifetime specifiers on the context structures.
2021-04-05 15:13:32 +10:00
Damien Elmes
a18bb2af12 add booleans for various screens to OpChanges
The backend knows exactly which op has executed, and it saves us having
to re-implement this logic on each client.

Fixes the browser table refreshing when toggling decks.
2021-04-05 14:28:56 +10:00
Damien Elmes
3adf03f9cb add a unit test for multiple mutations 2021-04-05 11:52:23 +10:00
Damien Elmes
996d9f9bbc undo support for tag collapse; expand->collapse for consistency w/ decks 2021-04-05 11:47:12 +10:00
Damien Elmes
2168dfe63d add routine to set deck collapse state
Updating a deck via protobuf is now exposed on the backend, but not
currently on the frontend - I suspect we'll be better off writing
separate routines for the actions we need instead, and we get a better
undo description for free.

This is currently causing an ugly redraw in the browse screen, which
will need fixing.
2021-04-05 11:19:04 +10:00
Damien Elmes
42a4d11416 embed deck config and expose to frontend 2021-04-04 22:52:53 +10:00
Damien Elmes
037df9522b embed notetype messages 2021-04-04 21:57:17 +10:00
Damien Elmes
c4b3ab62c8 embed deck messages 2021-04-04 21:41:16 +10:00
Damien Elmes
1a4c4373d2 expose read-only access to new notetype objects 2021-04-04 20:45:37 +10:00
Damien Elmes
c60b88cd2f expose read-only access to new deck objects 2021-04-04 20:39:56 +10:00
Damien Elmes
8e16c94b96 recognize select statements with a leading newline from old stats screen 2021-04-03 23:23:33 +10:00
Damien Elmes
10309c9d9c fix error after undoing default deck deletion 2021-04-03 16:54:02 +10:00
Damien Elmes
41c5a25dc8 simplify errors
- use a flat enum instead of oneof messages, most of which were empty
- tidy up the Python side
2021-04-03 16:06:46 +10:00
Damien Elmes
fe6888f9a4 rename backend/err.rs -> error.rs 2021-04-03 14:47:52 +10:00
Damien Elmes
f666f15b63 use perform_op() for undo()
Instead of manually updating the UI after undoing, we just rely
on the same change notification infrastructure regular operations
use.
2021-04-03 14:38:49 +10:00
Damien Elmes
afc8680f2a make sure we don't invoke second search in v1 scheduler 2021-04-02 21:05:22 +10:00
Damien Elmes
e73359510d move filtered deck labels to backend
- use strum to generate an iterator for the protobuf enum so we don't
forget to add new labels if extending in the future
- no add-ons appear to be using dynOrderLabels(), so it has been removed

@RumovZ perhaps a similar approach might work for listing the available
browser columns as well?
2021-04-01 23:53:38 +10:00
Damien Elmes
f55fe6e518 i18n error shown when attempting to rebuild normal deck 2021-04-01 22:55:10 +10:00
Damien Elmes
ac1b9fadde merge the filtered deck errors into an enum
Fixes the wrong message being shown when trying to move cards to a
filtered deck
2021-04-01 22:30:00 +10:00
Damien Elmes
7df128a103 fix changes to .ftl and .proto files not being picked up by 'cargo check' 2021-04-01 22:29:54 +10:00
Damien Elmes
4e9a5ec5ea fix a clippy lint 2021-04-01 18:01:31 +10:00
Damien Elmes
ba541076aa convert card template error to tuple, and report notetype name in error
Older translations will note have the $notetype variable, but that is
not an error in Fluent - it would only cause problems if we tried to
use the new string on older Anki versions.
2021-04-01 17:59:33 +10:00
Damien Elmes
7a29d987c4 convert Json and Proto errors to tuple 2021-04-01 17:45:12 +10:00
Damien Elmes
55a6f10d24 tuple type for IoError 2021-04-01 17:40:35 +10:00
Damien Elmes
2b6c8b4296 tuple type for InvalidInput 2021-04-01 17:37:18 +10:00
Damien Elmes
a250464309 switch DbError to tuple type 2021-04-01 17:34:03 +10:00
Damien Elmes
1704f7fe80 drop dependency on failure crate 2021-04-01 17:21:13 +10:00
Damien Elmes
af37164fba move sync/network errors into separate file 2021-04-01 17:02:54 +10:00
Damien Elmes
8363fcf2a8 move DB error into separate file; add InvalidRegex error 2021-04-01 16:28:23 +10:00
Damien Elmes
f14a631f68 split search errors into separate file 2021-04-01 16:18:28 +10:00
Damien Elmes
094e4ad461 crate::err -> crate::error 2021-04-01 16:07:13 +10:00
RumovZ
99e28068f9 Refactor get_row_color() 2021-03-31 08:56:54 +02:00
RumovZ
5e151cdc42 Pass Column by value 2021-03-31 00:02:10 +02:00
RumovZ
8779fb5ede Add note interval column 2021-03-30 23:44:35 +02:00
RumovZ
31155f2dcd Refactor note_ease_str() 2021-03-30 23:44:16 +02:00
RumovZ
f530c6d852 Fix comment typo 2021-03-30 21:40:35 +02:00
RumovZ
1ad91a5312 Add note due column 2021-03-30 21:39:15 +02:00
RumovZ
e9c14a763c Refactor card_due_str() 2021-03-30 20:50:09 +02:00
RumovZ
da156cd759 Rename browser_rows to browser_table
Reflects the addition of column handling.
2021-03-30 12:08:35 +02:00
RumovZ
ffe77b1291 Add browser column enum for backend 2021-03-30 11:59:52 +02:00
RumovZ
4933b922f7 Add note lapses column 2021-03-29 16:06:15 +02:00
RumovZ
32e538d0db Add note reps column 2021-03-29 15:52:02 +02:00
Damien Elmes
3383f1742a rename BrowserCardState
Use a more verbose name, and use 'note' rather than 'card', so we
can rely on the default of False
2021-03-29 17:12:45 +10:00
RumovZ
0d8b1c9d0b squash merge browser refactor
Closes #1100
2021-03-29 16:14:54 +10:00
Damien Elmes
0a5222c400 add a few more ftl type hints 2021-03-29 15:55:15 +10:00
Damien Elmes
6ca690a14c gate qt template inclusion on extra_ftl_root name
Bazel was not noticing that the build script needs to be recompiled
when the qt templates flag was changed.
2021-03-29 13:17:38 +10:00
Damien Elmes
cfac40febc switch NoteType to Notetype
When used as a variable, we were typically calling it a 'notetype', not
a 'note type'.
2021-03-27 22:03:19 +10:00
Damien Elmes
9f4a06abee ID -> Id in protobuf and Python
follow-up to dc81a7fed0
2021-03-27 21:38:20 +10:00
Damien Elmes
fcfa6bab4e update to latest Rust 2021-03-27 20:49:10 +10:00
Damien Elmes
561d160590 fix some clippy lints in tests 2021-03-27 20:44:31 +10:00
Damien Elmes
1055acb9f2 fix more issues uncovered by the latest clippy 2021-03-27 20:25:34 +10:00
Damien Elmes
dc81a7fed0 use mixed case for abbreviations in Rust code
So, this is fun. Apparently "DeckId" is considered preferable to the
"DeckID" were were using until now, and the latest clippy will start
warning about it. We could of course disable the warning, but probably
better to bite the bullet and switch to the naming that's generally
considered best.
2021-03-27 19:53:33 +10:00
Damien Elmes
89d249b3b6 update to the latest rules_rust + security framework update 2021-03-27 19:28:19 +10:00
Damien Elmes
dd99059218 address some new clippy lints 2021-03-27 19:28:19 +10:00
Damien Elmes
a96ac98605 update Rust deps 2021-03-27 14:47:16 +10:00
Damien Elmes
b5b21edd11 add string/number distinction to generated Rust methods 2021-03-27 14:31:23 +10:00
Damien Elmes
e4002d7a5e update to latest Fluent 2021-03-27 13:24:11 +10:00
Damien Elmes
3433c02242 i18n->tr in rslib/ to match Python/TS code 2021-03-27 12:09:51 +10:00
Damien Elmes
d6b9cc4d9b drop the legacy enum from rslib, and pass separate module/message idx 2021-03-27 11:56:31 +10:00
Damien Elmes
f485efce16 update remaining TR references in rslib 2021-03-27 11:18:34 +10:00
Damien Elmes
c45ab78b73 update multi-arg TR references, where some needed reordering 2021-03-27 10:49:40 +10:00
Damien Elmes
698ae855d3 update 1 arg tr strings in rslib 2021-03-27 10:39:53 +10:00
Damien Elmes
d5e5722dc8 preserve variable order when extracting from ftl files 2021-03-27 09:09:13 +10:00
Damien Elmes
dc5fdd30d4 update no-arg TR references in rslib/ 2021-03-26 23:16:08 +10:00
Damien Elmes
5abc48932c write methods into generated.rs 2021-03-26 23:07:18 +10:00
Damien Elmes
cca1d29cc8 fix warning in latest Rust 2021-03-26 23:06:15 +10:00
Damien Elmes
b57e9be46f allow js to request specific i18n modules
Brings the payload on the congrats page with a non-English language
down from about 150k to 15k
2021-03-26 21:43:36 +10:00
Damien Elmes
df93ed0b15 update TR references with args in *.ts; fix average answer time 2021-03-26 19:10:39 +10:00
Damien Elmes
3d366d5264 add types to some more Fluent variables 2021-03-26 16:52:54 +10:00
Damien Elmes
8cc6758eb1 declare variables with some common names as int instead of a union 2021-03-26 16:33:53 +10:00
Damien Elmes
3199fa80d5 delimit variables in docstrings to make them easier to read 2021-03-26 14:38:30 +10:00
Damien Elmes
8294b18c68 catch variables only used in plural selection 2021-03-26 14:20:44 +10:00
Damien Elmes
3c19708684
Merge pull request #1094 from shaunren/fix-tts-html
Fix extraneous whitespaces from strip_html_for_tts
2021-03-26 11:00:41 +10:00
Damien Elmes
c697eb1086 embed strings.json into write_json.rs
It appears that including the build script as a dependency is not
enough to make the file available at runtime, so the build breaks
if ts/ is built first.
2021-03-26 09:55:21 +10:00
Damien Elmes
9aece2a7b8 rework translation handling
Instead of generating a fluent.proto file with a giant enum, create
a .json file representing the translations that downstream consumers
can use for code generation.

This enables the generation of a separate method for each translation,
with a docstring that shows the actual text, and any required arguments
listed in the function signature.

The codebase is still using the old enum for now; updating it will need
to come in future commits, and the old enum will need to be kept
around, as add-ons are referencing it.

Other changes:

- move translation code into a separate crate
- store the translations on a per-file/module basis, which will allow
us to avoid sending 1000+ strings on each JS page load in the future
- drop the undocumented support for external .ftl files, that we weren't
using
- duplicate strings in translation files are now checked for at build
time
- fix i18n test failing when run outside Bazel
- drop slog dependency in i18n module
2021-03-26 09:41:32 +10:00
Shaun Ren
1f3751d191 Fix extraneous whitespaces from strip_html_for_tts 2021-03-25 11:44:42 -04:00
Damien Elmes
d382b33585 rework filtered deck screen & search errors
- Filtered deck creation now happens as an atomic operation, and is
undoable.
- The logic for initial search text, normalizing searches and so on
has been pushed into the backend.
- Use protobuf to pass the filtered deck to the updated dialog, so
we don't need to deal with untyped JSON.
- Change the "revise your search?" prompt to be a simple info box -
user has access to cancel and build buttons, and doesn't need a separate
prompt. Tweak the wording so the 'show excluded' button should be more
obvious.
- Filtered decks have a time appended to them instead of a number,
primarily because it's easier to implement. No objections going back to
the old behaviour if someone wants to contribute a clean patch.
The standard de-duplication will happen if two decks are created in the
same minute with the same name.
- Tweak the default sort order, and start with two searches. The UI
will still hide the second search by default, but by starting with two,
the frontend doesn't need logic for creating the starting text.
- Search errors now have their own error type, instead of using
InvalidInput, as that was intended mainly for bad API calls. The markdown
conversion is done when the error is converted from the backend, allowing
errors to printed as a string without any special handling by the calling
code.

TODO: when building a new filtered deck, update_active() is clobbering
the undo log when the overview is refreshed
2021-03-24 22:04:35 +10:00
Damien Elmes
12597e1094 support undo of filtered deck build/empty 2021-03-24 12:56:06 +10:00
Damien Elmes
2a168adb66 move filter code into scheduler/ 2021-03-23 23:55:28 +10:00
Damien Elmes
b5c58ff8e6 nest search term message/order enum 2021-03-23 23:28:50 +10:00
Damien Elmes
ff0d346927 move browser_row method into search service
For want of a better place to put it. Also split the node conversion
into a separate file.
2021-03-23 18:55:05 +10:00
Damien Elmes
95dea7f20a move activeCols into config/ 2021-03-23 18:40:50 +10:00
Damien Elmes
5fd79d9246
Merge pull request #1082 from RumovZ/backend-rows
Backend rows
2021-03-23 18:31:42 +10:00
Damien Elmes
01161c8ed2 use perform_op() for deck creation 2021-03-22 23:17:07 +10:00
RumovZ
03b9667789 Use raw sort field text in note_field_str() ...
... instead of the preprocessed note.sort_field. That means we always
have to load the note with fields.
2021-03-22 12:12:52 +01:00
RumovZ
9151bfb53e Return input if decode_entities() encounters error 2021-03-22 12:08:22 +01:00
Damien Elmes
0123a382ec deck rename with perform_op() 2021-03-22 20:38:51 +10:00
Damien Elmes
6a11c0398c use perform_op() for deck drag&drop 2021-03-22 18:23:56 +10:00
RumovZ
de73232f0d Fix date_string using FixedOffset instead of Local 2021-03-22 08:50:54 +01:00
Damien Elmes
7273996041 fix note importing detecting changes due to unicode differences
https://forums.ankiweb.net/t/python-checksum-rust-checksum/8195/16
2021-03-22 10:56:24 +10:00
RumovZ
255daad820 Fix card_due_str() 2021-03-21 21:18:56 +01:00
RumovZ
c91182b248 Strip question from answer string 2021-03-21 21:17:38 +01:00
RumovZ
af90bbf879 Check original_deck_id rather than original_deck()
in card_due_str() as we don't necessarily have to load that deck.
2021-03-20 18:12:00 +01:00
RumovZ
1ab0d4dff8 Refactor browser_rows.rs
* Make RowContext taking functions methods
* Make RowContext constructor a method
* Rename 'with_fields' to 'card_render'
2021-03-20 18:02:41 +01:00
RumovZ
04ae6f727b Rename browser_rows/RowColor to Color 2021-03-20 17:31:16 +01:00
RumovZ
b86d683f17 Rename render_card_inner() to render_card() 2021-03-20 17:26:30 +01:00
RumovZ
7425aa6b58 Refactor search/browser.rs to browser_rows.rs 2021-03-20 17:20:49 +01:00
RumovZ
c68a6131e0 Add backend routine for browser rows 2021-03-20 12:02:51 +01:00
RumovZ
436269b701 Add backend mod for browser rows 2021-03-20 12:02:18 +01:00
RumovZ
e931a429b3 Add html_to_text_line() on backend 2021-03-20 12:00:45 +01:00
RumovZ
1823c0dda4 Add get_note_without_fields() from storage 2021-03-20 11:59:45 +01:00
Damien Elmes
f7e4b6d822 fix spurious warning in db check for v1 scheduler+non-zero lapse ivl%
https://forums.ankiweb.net/t/invalid-property-on-card-not-resolving-via-recommended-check-database/8430
2021-03-19 22:57:43 +10:00
Damien Elmes
4c61c92806 speed up tag drag&drop and finish tag tidyup
approx 4x speedup when reparenting 10-15 tags and their children at once
2021-03-19 19:45:21 +10:00
Damien Elmes
9c2bff5b6d change bulk_update() into find_and_replace_tag()
Now behaves the same way as standard find&replace:
- Will match substrings
- Regexs can be used to match multiple items; we no longer split
input on spaces.
- The find&replace dialog has been updated to add tags to the field
list.
2021-03-19 19:45:21 +10:00
Damien Elmes
b287cd5238 speed up "add tags" and avoid usage of regex 2021-03-19 19:45:21 +10:00
Damien Elmes
08895c58d9 introduce separate routine to remove tags from specific notes
We were (ab)using the bulk update routine to do deletions, but that
code was really intended to be used for finding&replacing, where an
exact match is not a requirement.
2021-03-19 19:45:21 +10:00
Damien Elmes
33d467e688 split tags.rs up 2021-03-19 19:45:21 +10:00
Damien Elmes
09076da937 make tag deletion undoable, and speed it up
- ~4x faster than before on tag tree with 30k notes
- remove the separate clear_tag() backend method
2021-03-19 19:45:21 +10:00
Damien Elmes
157b74b671 make tag renaming undoable, and speed it up
~3x speedup when renaming a tag that's on 25k notes
2021-03-19 19:45:21 +10:00
Damien Elmes
0331d8b588 make reposition undoable 2021-03-19 19:45:21 +10:00
Damien Elmes
de668441b5 clear_unused_tags and browser redraw improvements
- clear_unused_tags() is now undoable, and returns the number of removed
notes
- add a new mw.query_op() helper for immutable queries
- decouple "freeze/unfreeze ui state" hooks from the "interface update
required" hook, so that the former is fired even on error, and can be
made re-entrant
- use a 'block_updates' flag in Python, instead of setUpdatesEnabled(),
as the latter has the side-effect of preventing child windows like
tooltips from appearing, and forces a full redrawn when updates are
enabled again. The new behaviour leads to the card list blanking out
when a long-running op is running, but in the future if we cache the
cell values we can just display them from the cache instead.
- we were indiscriminately saving the note with saveNow(), due to the
call to saveTags(). Changed so that it only saves when the tags field
is focused.
- drain the "on_done" queue on main before launching a new background
task, to lower the chances of something in on_done making a small query
to the DB and hanging until a long op finishes
- the duplicate check in the editor was executed after the webview loads,
leading to it hanging until the sidebar finishes loading. Run it at
set_note() time instead, so that the editor loads first.
- don't throw an error when a long-running op started with with_progress()
finishes after the window it was launched from has closed
- don't throw an error when the browser is closed before the sidebar
has finished loading
2021-03-19 19:45:21 +10:00
Damien Elmes
6b0fe4b381 undoable ops now return changes directly; add new *_ops.py files
- Introduced a new transact() method that wraps the return value
in a separate struct that describes the changes that were made.
- Changes are now gathered from the undo log, so we don't need to
guess at what was changed - eg if update_note() is called with identical
note contents, no changes are returned. Card changes will only be set
if cards were actually generated by the update_note() call, and tag
will only be set if a new tag was added.
- mw.perform_op() has been updated to expect the op to return the changes,
or a structure with the changes in it, and it will use them to fire the
change hook, instead of fetching the changes from undo_status(), so there
is no risk of race conditions.
- the various calls to mw.perform_op() have been split into separate
files like card_ops.py. Aside from making the code cleaner, this works
around a rather annoying issue with mypy. Because we run it with
no_strict_optional, mypy is happy to accept an operation that returns None,
despite the type signature saying it requires changes to be returned.
Turning no_strict_optional on for the whole codebase is not practical
at the moment, but we can enable it for individual files.

Still todo:
- The cursor keeps moving back to the start of a field when typing -
we need to ignore the refresh hook when we are the initiator.
- The busy cursor icon should probably be delayed a few hundreds ms.
- Still need to think about a nicer way of handling saveNow()
- op_made_changes(), op_affects_study_queue() might be better embedded
as properties in the object instead
2021-03-19 19:45:21 +10:00
Damien Elmes
30c7cf1fdd fade out webview when pending updates; do some reviewer updates immediately
Issues that need fixing:
- when the editor saves the note with perform_op(), if it isn't modified,
no new undo entry is created, and perform_op then returns the changes
made by the previous operation instead
- the approach of fetching the last action in a subsequent backend
method is unsound, as another queued operation may sneak in first before
we have a chance to query the result - it would be better if it were
returned in a single atomic action
- redrawing the current card while editing is likely to make sound
autoplay annoyingly, and it has an unpleasant redraw. We may be better off
fading it out instead

Side note: the editor cursor moves to the start of the field when the
note is updated in another window - it might be nicer to have it move
the cursor to the end instead.
2021-03-19 19:45:21 +10:00
Damien Elmes
1e849316be more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.

I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.

Other changes:

- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-19 19:45:21 +10:00
Damien Elmes
112cbe8b59 experiment with finer-scoped reset in perform_op()
Basic proof of concept, where the 'delete note' operation in the
reviewer has been updated to use mw.perform_op(). Instead of manually
calling .reset() afterwards, a summary of the changes is returned as
part of the undo status query, and various parts of the GUI can listen
to gui_hooks.operation_did_execute and decide whether they want to
redraw based on the scope of the changes. This should allow the sidebar
to selectively redraw just the tags area in the future for example.

Currently we're just listing out all possible areas that might be changed;
in the future we could theoretically inspect the specific changes in the
undo log to provide a more accurate report (avoiding refreshing the tags
list when no tags were added for example).

You can test it out by opening the browse screen while studying, and
then deleting the current card - the browser should update to show (deleted)
on the cards due the earlier change.

If going ahead with this, aside from updating all the screens that currently
listen for resets, some thought will be required on how we can integrate
it with legacy code that expects to called when resets are made, and expects
to call .reset() when it makes changes.

Thoughts?
2021-03-19 19:45:21 +10:00
Damien Elmes
7fab319dad derive reset scope from last undoable operation 2021-03-19 19:45:21 +10:00
Damien Elmes
90526c61cd move ops.rs out of undo/ 2021-03-19 19:45:21 +10:00
Damien Elmes
8fc43956c2 move collection mtime bump into backend
Fixes the following issue:
- some code directly modifies the database, causing modified_in_python
to be set to true
- an undoable operation is run, which calls autosave() at the end
- autosave() notices there's an undoable operation, and commits immediately
- because modified_in_python was true, col.mtime was bumped in Python
- that invalidated the undo queue, preventing the operation from being
undone
2021-03-19 19:45:21 +10:00
Arthur Milchior
9661684ca3 If a template name contains only quote, show relevant error message
This is for the sake of the consistency with the last commit
2021-03-14 02:10:48 +01:00
Arthur Milchior
dd48b2dff0 Return meaningful message if a field is empty after normalizing
This correct the probably rare bug as follow:

I got a note type with a field whose name is "\".

When I made any change to this note type, even unrelated, I get a message stating that there is an empty field. This is
strange because I can see it to be false. Investigating show that "\" is normalized to empty field. This ensure that
it's shown
2021-03-14 02:10:32 +01:00
Damien Elmes
bd959731d7
Merge pull request #1067 from RumovZ/regex-err
Fix regex error formatting and search error escaping
2021-03-13 10:16:10 +10:00
RumovZ
e033f21767 Fix markdown escaping in search errors 2021-03-12 20:32:38 +01:00
RumovZ
2078a094f4 Fix formatting of invalid regex error
Preserve whitespace, special characters and use monospace font.
2021-03-12 20:31:23 +01:00
Damien Elmes
28994458e9 add indexes to graves table to speed up undo 2021-03-12 18:59:24 +10:00
Damien Elmes
2ffc055487 'change deck' now undoable 2021-03-12 16:27:57 +10:00
Damien Elmes
7b7d7e8330 consume original card when updating 2021-03-12 16:20:58 +10:00
Damien Elmes
24762261d9 make 'forget card' undoable; remove checkpoint() in set_due_date 2021-03-12 16:13:50 +10:00
Damien Elmes
3b067c7a66 limit initial sort selection to new cards
https://github.com/ankidroid/Anki-Android/issues/8172
2021-03-12 14:58:19 +10:00