prati0100 / git-gui

Tcl/Tk based UI for Git. I am currently acting as the project's maintainer.
161 stars 87 forks source link

Hard wrap commit message text at the configured text width #7

Open prati0100 opened 4 years ago

prati0100 commented 4 years ago

Right now, all the gui.commitmsgwidth config variable does is set the size of the commit message window, so users get a visual hint on when to manually wrap their text. A much better quality-of-life feature would be to wrap the text for the user.

Also, allow disabling the line wrap for people who don't want it.

Wrapping the display text of the commit message text box is easy to do. The -wrap option of the text widget can wrap the displayed text. I haven't looked too much into the option, but AFAIK it only soft-wraps the text.

So, we need to hard-wrap the text before passing it to the commit machinery. The main challenge is to make sure our wrapping algorithm works exactly like the text widget's wrap, otherwise the users would see one thing and the commit would contain something else.

It would also probably be a good idea to allow not wrapping a line. Maybe we can do something like mbox subject lines where if the first character of the line is a space, it is considered a part of the previous line.

An alternate implementation to using -wrap would be to run the text wrapping logic every time the user types something (probably by using tags). This would remove the need to match Tcl's word wrap implementation, but might have a performance hit.