Commit Graph

109 Commits

Author SHA1 Message Date
Damien Elmes
797a7ea229 refactor editor focus handling
this fixes a bug where navigating to the next/previous card using
shortcut keys resulted in the first field being clobbered

- get rid of the stealFocus option in favour of explicitly passing
focusTo to setNote()
- setFields() is no longer responsible for setting focus
- add focusTo var to the browser so that the row changed hook can
restore focus when navigating to next/previous card
- fix the row changed hook being called twice
- the blur event now includes the field number instead of relying on the
 editor to have the correct currentField
- the current field is set to null on blur
- use deferred js and a callback rather than keeping track of when we
were loaded
- add shift+tab shortcut to go to previous field
2017-08-05 15:16:20 +10:00
Damien Elmes
9ec9274011 fix fields being overwritten when dropping
remove the unneeded setFocus() call which was causing the blur event
to fire with the wrong data
2017-08-01 17:40:51 +10:00
Damien Elmes
7ad6966943 split js code out into separate files, mathjax improvements
- js code that was previously bundled in .py files is now in the
web folder
- add helpers to create links to bundled files, and update
stdHtml() to accept a list of javascript files to include
instead of text
- render MathJax in card layout and preview screens - these should be
updated in the future to update the document dynamically like the
reviewer does
- start media server earlier so it can be used to serve content for
the toolbar, etc
- work around a bug in WebEngine on Windows that could cause the
media server to hang
2017-07-28 16:35:45 +10:00
Damien Elmes
630cddc786 fix superscript shortcut
https://anki.tenderapp.com/discussions/beta-testing/627-anki-210-beta-1#comment_43048185
2017-07-22 10:54:45 +10:00
Damien Elmes
17bb179d06 experimental prewrap support
- add option to wrap html in implicit pre-wrap environment during
editing and review - defaults to off
- update paste filter to convert divs/Ps to newlines and non-breaking
spaces to normal ones
- catch enter key and write \n instead of creating a new div

also:

- remove extra caretToEnd() call that is no longer required
- add dd/dt/dl to allowed tags
2017-07-20 12:16:47 +10:00
Damien Elmes
7ecd889d8f preserve newlines and indents when pasting text
https://anki.tenderapp.com/discussions/ankidesktop/24123-paragraphsnew-lines-not-preserved-when-copypasting-into-anki
2017-07-12 10:57:01 +10:00
Damien Elmes
14597bd888 if a non-media link pasted, paste the url text directly 2017-07-11 14:58:22 +10:00
Damien Elmes
7af591cfd7 add cancel button to recording window 2017-06-23 13:04:32 +10:00
Damien Elmes
a3fa2ff5ba remove duplicate <html> in editor, set bg on page creation 2017-06-22 18:01:47 +10:00
Damien Elmes
07f175cec8 add m4a to attachable media formats 2017-03-02 12:10:13 +10:00
Damien Elmes
6335dcb90e canonicalize to NFC form on edit/import 2017-02-19 12:49:52 +10:00
Illia Volochii
13b7e01044 Stop inheriting from object
It is not needed in Python 3.
2017-02-07 00:21:33 +02:00
Damien Elmes
6ae21e86af remove print statements that were causing unicode errors 2017-01-25 15:12:48 +10:00
Damien Elmes
f68d5a4285 Merge pull request #154 from simgunz/editor-buttons
Editor buttons
2017-01-16 15:08:23 +10:00
Simone Gaiarin
b57ee28ae7 Add check on file existence 2017-01-14 21:16:50 +01:00
Damien Elmes
7d1b894b45 add small bottom margin between "Fields"/"Cards" and field area 2017-01-10 19:02:29 +10:00
Simone Gaiarin
a5c24aaca0 Add option to make button toggleable 2017-01-08 14:34:18 +01:00
Simone Gaiarin
67246f8c80 Add method to convert resource to data uri, add button image with this 2017-01-08 13:52:47 +01:00
Simone Gaiarin
81ed10faee Add id param name and fix typo on duperscript id 2017-01-08 13:52:47 +01:00
Simone Gaiarin
42ea7c53dd Add optional id in parameters 2017-01-06 16:43:05 +01:00
Simone Gaiarin
1c8c34b443 Add padding among buttons
For some reason after using the new _addButton method the padding among the buttons is not there any more. So I add it manually.
2017-01-06 16:43:05 +01:00
Simone Gaiarin
abc3224fe3 Remove old tooltips 2017-01-06 16:43:05 +01:00
Simone Gaiarin
4e4947bd92 Run filter on right buttons list 2017-01-06 16:43:05 +01:00
Simone Gaiarin
5051dcedb6 Add anki buttons using the new method
The html of each anki button is stored in a list that is joined in a string at the end. This make it easier to run the filter.

Drawback: Only buttons on the right side of the editor can be added using the filter.
2017-01-06 15:57:02 +01:00
Simone Gaiarin
37e345ffe8 Replace _addButton method with HTML based one
Support loading icon from anki qrc resource file or using the absolute path
2017-01-06 15:57:02 +01:00
Simone Gaiarin
5775c3f92e Add filter on topbuts to allow addons to add buttons 2017-01-05 12:42:19 +01:00
Simone Gaiarin
81b60c6dc4 Add css id to editor buttons div
This facilitate the processing with beutifulsoup or similar parser
2017-01-05 12:42:19 +01:00
Marcio Mazza
a1f29c2bd2 Remove editor dependency on ECMAScript 6
It seems that ES6 is not available on Qt 5.5.
2016-12-19 12:59:20 -02:00
Damien Elmes
9b6a21126d drag&drop support, and paste refactor
- insert resulting html directly into fields instead of relying on
fragile clipboard rewriting
- catch paste events in js and send them back to python so we cover
all possible ways of pasting
- use checksum in pasted image filenames instead of .cacheKey(),
which was not unique across runs
- try each _processX() in turn instead of having special cases inside
them
- rewrite the HTML filtering:
 - img rewriting and stripping of certain tags handled in bs4; other
 processing handled in js for easier sharing with other clients
 - use a whitelist of HTML tags and properties instead of focusing
 mainly on webkit cruft
 - don't run filter when focus lost, as it no longer seems to
 be necessary
 - the "strip html" option is currently ignored
2016-12-15 18:14:47 +10:00
noobie
1a665cc185 Suppress the BeautifulSoup filename warning
Bs4 will raise a warning if the markup (field input) starts with '/'. Suppressing the warning is probably the easiest solution, as Bs4 will still process it (no disadvantages?).
2016-10-20 04:00:34 +02:00
Damien Elmes
8e71554ac4 saveNow() now requires a callback
the current code was freezing when clicking on 'cards' in the
browser - it looks like like the javascript callback was never
being called despite calling processEvents(). so we need to
refactor the code to call saveNow() with a callback that does the
subsequent processing.

a lot of the browser code was implicitly calling saveNow() via
beginReset(), so we've had to change all that code to save
immediately before it begins any processing. found a probable bug in
the process - it doesn't look like onRowChange() was saving before
overwriting the note, so theoretically edits could be lost if the
user switched to another card very quickly after typing something.

onSearch() has been split into a GUI-activated onSearchActivated()
that takes care of saving, and a lower level search() that refreshes
the current search. it keeps track of the last search via an instance
variable so that it refreshes properly if a user accidentally adds
some characters to their search without activating the search, then
does something like reverse the sort order.
2016-07-14 20:23:44 +10:00
Damien Elmes
3fa597ed1a wait until saveNow() is done
fixes content missing if typed right before save, and add window
complaining that fields aren't empty when they appear so
2016-07-12 13:30:10 +10:00
Damien Elmes
a8e2f992c8 image support 2016-07-07 23:39:48 +10:00
Damien Elmes
eddef71f75 prevent field from collapsing 2016-07-07 17:41:47 +10:00
Damien Elmes
258a10edc7 add titles to various webviews to make them easy to locate 2016-07-07 17:23:13 +10:00
Damien Elmes
d94c011c88 fix clayout preview, js errors
.exec_() and webengineview don't seem to play nicely together
2016-07-07 12:32:27 +10:00
Damien Elmes
a001553f66 move the editor buttons into the webview
use new icons, which scale with dpi changes
2016-06-22 14:52:17 +10:00
Damien Elmes
d7339d9a27 update editor, key handling in webview
keyPressEvent/etc no longer work with qwebengineview, so we need to
install an event filter to catch things like ctrl+c. drag & drop
doesn't seem to be supported until 5.7
2016-06-06 17:54:39 +10:00
Damien Elmes
15b349e3a8 start port to python 3
unit tests pass and main screens of GUI load
2016-05-12 14:45:35 +10:00
Damien Elmes
80e45fee85 Revert "Deal with Internationalized Domain Name in URI"
This reverts commit a68af5f199.

