+16

Add word wrap option to Commit Message

Douglas Masterson 6 years ago updated by Jeff Jensen 2 years ago 20

I often find myself having to add text to the middle of my commit message, and I thus have to change all of the following lines so that they adhere to the line length guidelines. It would be nice if the Commit Message editor would word wrap at line length guide.

GUI
+2

And correctly indent the second and subsequent lines for bulleted lists (e.g. lines that begin with * or -).  e.g.:


* This is my list that wraps

  onto multiple lines with a

  formatted paragraph and indent.


Do I understand this request correctly: It should enable work-wrap in the control but upon clicking the Commit button, it should insert line-endings automatically for too-long lines?

That works for me.

The key thing is auto-formatting to the correct length while typing, whether it uses hard newlines or not in the control, and then submits with hard newlines as formatted.


+2

I would really like this feature, but I think I would prefer it to be a separate command before committing so that I could see the result. I would prefer it to rewrap any selected lines, and if you run the command with nothing selected, it would rewrap the paragraph the caret is in (removing and inserting line-endings to wrap the text). I use the Rewrap extension for Visual Studio Code to wrap comments, and that's the behavior it has: https://marketplace.visualstudio.com/items?itemName=stkb.rewrap

+4

Any updates on this? I can't find any settings regarding it and right now, it just does soft-wrapping according to the window size. If you enable the line length guide it marks all the "too-long" lines as red. I would expect there to be a setting to set how wide the commit message can be (separate widths for the summary line and the body preferably) and then it should automatically soft-wrap to keep the text within that width. Once you hit save/commit/whatever it should automatically insert the actual line-breaks where the soft-wrapping occurred. Sounds simple enough to me.

+1

I would love to have this functionality as it's a standard interaction from w/in my IDE.  I currently swap back to IntelliJ to get some of the missing auto-format functionality.  Personally, I don't want an "autoformat on commit" as that could change the layout in a way that I can't correct before commit.

Please describe the auto-format functionality as detailed as possible, so a developer understands how to implement it. Thanks in advance.

+2

As a committer, when drafting a message, I can hit a keyboard shortcut (e.g. Ctrl+Alt+L in IntellJ) that will automatically wrap (and insert appropriate line breaks to make) all entered text fit within the configured line width so that I don't have to manually enter these line breaks.


Agreed - a menu option with keyboard shortcut is ideal way to reformat.  This is also similar to Emac's reflow feature.

Proposed spec, as requested by Thomas:

The Commit dialog should offer a button (and optionally a keyboard shortcut) to hard-wrap the selected text at word boundaries by inserting newline characters at the preset line length.

If no text is selected, wrapping should apply to the current paragraph, based on caret position. A paragraph is defined as a series of lines separated by one or more empty lines.

Long lines without spaces (e.g. a long URL), as well as the commit message's first line, should not be wrapped.

After reformatting, trailing whitespace on each line should be trimmed. Caret should be placed at the end of the wrapped paragraph's last line, or the initial selection restored.


To illustrate the expected behavior, see the VIM editor's gq command. Specifically, the {gq} performs wrapping on the current paragraph.


Optionally, an option (e.g. checkbox) to automatically apply word-wrapping while typing would be nice to have; this should be turned off by default, and preferences kept


I hope this helps.

Wondering if this feature is in release plans and forthcoming?  Manually formatting a commit message with newlines is a time waster!

I'm not yet sure about how to implement it the most efficient way and how to combine it with the line-length guides.

Thanks for the reply Thomas.

Do you mean internally/technically or do you mean from a user-feature interaction?

+1

I think what was proposed above, "a menu option with keyboard shortcut is ideal way to reformat", would be great.

+1

Agreed.  While auto-formatting while typing is really nice, I'm very happy with a manually invoked format option.

This would not work in the Commit dialog.

+1

May we understand why a manually invoked format option will not work?  Do you mean technically?  Is there also a difference between the Commit "dialog" vs Commit "view".

What options exist that will technically work?

Please look at the Commit view (and Commit dialog) of version 20.2. Where exactly you want to have the rewrap command? As a button, as a context menu (with hard-coded keyboard shortcut)?

+2

My preference is a keyboard shortcut (e.g. Alt-q) and not particular as to which UI component it maps to.  Reviewing them, context menu is less invasive; hamburger menu doesn't work well as is about messages, and a button would stand out on the UI.

Wondering if this feature is anywhere on the implementation planning radar?  It's one of the key usability features we encounter on a daily basis.