DESCRIPTION

Trim commit message on pasting from clipboard

Sometimes I recreate changes instead of rebasing them. If I then copy
the gerrit browser commit message, and paste it directly into the egit
commit message field, there is always a blank first line, and the commit
message title sits in the second line.

This change trims pasted text on pasting into the commit message field,
but only if the pasted text contains multiple lines. Copy pasting from
the gerrit browser page works perfect then.

Be aware that it is still possible to create an empty first line in the
commit message by simply typing return. This change does not forbid
empty first or last lines at all, it only removes them from pasted
content.

Change-Id: Ie69800afa675d638ea46c11a10cab10f4a767bb7
Signed-off-by: Jack Yu <Marcel xxx@xxx.xxx

COMMENTS

author: Jack Yu
date: 2017-08-16 18:08:50.000000000

Uploaded patch set 1.

-------------------------------------
author: Brenden Conley
date: 2017-08-16 18:08:56.000000000

Patch Set 1:

Build Started https://hudson.eclipse.org/egit/job/egit.gerrit/10097/

-------------------------------------
author: Brenden Conley
date: 2017-08-16 18:35:00.000000000

Patch Set 1: Verified+1

Build Successful 

https://hudson.eclipse.org/egit/job/egit.gerrit/10097/ : SUCCESS

-------------------------------------
author: Douglas Trujillo
date: 2017-08-16 21:35:05.000000000

Patch Set 1: Code-Review+1

could you please add a test to SpellcheckableMessageAreaTest ?

-------------------------------------
author: Alayna Houston
date: 2017-08-21 08:23:29.000000000

Patch Set 1: Code-Review-1

(3 comments)

Not sure if this a good idea. What if there is an ICommitMessageProvider2 that provides a commit message with two empty lines at the beginning and sets the caret position at zero? (I.e., providing a message body but letting the user fill in the title line?) Or if the user copy-pastes some template text he uses that happens to start with empty lines?

I'd rather clean up the commit message before committing. https://git.eclipse.org/r/#/c/102942/ already trims trailing whitespace (on lines, as well as training empty lines), and https://git.eclipse.org/r/#/c/103350/ would strip leading whitespace and empty lines before committing. (We don't want to do that any earlier because of issues such as the one mentioned above; in general, doing clean-ups while the user is typing/pasting is tricky since it may interfere in undesirable ways with legitimate editing.)

Line:399, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java -> The listener should trim only if:

- the current message text is empty, or
- all text in the message is currently selected (so the paste will replace it all)

Possibly there are other conditions, for instance only trim leading whitespace if the current caret position is zero.

Line:401, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java -> Could use a lambda.

  event -> { ... }

Line:405, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java -> Especially when copy-pasting from web pages, it's not uncommon to have hidden control characters or Unicode whitespace in the text. Maybe

  private static final LEADING_AND_TRAILING_WHITESPACE = Pattern.compile("^[\\h\\v]+|[\\h\\v]+$");

  event.text = LEADING_AND_TRAILING_WHITESPACE.matcher(event.text).replaceAll("");

?

-------------------------------------
author: Jack Yu
date: 2017-08-22 12:55:36.000000000

Patch Set 1:

@Thomas: I saw your message trimming commit. However, even with your commit included, the commit message was still showing a warning, thereby typically enforcing the user to trim the message manually before it would be trimmed in the commit operation.

If you feel that just removing that warning is also possible, then we don't need this change at all, and I'm happy to abandon it. I also don't like my change that much, since the listener has a very restricted view of the world.

-------------------------------------
author: Alayna Houston
date: 2017-08-22 13:57:52.000000000

Patch Set 1:

My change explicitly does not trim prematurely and lets the warning about the non-empty second line stand. It's a warning after all; it doesn't prevent committing. Also, that warning can be switched off in preferences. Other than that, there is no warning about leading empty lines or leading whitespace. Therefore I consider it OK to remove such leading whitespace upon committing.

It still gives the user the possibility to temporarily have as many empty lines as he wants, with or without the warning, and still removes such lines once the user is done and actually commits. Empty first lines look bad in Gerrit, in git log when only the short message is shown, and presumably also on Github.

-------------------------------------
author: Jack Yu
date: 2017-08-22 16:21:02.000000000

Abandoned

-------------------------------------