Patch does not fix the issue on my machine, so reverting for now.
2016-04-27 20:43:11 +10:00
Roman Franchuk
a68af5f199 Deal with Internationalized Domain Name in URI
This fixes https://anki.tenderapp.com/discussions/ankidesktop/17132-anki-reports-an-error-when-pasting-an-image-from-non-ascii-url

The problem is that urllib2 can't work with IDN. However, it's perfectly valid
to have such URIs in HTML, and Firefox, when copying image, generates exactly
this kind of HTML.
2016-04-17 15:49:28 +03:00
Damien Elmes
6f95527758 use the larger arrow only on windows, and in other screens 2015-09-28 23:09:30 +10:00
Jonathan Hall
6f77eed9bf Recognize a couple new media formats.
Adding 'webp' was necessary for Anki to recognize WebP images
(https://developers.google.com/speed/webp/?csw=1) as images rather than
audio.  The addition of the audio formats was incidental, as it appears Anki
assumes audio files if a file is not an image file.
2015-03-15 17:33:48 -05:00
Thomas TEMPÉ
3d81ef2c68 Avoid calling checkValid on an empty note
Fix error message when editFocusLost is called after editor destruction

https://anki.tenderapp.com/discussions/ankidesktop/11175-bug-in-browser-revealed-by-add-on?unresolve=true
To reproduce:
1. Install the attached add-on. (All it does is register a function on the editFocusLost hook, and set the flag to 1 to signify that a field has been updated).
2. Run Anki. Enter the Browse window. Press Enter to display your deck.
3. Select one card.
4. Click inside one of the fields for that card. Now, when you leave that field, the editFocusLost hook will be called.
5. Now, select 2 notes from the browser, with your mouse, without clicking anywhere else before.

You will observe this error message:

Traceback (most recent call last):
File "aqt/progress.pyc", line 69, in handler 
File "aqt/editor.pyc", line 467, in onUpdate 
File "aqt/editor.pyc", line 572, in checkValid AttributeError: 'NoneType' object has no attribute 'fields'
2014-12-31 22:36:12 +08:00
Damien Elmes
ece78a7d11 allow all ankiwebview instances to take focus
the canFocus/canCopy separate variables was silly, as we ended up
with text that could be copied from the context menu but not with
a shortcut key. also we default to allowing focus now, since that's
the more sensible default. fixes copy issues with card info dialog and
some addons
2014-09-15 15:04:14 +09:00
Damien Elmes
d53346d783 limit url unquoting to image tags
this prevents random text like %20 in a field from being converted
when note is saved
2014-08-01 09:42:28 +09:00
Damien Elmes
f8bf8afe4a Revert "remove urllib.unquote() step in editor"
This reverts commit 23cec2d5e9.

without other changes, this causes double escaping when editing
2014-08-01 09:37:23 +09:00
Soren I. Bjornstad
23cec2d5e9 remove urllib.unquote() step in editor
Fixes bug #950. We need to keep an eye out for media filename problems,
as this line is probably not necessary anymore with changes to the way
Anki handles encoding but could potentially introduce issues.
2014-07-22 10:36:08 -05:00
dae
8dd88c5f30 add m4a to usable formats 2014-05-25 20:02:24 +09:00
Julien Baley
69a19b58c2 Fixes creation of Cloze when having a chained modifier on the left of cloze 2014-03-09 18:12:39 +00:00