jdlorimer / incremental-reading

Anki add-on providing incremental reading features
https://ankiweb.net/shared/info/935264945
ISC License
216 stars 38 forks source link

Bug when creating flashcards with quickkeys and an empty selection #50

Closed ghost closed 6 years ago

ghost commented 6 years ago

It can be useful to use a shortcut to create a basic note, or a cloze deletion note, without selecting any text. For example, if the user wants to reformulate the sentence(s).

However a bug sometimes happens when I try to do that. It specifically happens when I use a shortcut after having used another (or the same) shortcut, without clicking on the text between both. It never happens when I simple-click on the text between shortcut uses. The bug also happens when I select a piece of text, then click once on the text, then use the shortcut. And when I use a shortcut having never clicked on the text before.

With a shortcut creating a Basic note, pasting text to Front field (these settings): bug ir add-on shortcut config basic front

2 error windows are opened:

Error ... Debug info: Anki 2.1.0beta27 Python 3.6.2 Qt 5.9.2 PyQt 5.9 Platform: Linux Flags: frz=True ao=True

Caught exception: File "/home/.../.local/share/Anki2/addons21/1081195335/main.py", line 169, in createNote addCards.editor.setNote(newNote) File "aqt/editor.py", line 289, in setNote File "aqt/editor.py", line 304, in loadNote File "anki/media.py", line 251, in escapeImages File "/home/dae/Local/py59/lib/python3.6/re.py", line 191, in sub <class 'TypeError'>: expected string or bytes-like object

Then:

Error ... Debug info: Anki 2.1.0beta27 Python 3.6.2 Qt 5.9.2 PyQt 5.9 Platform: Linux Flags: frz=True ao=True

Caught exception: File "aqt/editor.py", line 312, in oncallback File "aqt/editor.py", line 340, in checkValid File "anki/notes.py", line 136, in dupeOrEmpty <class 'AttributeError'>: 'NoneType' object has no attribute 'strip' Caught exception: File "aqt/editor.py", line 312, in oncallback File "aqt/editor.py", line 340, in checkValid File "anki/notes.py", line 136, in dupeOrEmpty <class 'AttributeError'>: 'NoneType' object has no attribute 'strip'

With a shortcut creating a Basic note, pasting text to Back field (these settings): bug ir add-on 2017 12 16 config basic back

Only the first error window appears.

And with a shortcut creating a Cloze Deletion note, pasting text to Text field (these settings): bug ir add-on 2017 12 16 config cloze text

Both errors happen.

Then in each case I find myself in front of an empty IR3 note, instead of an empty Basic or Cloze Deletion note: bug ir add-on 2017 12 16

aleksejrs commented 6 years ago

+1

Thanks for this report; I thought the shortcut was broken.

ghost commented 6 years ago

This error happened with v4.7.14 (the one that's currently on Ankiweb). In v4.8.0 (the one on Github), using a quick key with no text selected is forbidden so the error doesn't happen anymore. But since I make regular use of this, I've made it possible again and fixed the issue in my fork (here).

jdlorimer commented 6 years ago

Are you saying the behaviour in v4.8.0 is not desirable?

ghost commented 6 years ago

I think it is better to allow the creation of cards with no text selected (I'm using this feature perhaps once every 10 extractions), after a warning ('No text was selected. Continue?'): here is the commit. It is a bit dangerous when "Edit extracted note" isn't checked, though, as empty cards can be created.