Commit graph

1095 commits

Author SHA1 Message Date
Damien Elmes
d7a577e3af 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
970543ee26 move activeCols into config/ 2021-03-23 18:40:50 +10:00
Damien Elmes
2bffcba345 Merge pull request #1082 from RumovZ/backend-rows
Backend rows
2021-03-23 18:31:42 +10:00
Damien Elmes
fafe30f4b4 use perform_op() for deck creation 2021-03-22 23:17:07 +10:00
RumovZ
8b21c1ad7c 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
4c169106af Return input if decode_entities() encounters error 2021-03-22 12:08:22 +01:00
Damien Elmes
12e1ca0c2f deck rename with perform_op() 2021-03-22 20:38:51 +10:00
Damien Elmes
42d007d94d use perform_op() for deck drag&drop 2021-03-22 18:23:56 +10:00
RumovZ
38f03650c9 Fix date_string using FixedOffset instead of Local 2021-03-22 08:50:54 +01:00
Damien Elmes
b9421ac38b 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
0ca8434744 Fix card_due_str() 2021-03-21 21:18:56 +01:00
RumovZ
d07c7e1d94 Strip question from answer string 2021-03-21 21:17:38 +01:00
RumovZ
88f39fe081 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
72138a9528 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
14bd8181b3 Rename browser_rows/RowColor to Color 2021-03-20 17:31:16 +01:00
RumovZ
aed19da451 Rename render_card_inner() to render_card() 2021-03-20 17:26:30 +01:00
RumovZ
e965f1a685 Refactor search/browser.rs to browser_rows.rs 2021-03-20 17:20:49 +01:00
RumovZ
f6de60e5e6 Add backend routine for browser rows 2021-03-20 12:02:51 +01:00
RumovZ
20b36bff1f Add backend mod for browser rows 2021-03-20 12:02:18 +01:00
RumovZ
23a52c23a7 Add html_to_text_line() on backend 2021-03-20 12:00:45 +01:00
RumovZ
44f86f6402 Add get_note_without_fields() from storage 2021-03-20 11:59:45 +01:00
Damien Elmes
76fdfff714 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
0e925b407d 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
83a9c22186 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
5bb5811b5d speed up "add tags" and avoid usage of regex 2021-03-19 19:45:21 +10:00
Damien Elmes
6ce9297e37 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
0555b4398f split tags.rs up 2021-03-19 19:45:21 +10:00
Damien Elmes
1d0fabd859 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
c98c553a96 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
5c648ec4c6 make reposition undoable 2021-03-19 19:45:21 +10:00
Damien Elmes
b8bdc5824b 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
42e20461c0 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
ebd3bba91b 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
b9bb9920b5 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
fbcfa48419 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
4fa632f335 derive reset scope from last undoable operation 2021-03-19 19:45:21 +10:00
Damien Elmes
c72862af9f move ops.rs out of undo/ 2021-03-19 19:45:21 +10:00
Damien Elmes
b8e56dafda 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
d1bf02a709 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
574a513fe6 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
b5a913c1cf 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
9bbe584522 Fix markdown escaping in search errors 2021-03-12 20:32:38 +01:00
RumovZ
456a3b214a Fix formatting of invalid regex error
Preserve whitespace, special characters and use monospace font.
2021-03-12 20:31:23 +01:00
Damien Elmes
ae6cf81d69 add indexes to graves table to speed up undo 2021-03-12 18:59:24 +10:00
Damien Elmes
b9581b94fb 'change deck' now undoable 2021-03-12 16:27:57 +10:00
Damien Elmes
5b52f0e931 consume original card when updating 2021-03-12 16:20:58 +10:00
Damien Elmes
fef8c402e0 make 'forget card' undoable; remove checkpoint() in set_due_date 2021-03-12 16:13:50 +10:00
Damien Elmes
28cd625204 limit initial sort selection to new cards
https://github.com/ankidroid/Anki-Android/issues/8172
2021-03-12 14:58:19 +10:00
Damien Elmes
7f8d675e25 'set due date' now undoable 2021-03-12 14:50:31 +10:00
Damien Elmes
091ea67690 enable deck removal undo again 2021-03-11 22:24:12 +10:00