Assign Note-ID to new notes in addnote window (revert a change in 2.1.28)

Up until 2.1.28 when you ran mw.col.getNote() you got a new, unsaved note that already had a note id.

So in the add window you already knew the id a note would have and could e.g. display it with an add-on like “Add Note Id”. This allowed me to copy the nid into other places, e.g. other notes or an external document for reference. (Later I can quickly follow the references with my link Cards Notes and Preview them in extra window).

I also had an add-on that allows to extract selections from one note (in the browser) into a new add window which also stores the new note id for the extracted text in the original note, so that I can later find the extracts from the source note. This required knowing the new note-id when making the extract.

This no longer works because since 2.1.28 (based on I think the commit “hook up new note and note type handling”) all new notes have an id of “0”. The note-id is only assigned when mw.col.add_note() is run which is run only after you’ve finished processing the note in the addwindow after you click the “add” button.

I’d prefer the old behavior and I can imagine some use cases where the old behavior would be useful. I don’t know rust so I hope that I don’t casually ask for some huge changes …

1 Like

I’m afraid the new behaviour is likely to stay, as generating ids in advance is more error-prone. If you change your code to change the note after it is added, you can then immediately save it to accomplish the same as before.

It’s a bit silly to have to store the id in a field just so duplicates can be matched when importing - when I revisit the importing code, this is something I’d like to fix.