Commit Graph

1721 Commits

Author SHA1 Message Date
BlueGreenMagick
28eae0667a
fix wrong rich-text-widget offset (#2033)
.rich-text-input { padding: 6px; }
messed up image & mathjax overlay positioning
because parent padding isn't added to absolute positioning px
2022-08-31 18:35:01 +10:00
Damien Elmes
0809812c1d Preserve background-color when pasting external content in light mode
Closes #1964
2022-08-19 12:31:26 +10:00
Matthias Metelka
5f6ac1a916
Field redesign (#2002)
* Adjust size of legacy buttons

* Revert "Adjust size of legacy buttons"

This reverts commit fb888fe1db9050c34b1a7b0820e6da5ac91ccee6.

* Remove unused function from #1476

* Use outline version for tag icon

* Add chevron icons

* Remove code icons, keep one pin icon version

* Add code-bg color

* Redesign fields

* Remove unused import

* Fix imports

* Move PlainTextBadge between editing inputs

where it belongs :)

* Make whole separator line clickable

* Fix transition

and format

* Don't show toggle when field is collapsed

* Show toggle only on hover

for mobile I'd like to implement a swipe mechanism.

* Use tweened SVG for triangle instead of CSS hack

* Implement more obvious HTML toggle on bottom right

* Reduce field height by a few pixels

* Reduce field height by two pixels

* Show HTML toggle when PlainTextInput is active, regardless of hover/focus

* Remove RichTextBadge.svelte

* Create separate collapsed field state

this means users can collapse fields with the HTML editor open and it will stay open when the field is expanded again.

* Add slide out animation to EditingArea, RichTextInput and PlainTextInput

only for collapsing, because it is choppy on expansion (common issue with Svelte transitions).

* Fix aliasing issue on focused field corners

* Make StickyBadge feel more responsive

* Move StickyBadge closer to field border

* Adjust field gutter/margins

* Make LabelContainer sticky

to make field operations accessible on fields with a lot of content.

* Add back html icons, remove visual editor icons

* Revert "Add code-bg color"

This reverts commit 4200f354193710b3acd9bcf84b67958e200ddcdb.

* Add rich text icon, remove strikethrough code icon

* Revert PlainTextBadge to original position

* Adjust margins in FieldState

* Rename PlainTextBadge to SecondaryInputBadge

in preparation for #1987

* Run eslint and prettier

* Make whole LabelContainer clickable area for collapse/expand

* Revert "Add slide out animation to EditingArea, RichTextInput and PlainTextInput"

This reverts commit 9a2b3410d0ead37ae1da408d68e14507a058a613.

* Fix error on collapse/expansion

this was caused by the {#if} blocks, which resulted in the deletion of original EditingAreas.

* Refocus when toggling chevron and secondary input badge

* Revert "Revert "Add code-bg color""

This reverts commit 1cfd3bda65354ab90c1ab4cbbef47596a1be8754.

* Use single rotating chevron icon and make it RTL-compatible

* Remove redundant CSS transition rule

* Introduce animated Collapsible component and fix refocus on toggle

* Do not try to force repaint, as it is not required

* Remove RTL store from LabelContainer

the direction is already applied globally.

* Collapse secondary input with field

* Add focusedField to NoteEditorAPI

* Replace :global CSS selector with class .visible

thus removing the assumption that the component is used inside an EditorField.

https://github.com/ankitects/anki/pull/2002#discussion_r944876448

* Use named function syntax instead of function expressions

* Add explanation comment

* Remove unnecessary :bind directive

* Create CollapseBadge component

* Move :global selector into .plain-text-input

* Add comment explaining box-shadow pseudo-element

* Move Collapsible from EditingArea, PlainTextInput and RichTextInput into user components

* Rename SecondaryInputBadge to PlainTextBadge and remove generalization logic

I kept the rich text icon inside icons.ts for future use.

* Sort imports

* Fix background-color for duplicates not showing

with yet another pseudo-element :)

The pseudo-element that covers up field borders on scroll caused this issue. Fighting fire with fire here.

* Increase size of plain text toggle to original value again

This makes the clickable area a bit bigger and looks slightly more consistent with StickyBadge.

* Scrap pseudo-element mess in LabelContainer and tackle the actual issue

* Add class .visible to StickyBadge too

This introduces a peculiar bug: The active prop of StickyBadge resets to false when the mouse leaves the field - regardless of the actual back-end value.

* Fix sticky badge resetting on mouseleave/blur

* Apply overflow: hidden only during transition

fixes MathJax handle getting cut off by fields

* Remove unused variable

* Fix visual bug caused by overflow:hidden not applying in time

I tried several asynchronous approaches, but they all caused issues: either they prevented the CSS transition or they made field inputs lose focus.

In the end I resorted to direct, synchronous DOM-manipulation and added an explanatory comment.

* Decrease Collapsible load time by blocking first transition

I noticed the sliding animation has a hefty performance impact when a large number of fields is loaded simultaneously.

Blocking the first transition (which isn't even visible) results in a big boost in load time.

* Replace usages of gap with margins for children

* Revert unnecessary removal of grid-gap definition

* Correct comments about flex-gap property

mistook that for grid-gap.

* Resolve style issues

* Add minimum targets to gap comment

Co-authored-by: Henrik Giesel <hengiesel@gmail.com>
2022-08-19 10:02:28 +10:00
Matthias Metelka
d1cbb86178
Default input setting in fields dialog (#1987)
* Introduce field setting to use plain text editor by default

* Remove leftover function from #1476

* Use boolean instead of string

* Simplify clear_other_field_duplicates

* Convert plain text key to camelCase

* Move HTML item below the existing checkbox, instead of to the right (dae)

Showing it on the right is more space efficient, but feels a bit
cluttered IMHO.
2022-08-18 12:30:18 +10:00
Damien Elmes
75723d7c9c
Add option in math dropdown to toggle MathJax rendering (#2014)
* Add option in math dropdown to toggle MathJax rendering

Closes #1942

* Hackily redraw the page when toggling MathJax

* Add Fluent string
2022-08-18 12:06:06 +10:00
Henrik Giesel
678c354fed
Fix field descriptions blocking cursor from being set (#2018)
- happens when focus is in HTML editor
2022-08-17 17:21:13 +10:00
Henrik Giesel
c7f3bae738
Last polishes for Surrounder class (#2017)
* Make private properties in Surrounder truly private

* Fix remove logic of Surrounder

* No reason for toggleTriggerRemove to be async

* Allow using alt-shift to set all remove formats but this one

* modifyFormat => updateFormat

* Fix formatting
2022-08-17 16:00:37 +10:00
Damien Elmes
4b3332bdb8 Disable auto-closing of HTML tags
https://forums.ankiweb.net/t/set-html-editor-as-a-default-editor-instead-of-visual-editor/20988/3

Closes #1963
2022-08-16 12:43:43 +10:00
Henrik Giesel
ea53c73bf2
Allow passing debug=True to jest_test for debugger support (#2013) 2022-08-16 10:55:16 +10:00
Henrik Giesel
9ca13ca3bc
Refactor how toolbar buttons get to surround within editor fields (#1931)
* Export surrounder directly from RichTextInput

* Change wording in editor/surround

* Remove empty line

* Change wording

* Fix interfaces

* Add field description directly in NoteEditor

* Strip description logic from ContentEditable

* Make RichTextInput position: relative

* Make attachToShadow an async function

* Apply field styling to field description

* Show FieldDescription only if content empty

* Remove descriptionStore and descriptionKey

* Revert "Make attachToShadow an async function"

This reverts commit b62705eadf7335c7ee0c6c8797047e1f1ccdbf44.

SvelteActionReturnType does not accept Promise<void>

* Fix mess after merge commit

* Require registering surround formats
2022-08-15 13:34:16 +10:00
RumovZ
4ea370959b
Fix flicker when remapping imported notetype field (#2005) 2022-08-08 01:01:25 +10:00
Henrik Giesel
3e28605638
Use wavy flags (flag-alternative) (#1995) 2022-08-01 20:15:22 +10:00
Damien Elmes
2e2fc799e2 Only show basename of CSV file 2022-07-23 17:53:50 +10:00
Damien Elmes
340da23104 Wrap type answer output in code tag; remove extra div
This would make more sense as a class on the outer div, but existing
templates reference code#typeans, so avoid breaking things for now.
2022-07-22 20:37:56 +10:00
Damien Elmes
f582181ea4 Upgrade Svelte for CVE 2022-07-22 20:06:45 +10:00
RumovZ
cc929687ae
Deck-specific Limits (#1955)
* Add deck-specific limits to DeckNormal

* Add deck-specific limits to schema11

* Add DeckLimitsDialog

* deck_limits_qt6.py needs to be a symlink

* Clear duplicate deck setting keys on downgrade

* Export deck limits when exporting with scheduling

* Revert "deck_limits_qt6.py needs to be a symlink"

This reverts commit 4ee7be1e10c4e8c49bb20de3bf45ac18b5e2d4f6.

* Revert "Add DeckLimitsDialog"

This reverts commit eb0e2a62d33df0b518d9204a27b09e97966ce82a.

* Add day limits to DeckNormal

* Add deck and day limits mock to deck options

* Revert "Add deck and day limits mock to deck options"

This reverts commit 0775814989e8cb486483d06727b1af266bb4513a.

* Add Tabs component for daily limits

* Add borders to tabs component

* Revert "Add borders to tabs component"

This reverts commit aaaf5538932540f944d92725c63bb04cfe97ea14.

* Implement tabbed limits properly

* Add comment to translations

* Update rslib/src/decks/limits.rs

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

* Fix camel case in clear_other_duplicates()

* day_limit → current_limit

* Also import day limits

* Remember last used day limits

* Add day limits to schema 11

* Tweak comment (dae)

* Exclude day limit in export (dae)

* Tweak tab wording (dae)

* Update preset limits on preset change

* Explain tabs in tooltip (dae)

* Omit deck and today limits if v2 is enabled

* Preserve deck limit when switching to today limit
2022-07-19 18:27:25 +10:00
RumovZ
cff04a288a
Fix card info not updating (#1957)
Update was not triggered if card id didn't change.
2022-07-12 10:34:48 +10:00
Damien Elmes
5ea78e1c8e Since DupeResolution is in CsvMetadata, we don't need to pass it separately
Follow-up to #1930
2022-06-27 17:15:54 +10:00
RumovZ
b6a7760cb4
Restore and save last dupe resolution setting (#1930)
* Restore dupe resolution setting

* Save dupe resolution setting

* Push config logic into backend (dae)
2022-06-24 15:10:06 +10:00
Matthias Metelka
e6f158e445
Fix descriptions overflowing field (#1925) 2022-06-23 13:32:07 +10:00
Henrik Giesel
c1e54e6842
Fix field description (#1923)
* Remove most of the original description placeholder implementation

* Move description showing logic to RichTextInput

- there is no need to propagate it to ContentEditable

* Remove the @html from field-description

This actually worked - however I removed it in case we'd rather offer
markdown support or something else in the future.

* Do not remove placeholder already on focus

- Other editors do not do it either

* Hide via hidden attribute instead of unmounting

* Do not pass content to ContentEditable

* Sort imports

* Change placeholder text color (dae)

In day mode, slightly-grey is almost indistinguishable from black
(at least on the monitor I'm using here)
2022-06-22 09:53:10 +10:00
RumovZ
1b8bab73d1
Csv import tweaks (#1920)
* Don't use special label for tags column

This was setting the label of whichever column the user chose for tags
to "Tags". Showing field content is more helpful.

* Map tags column automatically like fields
2022-06-22 09:44:12 +10:00
Damien Elmes
3eb8a6ce9d Pass content directly instead of its writable container 2022-06-21 12:24:00 +10:00
Damien Elmes
30c6bd58c9 Recalculate field map after delimeter changes
https://forums.ankiweb.net/t/anki-2-1-54-release-candidate/20861/8
2022-06-21 10:35:08 +10:00
Hikaru Y
bc5633e070
Fix field description not toggled properly (#1919)
It appears that a variable bound to the `innerHTML` property of
a contenteditable element is only updated when `input` event fires on
the element, and not when changes are made to the DOM programmatically.
2022-06-21 10:12:00 +10:00
Henrik Giesel
3969487e77
Join RichTextAPI and RichTextContextAPI + Expose anki/RichTextInput (#1918)
* Format scss correctly so it passes ts:format

* Use on and singleCallback in ImageHandle and MathjaxHandle

* Add a few comments

* Fix relict of partial commit

* Fix 'element not found' in ImageHandle

* Remove setting css on image handle twice

* Remove use of container in ImageHandle

* Remove use of container in MathjaxHandle

* Use unprefixed properties of RichTextInputAPI

* Inline api to get to RichTextInputAPI

* Join customStyles into RichTextInputAPI

* Export RichTextInput; Remove SetContext

* Address eslint and svelte_check
2022-06-20 16:11:27 +10:00
Henrik Giesel
336ad05693
Add EditorField export (#1915)
- This is useful when you want to set up hooks, etc. on the EditorField
  component
- Because when you can only use the NoteEditor export, you cannot notice
  when fields are mounted or destroyed
2022-06-20 12:07:07 +10:00
Henrik Giesel
ae69bb0834
Check event.key instead of event.code to detect Space in TagEditor (#1913)
* Closes #1901
2022-06-17 11:08:17 +10:00
Matthias Metelka
6d8fb35fab
Make field description a placeholder inside EditingArea (#1912)
* Move field description into EditingArea as placeholder

* Prevent insertion of breaks into empty fields

to allow :empty CSS selector to also work on fields other than the first one.

* Remove redundant setContext from EditingArea

* Fix import order

* Revert "Prevent insertion of breaks into empty fields"

This reverts commit 1615fd5cf441b1047dae6a34265acb9c5cae50b2.

* Use class:empty instead of :empty CSS pseudo-class

* Restrict description to single line, ellipse overflow

* Make description in field dialog a bit clearer
2022-06-17 11:02:30 +10:00
Abdo
1bab947c9c
Fix JS drop event not firing in the reviewer (#1906)
* Allow webviews to opt in to default D&D handling

* Remove redundant webview.js include

* Block default drag & drop behavior in reviewing screens

* Fix mypy error
2022-06-10 23:33:53 +10:00
RumovZ
6da5e5b042
CSV import/export fixes and features (#1898)
* Fix footer moving upwards

* Fix column detection

Was broken because escaped line breaks were not considered.
Also removes delimiter detection on `#columns:` line. User must use tabs
or set delimiter beforehand.

* Add CSV preview

* Parse `#tags column:`

* Optionally export deck and notetype with CSV

* Avoid clones in CSV export

* Prevent bottom of page appearing under footer (dae)

* Increase padding to 1em (dae)

With 0.5em, when a vertical scrollbar is shown, it sits right next to
the right edge of the content, making it look like there's no right
margin.

* Experimental changes to make table fit+scroll (dae)

- limit individual cells to 15em, and show ellipses when truncated
- limit total table width to body width, so that inner table is shown
with scrollbar
- use class rather than id - ids are bad practice in Svelte components,
as more than one may be displayed on a single page

* Skip importing foreign notes with filtered decks

Were implicitly imported into the default deck before.
Also some refactoring to fetch deck ids and names beforehand.

* Hide spacer below hidden field mapping

* Fix guid being replaced when updating note

* Fix dupe identity check

Canonify tags before checking if dupe is identical, but only add update
tags later if appropriate.

* Fix deck export for notes with missing card 1

* Fix note lines starting with `#`

csv crate doesn't support escaping a leading comment char. :(

* Support import/export of guids

* Strip HTML from preview rows

* Fix initially set deck if current is filtered

* Make isHtml toggle reactive

* Fix `html_to_text_line()` stripping sound names

* Tweak export option labels

* Switch to patched rust-csv fork

Fixes writing lines starting with `#`, so revert 5ece10ad05f331.

* List column options with first column field

* Fix flag for exports with HTML stripped
2022-06-09 10:28:01 +10:00
Damien Elmes
496bce229b Override older protobufjs pulled in via @bazel/typescript 2022-06-03 13:15:48 +10:00
Damien Elmes
5ae7a4e3c4 Update protobufjs due to CVE 2022-06-03 12:54:41 +10:00
Damien Elmes
f042c0b9ec Prevent protobufjs attempting to install packages at runtime 2022-06-03 12:51:34 +10:00
Damien Elmes
92e13ae0d3 Fix some layout issues in the CSV import screen
- Align headers with the settings below them
- More equally space rows
- Ensure Import button is anchored to the bottom (
caused by 9b0729970e)
2022-06-02 18:48:28 +10:00
RumovZ
42cbe42f06
Plaintext import/export (#1850)
* Add crate csv

* Add start of csv importing on backend

* Add Menomosyne serializer

* Add csv and json importing on backend

* Add plaintext importing on frontend

* Add csv metadata extraction on backend

* Add csv importing with GUI

* Fix missing dfa file in build

Added compile_data_attr, then re-ran cargo/update.py.

* Don't use doubly buffered reader in csv

* Escape HTML entities if CSV is not HTML

Also use name 'is_html' consistently.

* Use decimal number as foreign ease (like '2.5')

* ForeignCard.ivl → ForeignCard.interval

* Only allow fixed set of CSV delimiters

* Map timestamp of ForeignCard to native due time

* Don't trim CSV records

* Document use of empty strings for defaults

* Avoid creating CardGenContexts for every note

This requires CardGenContext to be generic, so it works both with an
owned and borrowed notetype.

* Show all accepted file types  in import file picker

* Add import_json_file()

* factor → ease_factor

* delimter_from_value → delimiter_from_value

* Map columns to fields, not the other way around

* Fallback to current config for csv metadata

* Add start of new import csv screen

* Temporary fix for compilation issue on Linux/Mac

* Disable jest bazel action for import-csv

Jest fails with an error code if no tests are available, but this would
not be noticable on Windows as Jest is not run there.

* Fix field mapping issue

* Revert "Temporary fix for compilation issue on Linux/Mac"

This reverts commit 21f8a261408cdae49ec031aa21a1b659c4f66d82.

* Add HtmlSwitch and move Switch to components

* Fix spacing and make selectors consistent

* Fix shortcut tooltip

* Place import button at the top with path

* Fix meta column indices

* Remove NotetypeForString

* Fix queue and type of foreign cards

* Support different dupe resolution strategies

* Allow dupe resolution selection when importing CSV

* Test import of unnormalized text

Close  #1863.

* Fix logging of foreign notes

* Implement CSV exports

* Use db_scalar() in notes_table_len()

* Rework CSV metadata

- Notetypes and decks are either defined by a global id or by a column.
- If a notetype id is provided, its field map must also be specified.
- If a notetype column is provided, fields are now mapped by index
instead of name at import time. So the first non-meta column is used for
the first field of every note, regardless of notetype. This makes
importing easier and should improve compatiblity with files without a
notetype column.
- Ensure first field can be mapped to a column.
- Meta columns must be defined as `#[meta name]:[column index]` instead
of in the `#columns` tag.
- Column labels contain the raw names defined by the file and must be
prettified by the frontend.

* Adjust frontend to new backend column mapping

* Add force flags for is_html and delimiter

* Detect if CSV is HTML by field content

* Update dupe resolution labels

* Simplify selectors

* Fix coalescence of oneofs in TS

* Disable meta columns from selection

Plus a lot of refactoring.

* Make import button stick to the bottom

* Write delimiter and html flag into csv

* Refetch field map after notetype change

* Fix log labels for csv import

* Log notes whose deck/notetype was missing

* Fix hiding of empty log queues

* Implement adding tags to all notes of a csv

* Fix dupe resolution not being set in log

* Implement adding tags to updated notes of a csv

* Check first note field is not empty

* Temporary fix for build on Linux/Mac

* Fix inverted html check (dae)

* Remove unused ftl string

* Delimiter → Separator

* Remove commented-out line

* Don't accept .json files

* Tweak tag ftl strings

* Remove redundant blur call

* Strip sound and add spaces in csv export

* Export HTML by default

* Fix unset deck in Mnemosyne import

Also accept both numbers and strings for notetypes and decks in JSON.

* Make DupeResolution::Update the default

* Fix missing dot in extension

* Make column indices 1-based

* Remove StickContainer from TagEditor

Fixes line breaking, border and z index on ImportCsvPage.

* Assign different key combos to tag editors

* Log all updated duplicates

Add a log field for the true number of found notes.

* Show identical notes as skipped

* Split tag-editor into separate ts module (dae)

* Add progress for CSV export

* Add progress for text import

* Tidy-ups after tag-editor split (dae)

- import-csv no longer depends on editor
- remove some commented lines
2022-06-01 20:26:16 +10:00
Damien Elmes
96bacf792c Increase limit on easy multiplier
https://forums.ankiweb.net/t/limited-easy-bonus/20044
2022-05-26 12:51:51 +10:00
wisherhxl
5e1b67bcbc
Fix ibus first keystroke goes two (#1886)
Calling `moveCaretToEnd()` when `richText` is empty will cause the first keystroke of
ibus-based input methods with candidates to goes double. For example, if you
type "a" it becomes "aa". This problem exists in many linux distributions.
When `richText` is empty, there is no need to place the caret, just return
as a workaround.
2022-05-26 10:47:55 +10:00
Damien Elmes
9b0729970e Fix deck options sticky bar at top disappearing on scroll
Issue was introduced in 7922f18296
when the styling was moved into base.scss. From what I can tell, there
are two locations where the current styling is required:

- the editor, to ensure the tags are shown at the bottom
- the change notetype screen, which requires this styling for a sticky
bar at top

I'm no CSS guru, so if someone thinks this could be solved in a better
way, please submit a follow-up PR.

Closes #1782
2022-05-23 16:10:45 +10:00
Henrik Giesel
7a77a8f2f9
Add getNoteId to exports (#1884) 2022-05-23 09:14:36 +10:00
Damien Elmes
ae18ba2a05 Switch editor to full MathJax package to fix broken autoloads
Re: https://forums.ankiweb.net/t/anki-2-1-53-release-candidate/20122/2

Autoloads in MathJax are asynchronous, and the caller is expected to
use asynchronous APIs when they are in use [1]. The editor uses the synchronous
tex2svg(), which throws a "MathJax retry" error when an autoload package
has not yet loaded. Attempting to use the package before it has loaded
appears to break future invocations as well, so the package fails to work
at all until a new webview is created.

The following HTML will reproduce the issue when added to a single card
in a new profile:

```
<strong>6&nbsp; &nbsp;&nbsp;</strong>Every combination of <anki-mathjax>\boldsymbol{v}=(1,-2,1)</anki-mathjax> and <anki-mathjax>\boldsymbol{w}=(0,1,-1)</anki-mathjax> has components that add to&nbsp; _____.<br>
```

Ideally we'd switch the MathJax rendering to be asynchronous, but that
didn't work well when I tried it in #1862. For now I've just switched
to the full package, which adds about 130KB to the final minified JS
(2.76MB), and likely slows down editor loading somewhat.

[1] https://github.com/mathjax/MathJax/issues/2557#issuecomment-727655089
2022-05-21 14:01:38 +10:00
Damien Elmes
8b1afc7e3a Reveal cloze answers in MathJax preview
Closes #1862
2022-05-19 12:48:12 +10:00
BlueGreenMagick
6ddbf7bc10
Fix graphs tooltip incorrect position (#1872) 2022-05-19 11:08:57 +10:00
Henrik Giesel
dba12e8cb3
Allow style tags in HTML editor (#1870) 2022-05-17 16:37:20 +10:00
Damien Elmes
a451fec5a1 Fix new card positions being included in future due graph
Introduced in f60de39015

https://forums.ankiweb.net/t/anki-2-1-52-qt6-stats-bug-future-due-backlog/20016
2022-05-16 15:14:15 +10:00
Henrik Giesel
826e135510
Update Svelte to 3.48.0 (#1867) 2022-05-16 14:47:38 +10:00
Henrik Giesel
1b18005d6e
Transform <br> in Mathjax to newlines (#1866)
* Transform <br> in Mathjax to newlines

* Add missing quantifier
2022-05-16 14:42:10 +10:00
Damien Elmes
a070bec03c Allow alt tags when pasting images
https://forums.ankiweb.net/t/do-not-strip-alt-attribute-when-pasting-images-from-the-web/20007
2022-05-16 14:32:24 +10:00
Henrik Giesel
3b8aa97396
Use same config for editor and reviewer Mathjax (#1865)
* Remove custom config and use tex-chtml-full for editor Mathjax

* Add mathjax package in /ts

* Share mathjax config between tex-svg and tex-chtml

* Use "[+]" in Mathjax config again

* Remove mention of MathJaxReady

* Satisfy eslint
2022-05-13 13:23:35 +10:00
Henrik Giesel
b6fb64fde1
Implement cloze buttons in Mathjax editor (#1860)
* Introduce RichTextClozeButtons

* Implement cloze buttons in Mathjax editor
2022-05-13 13:04:20 +10:00
Henrik Giesel
52438fe4c9
Move focus into HTML editor when shown (#1861)
* Move focus into input field, when input is shown

* Change trapFocusOut to move focus into available inputs

- This means that e.g. closing the HTML editor with focus in it will
  focus the visual editor in turn

* Prevent Control+A unselecting tag editor when no tags exist
2022-05-13 13:02:03 +10:00
Henrik Giesel
de2cc20c59
Change how resizable images work (#1859)
* Add ResizableImage.svelte in ts/editable

* Set image constrained via attributes instead of managed style sheet

* Implement new constrained size method

* Turn WithImageConstrained.svelte into normal ts file

* Introduce removeStyleProperties

Removes "style" attribute if all style properties were cleared

* Avoid --editor-width and use one variable set on container

* Disable shrinking if already smaller than shrunken size

* Add button to restore image to original size

* Don't allow restoring original size if no custom width set

* Bottom-center HandleLabel

* Satisfy svelte-check
2022-05-13 12:57:07 +10:00
BlueGreenMagick
fb5521eeed
remove image.style.height on resize (#1856) 2022-05-11 10:06:34 +10:00
Henrik Giesel
89530c5f24
Change sequence of Mathjax escaping (#1854) 2022-05-10 11:54:06 +10:00
Henrik Giesel
6043d2f5a2
Set editor size to 1.6 on Windows as well (#1853) 2022-05-10 11:48:11 +10:00
Henrik Giesel
96d9539b9d
Fix activeName updating wrongly when selecting previous tag from invalid tag (#1851) 2022-05-10 11:45:41 +10:00
BlueGreenMagick
68482d37a1
select all tags with Ctrl+A (#1847) 2022-05-10 11:39:54 +10:00
BlueGreenMagick
9d98c62d50
Fix when tooltip changes before tooltipObject is created (#1845)
It can happen in TagWithTooltip.svelte
when a tag is normalized beause of leading/trailing delimiter
2022-05-10 11:36:54 +10:00
BlueGreenMagick
fc8b976ca8
fix typo. Shortcut uses on:action not on:click (#1846) 2022-05-09 19:55:35 +10:00
BlueGreenMagick
faa21266db
Fix caret jumping to start when unselecting autocomplete suggestion (#1844) 2022-05-09 11:15:56 +10:00
BlueGreenMagick
cc374996cc
align tag icon and text (#1843) 2022-05-09 11:15:44 +10:00
Henrik Giesel
1ec227d926
Make TagAddButton focusable and simulate click on focus (#1838) 2022-05-07 09:15:58 +10:00
Damien Elmes
bc6ede7c11 Fix &amp; showing up in MathJax
https://forums.ankiweb.net/t/anki-2-1-52-release-candidate/19412/22

Accidentally introduced in #1818
2022-05-03 14:21:31 +10:00
Damien Elmes
6f0d86b9a9 Cap tag matches to 10 on macOS/Qt5 to work around Chromium perf issue
Closes #1825
2022-04-27 19:23:07 +10:00
Damien Elmes
f60de39015 Fix due graph showing wrong date for review cards with resched off
Since we are using the original due date instead of the current one,
the learning check needs to be based on the card type, not its current
queue.

https://forums.ankiweb.net/t/anki-2-1-51-release-candidate/18942/22
2022-04-25 14:14:08 +10:00
Henrik Giesel
b8eabfd622
Remove onInput call in input handler (#1819)
This was implemented by me to prevent seemingly empty fields,
which however still contain some HTML (e.g. <div></div>) and
thus will trigger in the templates.
However it only worked in very limited cases, maybe we could
solve this better by indicating whether a field has content somehow.
2022-04-25 13:56:05 +10:00
Henrik Giesel
2be1f4c56d
Instead of transforming to {\lt}, transform to &lt; (#1818)
* Instead of transforming to {\lt}, transform to &lt;

- In Mathjax editor
- This way you can also use Mathjax convenience shortcuts like <=> in
  chemistry mode: \ce{<=>}

* Remove unused translateEntitiesToMathjax() (dae)

https://github.com/ankitects/anki/pull/1818#discussion_r857238310
2022-04-25 13:42:54 +10:00
Matthias Metelka
2b739d76b2
Align list items to start (#1816) 2022-04-22 14:18:11 +10:00
Matthias Metelka
770fabd51b
Remove unnecessary night mode rule for typeans (#1815)
which caused https://forums.ankiweb.net/t/shaddow-below-cloze-type-area-in-night-mode/19287/2
2022-04-22 14:17:43 +10:00
Henrik Giesel
cf78a555c6
Add some component comment (#1779)
* Add a component comment for NoteEditor

* Move comments above component template

* EditorField -> EditingArea
2022-04-19 17:20:26 +10:00
Damien Elmes
adbe96ca00
Load page script after body created (#1802)
document.body must exist by the time the top level Svelte component
initializes.

https://forums.ankiweb.net/t/2-1-50-editor-wont-show-when-addons-load-many-js-files/19036
2022-04-19 17:16:56 +10:00
Damien Elmes
856d4763a9 Switch strong/em back to b/i
In the absence of strong arguments either way, and given the fact that
strong/em has broken a few (perhaps rare) use-cases, reverting seems
prudent. But happy to revisit this again in the future if someone has
a convincing argument for why we should be doing it differently.

Closes #1807
2022-04-19 16:28:44 +10:00
Henrik Giesel
6017214042
Fix resetting of formatting modes when pressing modifer or dead keys (#1811)
* Fix shift removing bold formatting

* Remove input handler on selection change

We listened to "non-input events" mostly to catch events that
change the selection (like Ctrl-a, or arrow keys) anyway
2022-04-19 16:08:32 +10:00
Damien Elmes
a9769813ba Add back support for custom mountpoint in card stats
The move to separate .html files broke our legacy card stats routine.

Related: d1d71ffdbb
2022-04-15 15:30:05 +10:00
Henrik Giesel
f3f5a42218
Speed up editor by lazily loading CodeMirror - Second try (#1776)
* Revert "Revert "Speed up editor by lazily loading CodeMirror (#1766)""

This reverts commit b0a2884f19.

* Pass in options via action update + Make access to editor optional
2022-04-09 13:25:54 +10:00
Abdo
964f0a5763
Add relative overdueness to review order (#1757)
* Add relative overdueness to review order

* Add test for relative overdue
2022-04-09 13:20:09 +10:00
Damien Elmes
b0a2884f19 Revert "Speed up editor by lazily loading CodeMirror (#1766)"
This reverts commit 0db921dd39.

This caused a regression that needs looking into:
https://github.com/ankitects/anki/issues/1775
2022-04-06 11:08:32 +10:00
Damien Elmes
1a55942ffa Fix invisible tag input in Qt5 (thanks to Hikaru)
Closes #1768
2022-04-05 09:53:36 +10:00
Henrik Giesel
0db921dd39
Speed up editor by lazily loading CodeMirror (#1766) 2022-04-03 19:00:20 +10:00
Henrik Giesel
7bfd7245e0
Fix HighlightColorButton setting last text color (#1765) 2022-04-02 14:58:32 +10:00
Henrik Giesel
67c1f7368e
Set caret inside chemical expression in Mathjax (#1763) 2022-03-31 23:39:49 +10:00
Damien Elmes
6df63f8643 Tweak cloze deletion labels 2022-03-31 14:47:51 +10:00
Henrik Giesel
5b1fcccf33
Add extra button group for cloze commands (#1756)
* First attempt at adding a directory for icons under //ts

* Fix image import

* Fix import order

* Add cloze button group

* Fix issue with toolbar.toolbar dynamically slottable

* Change tooltip for repeating cloze deletion

* Fix repeat cloze button not working on macOS (dae)
2022-03-31 13:30:00 +10:00
Henrik Giesel
7f737b60c6
Fix infinite update loop in editor with invalid input HTML (#1761)
* Use async function in PlainTextInput

* Clean up PlainTextInput

* Refactor logic from {Rich,Plain}TextInput into own files

* Remove prohibited tags on content.subscribe which also parses the html
2022-03-31 11:17:13 +10:00
Damien Elmes
f0dc6e103f Fix "repeat cloze" shortcut regression
Closes #1748 again.
2022-03-30 14:52:16 +10:00
Damien Elmes
91ca5090aa Don't attempt to localize numbers in SpinBoxFloat
Issue report: 
https://forums.ankiweb.net/t/anki-2-1-50-beta-6-release-candidate/18181/71

Localization was added in #1566. It works fine in the Qt5 build, but
the Qt6 build appears broken. This appears to be a change in Chromium,
and the latest Chrome has the same issue. Whether it's a legitimate bug
on their end, a deliberate change in behaviour, or we're doing something
wrong, I do not know.
2022-03-29 14:45:18 +10:00
Henrik Giesel
7977a0dc1f
Allow using keyup with registerShortcut (#1755) 2022-03-29 09:28:44 +10:00
Damien Elmes
5dab7ed47e Use original due date for learning cards as well in the future due graph
Closes #1735
2022-03-25 08:39:52 +10:00
Henrik Giesel
bf20353b53
Add tooltip that you can double-click image for restoring its size (#1738)
* Add tooltip that you can double-click image for restoring its size

* Update ftl/core/editing.ftl

Lower case label
2022-03-24 19:53:57 +10:00
Henrik Giesel
9029c5f497
Fix cursor sometimes not being moved into mathjax editor (#1737) 2022-03-24 18:29:30 +10:00
Damien Elmes
7ab79aad8b
Update ts deps for minimist issue (#1739)
Presumably not an issue for our use case, but this removes the warning
from GitHub.

ef88b9325f
2022-03-24 10:24:56 +10:00
Henrik Giesel
2d00b6659f
Fix add-on usages of addMedia (#1721)
* Expose old .addMedia again, and use a new resolve_media for built-in uses

* Add an explaining comment for addMedia

* Add some docstrings (dae)
2022-03-16 10:29:06 +10:00
Bruce Harris
d7a101827a
Extend maximum answer time... (#1698)
* Extend maximum answer time...

Previously the time allowed to answer a question was capped at 10 minutes.
While this makes sense for fact recall, it limits the utility of Anki when
used for solving problems that can take more time to work through. This
extends the maximum answer time to 2 hours, which seems to be a reasonable
upper limit for solving a math or algorithm question.

* Add warning when max answer time exceeds 10 minutes

* Move warning below input field
2022-03-15 10:06:45 +10:00
Henrik Giesel
1ec3741934
Fix outstanding tag editor issues (#1717)
* Start using WithFloating for SelectedTagBadge

* Adjust arrow on WithFloating for all directions

* Move TagOptionsBadge to its own sub directory

* Show autocomplete menu via WithFloating

* Have WithFloating return asReference instead of initializing its own reference element

* Add html: overflow: hidden for editor

* Replace ButtonToolbar with generic div

* Move scroll logic into autocomplete item + restrict Popover width to 95vw

* Fix autocomplete menu after pressing enter after selecting

- should not trigger an autocomplete choose

* Overlap TagInput perfectly with Tag

* Satisfy formatter

* Fix autocompletion item scrolling too much

* Remove unused Tag.svelte focusable prop

* Remove console.log

* Fix floating arrow is a diamond in dark mode

* Set autocompletion menu to 80vw
2022-03-11 15:48:49 +10:00
Henrik Giesel
76bdfb3899
Add a flag to allow loading the fields dialog in a web view (#1706)
* Load fields_web from fields.py if appropriate flag is set

* Add FieldsPage as entry for new fields view

* Pass mypy

* Fix pylint

* Fix fields_web in Qt5 (dae)

May not be related to the CI error, but required for compatibility
with Qt5.
2022-03-03 22:45:26 +10:00
Henrik Giesel
29d17a84fc
Fix newline shortcut in MathjaxMenu (#1705) 2022-03-03 18:55:07 +10:00
Henrik Giesel
88217c5e7d
Replace (some) Bootstrap dropdowns with Floating UI (#1695)
* Implement a first version of WithFloating and Portal

* Add outside slot for Portal

* Execute computePosition from WithFloating

* Set up a first example of new WithFloating with the Latex menu

* Use autoUpdate in WithFloating

* Create sveltelib/position

* Add event-store

* Use event-store in close-on-click

* Implement subscribeToUpdates

* Introduce sass/elevation

* Split close-on-click to closing-click and subscribe-trigger

* Have closing-* stores return a symbol

- This way they act more of an EventEmitter than a store

* Allow passing show store

* Remove styling on float on updatePosition removal

* Implement a nice border for dropdowns

* Apply different border and box-shadow to Popover in dark/light theme

* Fix Ctrl+Shift+T not working

* Satisfy formatters and tests

* Add copyright header

* move copyright header to top (dae)
2022-03-02 14:21:19 +10:00
Henrik Giesel
92bf23df99
Use async functions in .svelte files (#1693)
* Use async functions in CodeMirror.svelte

* Fix using async functions by modifying svelte-preprocess output

* Revert "Fix using async functions by modifying svelte-preprocess output"

This reverts commit 94c9cadaaa3ca2084780833e9efc7807f2f1d1a9.

Trying a different fix.

* Change TypeScript target to ES2019
2022-02-27 22:35:47 +10:00
Damien Elmes
6941bccde4 Add support for proto3 optional scalars
Protobuf 3.15 introduced support for marking scalar fields like
uint32 as optional, and all of our tooling appears to support it
now. This allows us to use simple optional/null checks in our Rust/
TypeScript code, without having to resort to an inner message.

I had to apply a minor patch to protobufjs to get this working with
the json-module output; this has also been submitted upstream:
https://github.com/protobufjs/protobuf.js/pull/1693

I've modified CardStatsResponse as an example of the new syntax.

One thing to note: while the Rust and TypeScript bindings use optional/
null fields, as that is the norm in those languages, Google's Python
bindings are not very Pythonic. Referencing an optional field that is
missing will yield the default value, and a separate HasField() call
is required, eg:

```
>>> from anki.stats_pb2 import CardStatsResponse as R
... msg = R.FromString(b"")
... print(msg.first_review)
... print(msg.HasField("first_review"))
0
False
```
2022-02-27 19:42:06 +10:00
Henrik Giesel
55c64e5b54
Fix Mathjax sometimes being deleted even though it's not selected (#1696)
* Fix frame element being deleted, when a frame handle is deleted from while selected

* Fix mixing up preceding/following
2022-02-27 17:58:01 +10:00
Henrik Giesel
5963791d85
Consider using --force-message for ts/protobuf.bzl (#1694)
* Use --force-message in ts/protobuf

* Remove some now unnecessary type assertions in deck-options/lib

* Satisfy formatter
2022-02-27 17:35:07 +10:00
Damien Elmes
625d8596a4 Update to Jest 28 alpha
https://github.com/ankitects/anki/pull/1682
2022-02-25 16:20:50 +10:00
Damien Elmes
902f125954 Update rules_nodejs 2022-02-25 16:19:26 +10:00
Damien Elmes
f3b0c31354 Update JS deps 2022-02-25 15:29:49 +10:00
Henrik Giesel
50e36bc312
Fix plain text (#1689)
* Move remove-prohibited-tags logic from PlainTextInput

* Make CodeMirror export a promise

* Offer lifecycle hooks for PlainTextInput for easily accessing code mirror instance

* Fix </> breaking Mathjax

* remove debug statement (dae)
2022-02-25 11:14:26 +10:00
Henrik Giesel
7c27159149
Fix setting of caret when creating clozes (#1688) 2022-02-25 11:07:44 +10:00
Henrik Giesel
0d83581ab0
Fix insert media always insert at the start (on Windows) (#1684)
* Move Trigger into its own file

* Try implement HandlerList

* Implement new input handler and handler-list

* Use new refocus HandlerList in TextColorButton

* Fix TextColorButton on windows

* Move ColorPicker to editor-toolbar

* Change trigger behavior of overwriteSurround

* Fix mathjax-overlay flushCaret

* Insert image via bridgeCommand return value

* Fix invoking color picker with F8

* Have remove format work even when collapsed

* Satisfy formatter

* Insert media via callback resolved from python

* Replace print with web.eval

* Fix python formatting

* remove unused function (dae)
2022-02-25 10:59:06 +10:00
Damien Elmes
1a3eef505f interday sibling burying is only valid in v3 2022-02-23 14:33:52 +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
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
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
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
Damien Elmes
c41e455554 fix reviewer_extras 2022-02-14 18:46:50 +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
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
Henrik Giesel
0c81bbce04
Fix field not restored if active (#1639)
* Fix field not being restored after Undo, if field also has focus

* Execute moveCaretToEnd after undoing a change

- Otherwise the caret might be placed in seemingly random positions

* Fix wording of comments

* Remove autofocus functionality of EditingArea

- instead await a tick in focusField
- We used the autofocus prop for the initial focus setting when opening the
  editor. However it seems that awaiting tick in focusField also does the trick.
2022-02-05 15:58:31 +10:00
Henrik Giesel
c5280cd056
Fix CodeMirror retaining history of unrelated notes (#1640) 2022-02-04 18:40:50 +10:00
Henrik Giesel
30bbbaf00b
Use eslint for sorting our imports (#1637)
* Make eslint sort our imports

* fix missing deps in eslint rule (dae)

Caught on Linux due to the stricter sandboxing

* Remove exports-last eslint rule (for now?)

* Adjust browserslist settings

- We use ResizeObserver which is not supported in browsers like KaiOS,
  Baidu or Android UC

* Raise minimum iOS version 13.4

- It's the first version that supports ResizeObserver

* Apply new eslint rules to sort imports
2022-02-04 18:36:34 +10:00
Damien Elmes
83baa946dd fix mojibake on congrats screen
a8d4774cdb (commitcomment-65963462)
2022-02-04 18:25:40 +10:00
Henrik Giesel
a981e56008
Improved add-on extension API (#1626)
* Add componentHook functionality

* Register package NoteEditor

* Rename OldEditorAdapter to NoteEditor

* Expose instances in component-hook as well

* Rename NoteTypeButtons to NotetypeButtons

* Move PreviewButton initialization to BrowserEditor.svelte

* Remove focusInRichText

- Same thing can be done by inspecting activeInput

* Satisfy formatter

* Fix remaining rebase issues

* Add .bazel to .prettierignore

* Rename currentField and activeInput to focused{Field,Input}

* Move identifier to lib and registration to sveltelib

* Fix Dynamic component insertion

* Simplify editingInputIsRichText

* Give extra warning in svelte/svelte.ts

- This was caused by doing a rename of a files, that only differed in
  case: NoteTypeButtons.svelte to NotetypeButtons.svelte
- It was quite tough to figure out, and this console.log might make it
  easier if it ever happens again

* Change signature of contextProperty

* Add ts/typings for add-on definition files

* Add Anki types in typings/common/index.d.ts

* Export without .svelte suffix

It conflicts with how Svelte types its packages

* Fix left over .svelte import from editor.py

* Rename NoteTypeButtons to unrelated to ensure case-only rename

* Rename back to NotetypeButtons.svelte

* Remove unused component-hook.ts, Fix typing in lifecycle-hooks

* Merge runtime-require and register-package into one file

+ Give some preliminary types to require

* Rename uiDidLoad to loaded

* Fix eslint / svelte-check

* Rename context imports to noteEditorContext

* Fix import name mismatch

- I wonder why these issues are not caught by svelte-check?

* Rename two missed usages of uiDidLoad

* Fix ButtonDropdown from having wrong border-radius

* Uniformly rename libraries to packages

- I don't have a strong opinion on whether to name them libraries or
  packages, I just think we should have a uniform name.
- JS/TS only uses the terms "module" and "namespace", however `package`
  is a reserved keyword for future use, whereas `library` is not.

* Refactor registration.ts into dynamic-slotting

- This is part of an effort to refactor the dynamic slotting (extending
  buttons) functionality out of components like ButtonGroup.

* Remove dynamically-slottable logic from ButtonToolbar

* Use DynamicallySlottable in editor-toolbar

* Fix no border radius on indentation button dropdown

* Fix AddonButtons

* Remove Item/ButtonGroupItem in deck-options, where it's not necessary

* Remove unnecessary uses of Item and ButtonGroupItem

* Fix remaining tests

* Fix relative imports

* Revert change return value of remapBinToSrcDir to ./bazel/out...

* Remove typings directory

* Adjust comments for dynamic-slottings
2022-02-03 14:52:11 +10:00
Hikaru Y
7501ff7ab5
Fix field content overflowing its container (#1618) 2022-01-25 10:35:13 +10:00
Henrik Giesel
f534dbb8e5
Separate input components into their own directories / Remove WithShortcut (#1613)
* Put PlainTextInput into its own directory

* Create a directory for RichTextInput

* Create editor-toolbar directory

* Move PreviewButton into editor-toolbar

* The time to refactor this is not quite yet here

* Create tag-editor directory

* Remove some of the uses of WithShortcut

* Remove all uses of WithShortcut from editor package

* Remove last uses of WithShortcut

* Fix typo
2022-01-24 11:43:09 +10:00
Damien Elmes
f842ab7c9d switch convenience symlinks to .bazel/
Unfortunately 5efaf5a4be broke the Svelte
language tools - presumably having paths outside of the repo is confusing
them.

As a plan B, the symlinks have been shifted to a single subdir. Along
with some exclusions in the VS Code config, this should allow VS Code
to continue to work out of the box, but the docs will need updating
to reflect the extra work required for PyCharm/IntelliJ.

+ fix svelte-check execution on a system without node installed. It
still throws up some errors that are presumably caused by our multiple
rootDirs - not sure if there's an easy way to work around that.
2022-01-24 11:06:02 +10:00
Damien Elmes
e986304592 replace some bazel-bin references in our scripts
+ fix scripts/mypy-watch, and make it only listen to change events
2022-01-23 20:17:08 +10:00
Henrik Giesel
a8d4774cdb
Add _raw methods for all methods in the backend (#1594)
* Add _bytes methods for all methods in the backend

Expose get_note in qt/aqt/mediasrv.py

* Satisfy formatter

* Rename _bytes function to _raw and have them bytes as input

* Fix backend generation

* Use lib/proto/deckOptions in deck-options

* Add exposed_backend to qt/aqt/mediasrv.py

* Move some more backend methods to exposed_backend_list

* Use protobufjs for congrats and i18n

* Use protobufjs for completeTag

* Use protobufjs services in change-notetype

* Reorder post handlers in alphabetical manner

* Satisfy tests

* Remove unused collection methods

* Rename access_backend to raw_backend_request

* Use _vendor.stringcase instead of creating a new function

* Remove SKIP_UNROLL_OUTPUT

* Directly call _run_command in non _raw methods

* Remove TranslateString, ChangeNotetype and CompleteTag from SKIP_UNROLL_INPUT

* Remove UpdateDeckConfigs from SKIP_UNROLL_INPUT

* Remove ChangeNotetype from SKIP_UNROLL_INPUT

* Remove SKIP_UNROLL_INPUT

* Fix typing issue with translate_string

- Adds typing support for Protobuf maps in genbackend.py

* Do not emit convenience method for protobuf TranslateString
2022-01-21 21:32:39 +10:00
Henrik Giesel
f90895995f
Fix the caret flushing behavior when moving out of a Mathjax element (#1605)
* Fix the caret flushing behavior when moving out of a Mathjax element

* Fix typing issue and add docs for ContentEditableAPI
2022-01-19 10:17:53 +10:00
Henrik Giesel
0bb04e2951
Fix bug when selecting text next to frame by clicking three times (#1604) 2022-01-19 10:15:53 +10:00
RumovZ
0e06a1c679
Webview margins (#1583)
* Improve side margins in card info screen

* Improve top margin in deck options screen

* Hide revlog time of day on narrow screens

* Remove monospace for now (dae)
2022-01-17 15:04:25 +10:00
Henrik Giesel
478b3a53f1
Remove individual .html files + other refactorings (#1588)
* Move some AddCards specific code to NoteCreator.svelte

* Add new strings for Toggling the Visual / HTML editor

* Set LabelContainer vertical-align to text-top

- Makes them look more centered

* Remove appendInParentheses helper

* Make all ts/*.html files include only module.js and module.css

* Move any JS from .html to index files

* Remove .html files from ts modules

* Remove Python with Starlark implemenation

* Remove reference to non-existing file

* Remove deck-option.html as well

* fix change-notetype screen (dae)
2022-01-16 15:05:35 +10:00
Damien Elmes
e3bfc86f50 update JS deps
- fixes warnings about security issues in marked/markdown-it
- jsdoc is mostly unmaintained at this point, and we need to override
its dependencies manually
- typescript is still pinned
2022-01-16 13:29:48 +10:00
Damien Elmes
ce049ec360 sass/codemirror does not appear to be used 2022-01-15 21:19:58 +10:00
Damien Elmes
15358ac4e8 copy_bootstrap_css/icons were unused 2022-01-15 20:35:11 +10:00
Henrik Giesel
3beea5e1e4
Split/Merge editor.py for its three use cases (#1581)
* Forbid inserting object and iframe tags via PlainTextInput

* Add optional browserMode parameter to Editor

* Create new ts modules for three editor instances

- note-creator for AddCards
- browser-editor for the editor in the Browser
- reviewer-editor for the EditCurrent

* Revert "Forbid inserting object and iframe tags via PlainTextInput"

This reverts commit ab90ae8194494d883a1863126496e2d8f332509e.

* Refactor browserMode to editorMode

* Move new editor variants inside /ts/editor directory

* Fix typo
2022-01-12 14:51:43 +10:00
Henrik Giesel
489eadb352
Fix IME input after tab (#1584)
* Avoid initial call of mirror-dom

* Disable updateFocus from OldEditorAdapter

* fixes IME input duplication bug

* Fix saving of latestLocation for ContentEditable

* Fix IME after calling placeCaretAfterContent

* Export other libraries from domlib/index.ts

* Remove dead code

+ Uncomment code which was mistakenly left commmented
2022-01-12 08:39:41 +10:00
Ryan
ead75f2898
Calendar graph uses consistent colors across years (#1585) 2022-01-11 16:26:26 +10:00
Henrik Giesel
4360fd16fb
Use default colors for CodeMirror in light theme Anki (#1578)
Refactor PlainTextInput

Put CodeMirror themes into variables
2022-01-10 12:51:50 +10:00
RumovZ
1cee864875
Fix padding and alignment inside revlog table (#1576)
* Use nested tables in revlog

This allows for centered rows, while still preserving internal
alignment.

* Fix hidden columns

* Replace inner tables with flexbox divs

* Replace revlog table with flexbox divs

* Replace flex-gap in revlog

Unsupported on iOS and Qt5.
2022-01-10 12:50:48 +10:00
Henrik Giesel
81cc5a0914
Small Tag editor fixes (#1580)
* Adjust height of TagInputs to not switch when changing mode

* Hide scrollbar on tag suggestions when not necessary
2022-01-08 11:48:17 +10:00
Henrik Giesel
7e5b6aba4a
Reset .style.width when resizing images (#1579) 2022-01-08 11:47:12 +10:00
Henrik Giesel
739e286b0b
Fix some Mathjax issues (#1547)
* Move move-nodes logic into domlib

Refactor input-manager

Refactor out FocusTrap from EditingArea

Remove unnecessary selecting of node from surround

Add onInput interface to input-manager

Create MathjaxElement.svelte

- This should contain all the setup necessary for displaying
  <anki-mathjax> elements in the rich text input
- Does not contain setup necessary for Mathjax Overlay

Deal with backwards deletion, when caret inside anki-mathjax

Set mathjax elements contenteditable=false

Do not undecorate mathjaxx element on disconnect

- Fixes issues, where Mathjax might undecorate when it is moved into a
  different div

Add framed element custom element

Introduce iterateActions to allow global hooks for RichTextInput

Remove some old code

Deal with deletion of frame handles

Make Anki frame and frame handles restore each other

Make FrameElement restore its structure upon modification

Frame and strip off framing from MathjaxElement automatically

Move FrameHandle to separate FrameStart/FrameEnd

Refactor FrameHandle

Set data-frames on FrameElement

Fix logic error connected to FrameElement

Communicate frameHandle move{in,out} to anki-mathjax

Clear selection when blurring ContentEditable

Make sure frame is destroyed when undecorating Mathjax

Use Hairline space instead of zeroWidth

- it has better behavior in the contenteditable when placing the caret
  via clicking

Allow detection of block elements with `block` attribute

- This way, anki-mathjax block="true" will make field a
field be recognized to have block content

Make block frame element operater without handles

- Clicking on the left/right side of a block mathjax will insert a br
  element to that side

When deleting, remove mathajax-element not just image

Update MathjaxButtons to correctly show block state

SelectAll when moving into inline anki mathjax

Remove CodeMirror autofocus functionality

Move it to Mathjaxeditor directly

Fix getRangeAt throwing error

Update older code to use cross-browser

Fix issue with FrameHandles not being properyly removed

Satisfy formatting

Use === instead of node.isSameNode()

Fix issue of focusTrap not initialized

* Fix after rebasing

* Fix focus not being moved to first field

* Add documentation for input-manager and iterate-actions

* Export logic of ContentEditable to content-editable

* Fix issue with inserting newline right next to inline Mathjax

* Fix reframing issue of Mathjax Svelte component

* Allow for deletion of Inline Mathjax again

* Rename iterate-actions to action-list

* Add copyright header

* Split off frame-handle from frame-element

* Add some comments for framing process

* Add mising return types
2022-01-08 11:46:01 +10:00
Damien Elmes
a6c65efd36 another attempt at enforcing script load order
See discussion on 36e20fd110 (commitcomment-62861929)
2022-01-07 14:23:55 +10:00
Damien Elmes
349d5d0862 Revert "Guarantee execution order of <script> elements (#1574)"
This reverts commit 36e20fd110.

Reverting until this can be investigated:

36e20fd110 (commitcomment-62861929)
2022-01-04 10:43:56 +10:00
Hikaru Y
36e20fd110
Guarantee execution order of <script> elements (#1574) 2022-01-04 08:58:09 +10:00
Vova Selin
2df3698e8c
Minor changes to graphs (#1566)
* Add thousands comma separator for card counts graph

* Fix Answer Buttons graph's tooltip

Changes to the "times pressed" heading

* Shows the percent of that button out of all the presses

* Comma separates total on thousands

* Update CONTRIBUTERS

* Wider spacing for graph tables

* Switch to locale-based stats numbers

* Update CONTRIBUTORS 

Wrong email?

* Fix counts graph on narrow devices

Graph and table now align in a column when the device's screen is narrow. Columns widths are  bounded to not get too wide

* Rename toLocaleXXX functions

* toLocaleNumber -> localizedNumber
 *  toLocaleString -> localizedDate

Also cleans up sketchy "card counts" table formatting

* Localize more numbers

Uses locale-based rounding for more numbers now

* Localize graph axis ticks

* Fix future-due graph tooltip

* avoid div by zero (dae)

Ignoring NaN in localizedNumber() could potentially mask a mistake
in the future - better to explicitly handle the invalid case at the
source instead.
2021-12-29 15:04:15 +10:00
Hikaru Y
df0ad4be4b
Prevent unwanted <div> from being left behind when clearing field (#1565)
* Prevent unwanted <div> from being left behind when clearing field

* Use event.currentTarget instead of 'this'

* Check if event.data is empty for better performance

* Change order of conditions for better performance
2021-12-24 09:12:04 +10:00
Hikaru Y
12ccdee25b
Fix some issues with closing previewer (#1563)
* Fix media playback not terminating when previewer is closed

https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/78

* Fix _on_preview_closed being called twice unnecessarily

The function was being called twice when the preview button is clicked
while the previewer is open.

* Fix console error caused by leftover code

The following error was shown in the console when closing previewer:
`Uncaught TypeError: Cannot read property 'classList' of null`

* Toggle state of preview button via 'active' prop
2021-12-20 20:23:50 +10:00
Damien Elmes
e175c068af fix inverted SchedBuried and UserBuried in cards.ts
This wasn't causing any problems, as we only ever checked for both at
once.
2021-12-20 12:57:35 +10:00