fonol / anki-search-inside-add-card

An add-on providing full-text-search and PDF reading functionality to Anki's Add card dialog
https://ankiweb.net/shared/info/1781298089
GNU Affero General Public License v3.0
178 stars 24 forks source link

Save text notes on "Done" and "Close" buttons #112

Open An-png opened 4 years ago

An-png commented 4 years ago

Currently, you can make changes in the tinyMCE editor. However, those changes do not leave the editor, and aren't stored in the notes database at all. This means closing a text note or pressing "Done!" means all changes made in the tinyMCE editor are lost.

fonol commented 4 years ago

Have you hit Save? I tested, and it seems to work for me. I had autosaving in an earlier version, but it caused some problems, so I added the Save button at some point.

An-png commented 4 years ago

Oh wow, didn't see that. :rofl: :rofl: Maybe there could be autosave when you hit Done!, or close with the cross?

An-png commented 4 years ago

p.s. what is "SIAC"?

An-png commented 4 years ago

For example, here, you could add this pseudocode in actual python

if note_type = text:
    execute_javascript_command(saveTextNote(nid, remove=False))

I don't know how to invoke javascript functions using python, and I don't know what the nid parameter is referring to (note id), so I can't actually write the code. I attempted at righting some code, but it's probably wrong in some sense.

An-png commented 4 years ago
is_text_note = False
if note.text is None:
            is_text_note = True

on line 634 of readingmodal.py.

and then change this on line 646:

<a onclick='if (!pdfLoading && !modalShown) {{ noteLoading = true; greyoutBottom(); pycmd("{queue_btn_action}") }}' class='siac-clickable-anchor' style='font-size: 16px; font-weight: bold;' id='siac-first-in-queue-btn'>{queue_btn_text}</a><br>

to this:

<a onclick='if (!pdfLoading && !modalShown) {{ noteLoading = true; greyoutBottom(); pycmd("{queue_btn_action}") }} if ({is_text_note}) {{ saveTextNote({note_id}, remove = false) }}' class='siac-clickable-anchor' style='font-size: 16px; font-weight: bold;' id='siac-first-in-queue-btn'>{queue_btn_text}</a><br>

(and do the same for the close button, located at line 358) I think this might work? I don't know any way of distinguishing text notes from PDF notes using (what seems to be) the SQL entry for the current note. I looked around that file and note.text might work, however I don't know if note.text calls the textlayer for PDFs. If it does, then obviously that IF statement isn't effective.

fonol commented 4 years ago

p.s. what is "SIAC"?

"Search in Add Card", the original add-on name, I started using this prefix at some point to prevent name clashes.

As for the saving on Done, I will look into it again, but there was some reason I abandoned it, I just don't exactly remember it at the moment.

An-png commented 4 years ago

Changed the title to reflect the issue that text notes aren't saved on "Done", "Close" buttons as well as clicking on an article in the queue head.