Commit graph

9161 commits

Author SHA1 Message Date
Hikaru Y
a3c36a530b Fix memory leak in AnkiWebView (#1510) 2021-11-29 12:31:37 +10:00
RumovZ
7c2e0ab2d4 Remove redundant camelcase aliases (#1509) 2021-11-26 12:29:48 +10:00
Damien Elmes
cbf14b16c4 move aqt/platform.py code into theme.py
We have other platform-specific code scattered through the codebase,
and better it lives in a location where it is used.
2021-11-25 19:10:57 +10:00
Damien Elmes
2898a46e54 convert invariant assertions to if statements
The packaged builds of 2.1.50 use python -OO, which means our assertion
statements won't be run. This is not an issue for unit tests (as we
don't run them from a packaged build), or for type assertions (which are
added for mypy's benefit), but we do need to ensure that invariant checks
are still run.
2021-11-25 17:47:50 +10:00
Damien Elmes
5d721e8893 fix check for user exporting into data folder on Windows
https://forums.ankiweb.net/t/unable-to-export-colpkg-file/10527
2021-11-25 09:30:17 +10:00
Damien Elmes
0e4c02eac1 update platform checks (eg isWin -> is_win) + devMode 2021-11-25 09:06:16 +10:00
Damien Elmes
270eaa4478 avoid duplicate work in overview screen 2021-11-25 09:01:02 +10:00
Damien Elmes
b1575f9a63 minor docstring fix 2021-11-25 08:57:33 +10:00
Damien Elmes
0d46cb7fd9 add minimal theme detection on Linux
Closes #1116
2021-11-25 08:45:14 +10:00
RumovZ
54d39d1b3b Live theme changes (#1497)
* Allow theme change at runtime and add hook

* Save or restore default palette on theme change

* Update aqt widget styles on theme change

* styling fixes

- drop _light_palette, as default_palette serves the same purpose
- save default platform theme, and restore it when switching away
from nightmode
- update macOS light/dark mode on theme switch
- fix unreadable menus on Windows

* update night-mode classes on theme change

This is the easy part - CSS styling that uses standard_css or our
css variables should update automatically. The main remaining issue
is JS code that sets colors based on the theme at the time it's run -
eg the graph code, and the editor.

* switch night mode value on toggle

* expose current theme via a store; switch graphs to use it

https://github.com/ankitects/anki/issues/1471#issuecomment-972402492

* start using currentTheme in editor/components

This fixes basic editing - there are still components that need updating.

* add simple xcodeproj for code completion

* add helper to get currently-active system theme on macOS

* fix setCurrentTheme not being immediately available

* live update tag color

* style().name() doesn't work on Qt5

* automatic theme switching on Windows/Mac

* currentTheme -> pageTheme

* Replace `nightModeKey` with `pageTheme`

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2021-11-25 07:17:41 +10:00
Damien Elmes
63b34e0f0e prettier: don't depend on system node being available 2021-11-25 07:14:15 +10:00
Damien Elmes
db4a15eea6 change previous card info shortcut
https://forums.ankiweb.net/t/option-i-shortcut-conflicts-with-language-input/15206
2021-11-24 15:44:25 +10:00
Damien Elmes
fac8df43dc update translations 2021-11-24 14:44:02 +10:00
Damien Elmes
55056baf28 run ftl/remove-unused.sh 2021-11-24 14:44:02 +10:00
Damien Elmes
a705b72c46 retire the v1 scheduler 2021-11-24 14:12:56 +10:00
Matthias Metelka
e2a30666e4 Change Notetype UI Rework (#1499)
* Enable access to old notetype name

* Set minimum height for ChangeNotetypeDialog

* Add bootstrap icons to change-notetype

* Move alert up and make it collapsible

* Tweak some CSS

- Add variables --sticky-bg and --sticky-border to StickyContainer
- Tweak base.css

* Add translatable string "(Nothing)"

* Rework ChangeNotetype screen

* Initially load option at newIndex and remaining options on focus

Optimization for big notetypes:
Should increase efficiency from O(n²) to O(n). Test on notetype with 500 templates shows significant improvement in load time (~10s down to ~1s).

* Try to satisfy rust test

* Change arrow direction depending on reading direction

+ add 0.5em top padding to main

* Create Alert.svelte

* Introduce CSS variable --pane-bg

* Revert "Initially load option at newIndex and remaining options on focus"

This reverts commit f42beee45c.

* Final cleanup

* Refine padding/gutter
2021-11-24 12:09:55 +10:00
Henrik Giesel
a1d6269d49 Fix some issues with new surround buttons (#1505)
* Add a store to indicate whether input trigger is active

Button state is then indicated by: caretIsInBold XOR boldTriggerActive

* Fix surrounding where normalization is tripped up by empty text nodes

* Add failing test for unsurrounding

* Fix failing test

* prohibitOverlapse does not need to be active, if aboveEnd is null

* Reinsert Italic and Underline button

* Refactor find-adjacent to use sum types

* Simplify return value of normalizeAdjacent
2021-11-24 10:33:14 +10:00
Henrik Giesel
e14ab90551 Fix Cloze button (#1504) 2021-11-24 10:25:24 +10:00
Damien Elmes
a47ae935bf minor wording tweaks and a docstring 2021-11-23 12:18:50 +10:00
evandrocoan
6dfd9665b2 Fix issue 1362 and add a default favicon.ico (#1369) 2021-11-23 12:18:32 +10:00
Damien Elmes
1d04c824b7 remove experimental comment and update link 2021-11-23 11:13:04 +10:00
Damien Elmes
8acc482848 drop beta tag from v3 scheduler
Will exit beta when 2.1.50 is released as stable
2021-11-23 11:10:04 +10:00
Arthur Milchior
a93fad57d9 Remove all_names in notetypechooser (#1501)
The only purpose is to stop having warning in my console because all_names is deprecated
2021-11-23 10:27:57 +10:00
Henrik Giesel
0f17c32401 Mathjax editor improvements (#1502)
* Remove unnecessary stopPropagation of mathjax-overlay events

* Use CodeMirror component for MathjaxHandle

* Refactor ResizeObserver code in MathjaxHandle

* Wrap setRange in CodeMirror in try/catch

* Add Mathjax Editor bottom margin

* Add custom Enter and Shift+Enter shortcuts for the MathjaxHandle

* Format

* Move placeCaretAfter to domlib

* Move focus back to field after editing Mathjax

* Put Cursor after Mathjax after accepting

* Add delete button for Mathjax

* Change border color of mathjax menu

* Refactor into MathjaxMenu

* Put caretKeyword in variable

* Use one ResizeObserver for all Mathjax images

* Add minmimum width for Mathjax editor

* is still smaller than minimal window width

* Add bazel directories to .prettierignore and format from root

* exclude ftl/usage (dae)

the json files that live there are output from our tooling, and
formatting them means an extra step each time we want to update them

also exclude .mypy_cache, which is output by scripts/mypy*

* minor ftl tweak: newline -> new line  (dae)
2021-11-23 10:27:32 +10:00
Damien Elmes
bf11b3419d SELinux fixes
https://forums.ankiweb.net/t/anki-installer-for-linux-install-sh-should-change-file-owners-and-selinux-labels-while-installation/15143
2021-11-22 11:06:21 +10:00
Henrik Giesel
a2aeaf456f Fix missing left margin in CongratsPage (#1498) 2021-11-19 11:02:54 +10:00
Damien Elmes
695871e66c Fix latest Rusqlite on Windows
https://github.com/bazelbuild/rules_rust/pull/1025
2021-11-19 10:44:02 +10:00
Damien Elmes
89b043c319 roll rusqlite back due to Windows breakage 2021-11-18 21:39:23 +10:00
Damien Elmes
c5c41759b4 update Rust deps 2021-11-18 20:58:41 +10:00
Damien Elmes
1ac84d9454 update to edition 2021 2021-11-18 20:51:10 +10:00
Damien Elmes
744254daa4 update Rust to 1.56.1 2021-11-18 20:44:15 +10:00
Henrik Giesel
cfe1895870 Reverse-engineer surrounding with execCommand (#1377)
* Add utility functions for saving and restoring the caret location

Implement surroundNoSplitting

Clarify surroundNoSplitting comments

Start implementing surroundSplitting and triggerIfSimpleInput

Fix after rebase

Implement findBefore / findAfter in lib/surround

* to merge adjacent nodes into the surrounding nodes

Use new prettier settings with lib/{location,surround}

Fix imports that I missed to rename

Add some tests for find-adjacent

Split find-within from find-adjacent

Normalize nodes after insertion in surroundNoSplitting

Do not deep clone surroundNode

-> no intention of supporting deep nodes, as normalization would be impossible

Add some tests concerning nested surrounding nested nodes

Select surroundedRange after surrounding

Fix ascendWhileSingleInline

A flawed first surround/trigger implementation

Move trigger out of lib/surround

Implement Input Manager as a way to handle bold on empty selection

Switch bold button away from execCommand

Pass in Matcher instead of selector to find-adjacent and surroundNoSplitting

* Also adds a failing test for no-splitting

Refactor find-adjacent

* add failing test when findBefore's nodes have different amounts of
  child nodes

Change type signature of find-adjacent methods to more single-concern

Add test for surrounding where adjacent block becomes three Text elements

Make nodes found within surrounded range extend the ranges endOffset

Add base parameter to surroundNoSplitting to stop ascending beyond container

Stop surrounding from bubbling beyond base in merge-match

Make all tests pass

Add some failing tests to point to future development

Add empty elements as constant

Implement a broken version of unsurround

Even split text if it creates zero-length texts

-> they are still valid, despite what Chromium says

Rename {start,end} to {start,end}Container

Add more unit tests with surround after a nested element

Set endOffset after split-off possibly zero length text nodes

Deal with empty elements when surrounding

Only include split off end text if zero length

Use range anchors instead off calcluating surroundedRange from offsets

* this approach allows for removal of base elements when unsurrounding

Comment out test which fail because of jsdom bugs

We'll be able to enable them again after Jest 28

Make the first unsurround tests pass

Add new failing test for unsurround text within tag

Fix unsurround

Test is deactivated until Jest 28

Rewrite input-manager and trigger callback after insertion

Avoid creating zero length text nodes by using insertBefore when appropriate

Implement matches vs keepMatches

Make shadow root and editable element available on component tree

Make WithState work with asynchronous updater functions

Add new Bold/Italic/UnderlineButton using our logic

Add failing test for unsurrounding

* Move surround/ to domlib

* Add jest dependency

* Make find-within return a sum type array rather than two arrays

* Use FoundMatch sum-type for find-above (and find-within)

* Fix issue where elements could be cleared twice

* if they are IN the range.endContainer

* Pass remaining test

* Add another failing test

* Fix empty text nodes being considered for surrounding

* Satisfy svelte check

* Make on more type correct

* Satisfy remaining tests

* Add missing copyright header
2021-11-18 19:18:39 +10:00
RumovZ
c1c9b6c065 Fix close button for add cards dialog (#1496) 2021-11-18 07:22:23 +10:00
Henrik Giesel
88a637251b Introduce our own Container, Row, and Col components (#1495)
* Refactor out Placeholder from CardInfo.svelte

* Add breakpoint parameter for Container

- Use `Container` component inside `TitledContainer`

* Build Item into Row

- Use Row in DeckOptionsPage instead of just Item

* Reengineer Container/Row/Col CSS

* Inline Badges next to Labels when Lable spans multiple rows

* Adjust margins for mobile

* Implement Col component breakpoints

* Move card-info to use new Container and Row components

* Join StickyHeader and StickyFooter to StickyContainer

* Remove default middle vertical-alignment for Badges again

* Satisfy tests

* Restore inline gutters in change-notetype Mapper

* Add some comment to Col and Container

* Fix breaking behavior in DeckOptionsPage when multi-column

* Add back toolbar left padding to counter-act buttongroup right margins

* Make Label in SwitchRow take more of available space
2021-11-17 13:49:52 +10:00
Abdo
eb85653f0f Load missing i18n modules (#1494) 2021-11-17 07:28:48 +10:00
RumovZ
119f8cb0b3 Smooth fuzz (#1493)
* Add separate `fuzz.rs`

* Switch to a smoother fuzz calculation
2021-11-17 07:23:19 +10:00
Abdo
100cf54f40 Add hotkey to save add-on config (#1492) 2021-11-17 07:18:48 +10:00
Damien Elmes
f925660b08 update translations 2021-11-15 16:03:31 +10:00
Damien Elmes
35c6d9585f avoid fuzzing until interval reaches 3 days
e5e47a31fe (r748827327)

+ switched assert_lower_middle_upper to a macro, so that when it fails,
the reported line number is the original call site, instead of one inside
the helper function
2021-11-15 15:48:58 +10:00
RumovZ
ec1e6b8819 Fix constrained_fuzz_bounds() (#1490)
... for cases where the entire fuzz range is above `maximum`.
Also improve hanling if the entire range is below `minimum` and
readability.
2021-11-15 15:41:43 +10:00
Damien Elmes
4855fa1182 fix a link anchor 2021-11-14 11:44:54 +10:00
Abdo
ef5b577189 Fix duplicate conflicting add-on names being shown (#1489) 2021-11-14 11:36:32 +10:00
RumovZ
87b851bde2 Add fullscreen shortcut (#1488) 2021-11-14 11:35:43 +10:00
RumovZ
120909f1d9 Make add cards dialog a main window (#1486)
Closes #980.
2021-11-14 11:33:59 +10:00
Damien Elmes
c2d9f148fd unbury when refreshing queues
While we already unbury when refreshing the deck list, if the user
resumes study on a new day without refreshing the deck list, burying
could end up being delayed.

Possible fix for https://forums.ankiweb.net/t/buried-cards-in-ankimobile-beta-20081-3/14753/3
2021-11-14 10:06:47 +10:00
Damien Elmes
4dca9a724c fix underflow in fuzz code, leading to large intervals
https://forums.ankiweb.net/t/buried-cards-in-ankimobile-beta-20081-3/14753
2021-11-14 09:17:37 +10:00
RumovZ
5c64aadb7a Garbage collect unused Fluent strings (#1482)
* Canonify import of i18n module

Should always be imported as `tr`, or `tr2` if there is a name collision
(Svelte).

* Add helper for garbage collecting ftl strings

Also add a serializer for ftl asts.

* Add helper for filter-mapping `DirEntry`s

* Fix `i18n_helpers/BUILD.bazel`

* run cargo-raze

* Refactor `garbage_collection.rs`

- Improve helper for file iterating
- Remove unused terms as well
- Fix issue with checking for nested messages by switching to a regex-
based approach (which runs before deleting)
- Some more refactorings and lint fixes

* Fix lints in `serialize.rs`

* Write json pretty and sorted

* Update `serialize.rs` and fix header

* Fix doc and remove `dbg!`

* Add binaries for ftl garbage collection

Also relax type constraints and strip debug tests.

* add rust_binary targets for i18n helpers (dae)

* add scripts to update desktop usage/garbage collect (dae)

Since we've already diverged from 2.1.49, we won't gain anything
from generating a stable json just yet. But once 2.1.50 is released,
we should run 'ftl/update-desktop-usage.sh stable'.

* add keys from AnkiMobile (dae)

* Mention caveats in `remove-unused.sh`
2021-11-12 18:19:01 +10:00
Damien Elmes
6220bdc33c fix card info layout & test code
Closes #1479

Related: #1470
2021-11-12 16:24:08 +10:00
Damien Elmes
ac23757e82 update translations 2021-11-12 15:02:17 +10:00
Damien Elmes
0637f3190b another external workspace fix for sass 2021-11-12 15:02:17 +10:00