Improve plaintext attachment handling

See 28097 for the #support thread regarding this.

Versions Tested on:
  • Joplin 2.8.8 (prod, win32)
  • Client ID: 8958c5ac9ba74d009a28611ea3782b3f
  • Sync Version: 3
  • Profile Version: 41
  • Keychain Supported: Yes
  • Revision: c2a6a13

With the Operating System:

  • Microsoft Windows 10 Enterprise v10.0.19044.0 (2009)
  • Motherboard: MSI MS-7998
  • Processor: Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz
  • BIOS Version: 1.E0

I'm not certain when this was implemented, but it started to occur a good while back. Nor am I certain if this counts as a bug instead, if it does, please inform me and I will move it.

Occasionally, specifically with plaintext files of non-standard file extensions like Android bytecode smali, Ren'Py rpy or other such files, attachment by dragging-and-dropping the file into the editor can either succeed as expected or fail. The way it fails varies on length, as far as I've observed.

When a file is non-standard extension is attached, it first pastes the contents, then replaces it with a relative link to the resource. This can be verified by doing an undo step after the link has been added, as it then reveals the contents of the file that was just attached.

Attaching a txt file containing Hello World is handled correctly and doing an undo-step shows no additional content. I am not familiar with Joplin's internals, so this may just be an illusion created by the application having deleted the previous undo step to avoid end-user confusion.

Attaching a rpy file containing Hello World is handled incorrectly. It seemingly adds a relative link to the file, but doing an undo step reveals that the contents of the file has been added to the note.

On small files, that is fine enough, however it causes issues depending on the size of the file that is added. Joplin does not handle very large notes particularly well from my experience, and it does not seem to like suddenly having a few hundred thousand or millions of lines of text into a note. This can cause Joplin to crash, freeze entirely or otherwise become difficult to work with when trying to remove the newly pasted text. Below is an example of a small rpy file:

The file is dragged into the editor and seemingly attached:

Doing an undo step reveals the content of the file (truncated image):

Currently, this can be worked around by using the attach file command either through the GUI or the command launcher. However, doing so is cumbersome in comparison to simply being able to drag-and-drop it into the note.

If this is intended behavior, please add a prompt to the end user before anything is done asking whether they want the content pasted or if they want the file attached. If this is not intended, then the way file handling works should be looked at.

I hope the post is written clearly, but please tell me if not and I'll do my best to rephrase things.