Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cited text shows up as ordinary text after returning from external editor #66

Open
nicoroeser opened this issue May 14, 2020 · 6 comments · Fixed by #70 · May be fixed by #75
Open

Cited text shows up as ordinary text after returning from external editor #66

nicoroeser opened this issue May 14, 2020 · 6 comments · Fixed by #70 · May be fixed by #75

Comments

@nicoroeser
Copy link

When the external editor opens, and you save the text and quit the external editor, all text shows up as “normal text”. Even lines that had been marked as cited before (blue on white in the default Thunderbird setup; pressing Enter in such a block auto-inserts “> ” at the start of the next line, and such) become ordinary text lines, too (black on white in the default setup).

I think this might be related to #42.

@guiraldelli
Copy link
Contributor

guiraldelli commented May 14, 2020

@nicoroeser, I spent the last two days also bugged by this problem.

I could not find a solution yet, but I found out the following:

  • Thunderbird 68 (the one I tested it) is adding a white-space just before the greater-than sign.
  • Looking in the source code, I think the editor.insertText() might be the cause of problem: I guess it looks for the greater-than symbol in the beginning of a line and prepend it with a white-space.
  • Calling "Edit→Rewrap" or "Edit→Paste as Quotation" in the editor window "fixes" the problem (introducing others, such as rewrapping the text where it shouldn't or adding an extra greater-than symbol in the pasted message).

I have zero knowledge about the Mozilla code-base and JavaScript (used to develop this extension), but I hope this information will help the maintainers to hunt down this bug.

EDIT:

It seems there is a function called insertTextWithQuotations() that I have the feeling it could be correct one instead of insertText() given they have the same function signature.

@snipsnipsnip
Copy link
Member

Hi, thanks for report and investigation.

Unfortunately, insertTextWithQuotations() is already removed (patch), so we can't use that function on Thunderbird 68 :(. In fact, current code is a product of workaround for that removal.

I haven't found a way to fix this issue with some simple API call. Maybe External Editor could do a rewrap after closing the editor, but it has some side effects as you mention.

External Editor can style the message as a HTML even when it is a plaintext, so it can replicate the Thunderbird functionality in principle. (i.e. parsing quotation >s and redo highlight as the rewrap command do). But it requires some work.

@nicoroeser
Copy link
Author

@snipsnipsnip, you wrote:

External Editor can style the message as a HTML even when it is a plaintext,

I am sorry, I don’t know what you mean by this. I hope that it will still be possible to use text-only (text/plain) messages in Thunderbird?

so it can replicate the Thunderbird functionality in principle. (i.e. parsing quotation >s and redo highlight as the rewrap command do). But it requires some work.

As I am bitten by this issue every day, I am willing to invest a bit of time here and try to produce code that can help. Unfortunately I do not understand the way of going forward which you are outlining here. If you could explain the idea a bit further or could share a few pointers into the code or relevant methods or whatever, I’d be grateful, and will happily give it a try!

@nicoroeser
Copy link
Author

editor is an nsIEditor at the moment, and we are using its insertText method. Am I right?

And there is insertAsCitedQuotation in nsIEditorMailSupport, which can insert a piece of text as a quotation.

So it seems to me that we have to parse the text in the JavaScript code of the External Editor addon. We need to alternately call insertText and insertAsCitedQuotation (with the leading > or > removed on each line because it will be re-inserted). This should properly move all of the text to the editor in Thunderbird.

I do not understand yet how to move the cursor or how to position Node objects within the document, but we probably do not need it at all if we handle everything in succession.

I’ve only had a brief look at the source code, and am not an expert on this. Please correct me if I’m wrong.

nicoroeser added a commit to nicoroeser/exteditor that referenced this issue Aug 26, 2020
Should work on Thunderbird 68.

NB: this also converts lines starting with “>” to cited text, even if
the text had not been cited before. Most power users might like that,
though.

And it always changes the citation leaders to default Thunderbird style.

Fixes exteditor#66.
@nicoroeser nicoroeser linked a pull request Aug 26, 2020 that will close this issue
@nicoroeser
Copy link
Author

I’ve been using #75 for some time now without any problems. Has anyone else tried it and can give feedback?

nicoroeser added a commit to nicoroeser/exteditor that referenced this issue Oct 22, 2020
Should work on Thunderbird 68.

NB: this also converts lines starting with “>” to cited text, even if
the text had not been cited before. Most power users might like that,
though.

And it always changes the citation leaders to default Thunderbird style.

Fixes exteditor#66.
@nicoroeser
Copy link
Author

Pull request updated and repaired. Tested with several empty and non-empty messages. Looks good to me now. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants