bendera / vscode-commit-message-editor

Edit commit messages in a convenient way.
https://marketplace.visualstudio.com/items?itemName=adam-bender.commit-message-editor
MIT License
70 stars 13 forks source link

Options not applied to Form #78

Closed l0ner closed 1 year ago

l0ner commented 1 year ago

Hi

The options "commit-message-editor.view.useMonospaceEditor" and "commit-message-editor.view.rulers" are not applied to the fileds in the form view.

bendera commented 1 year ago

Hi

These options belong to the text view.

l0ner commented 1 year ago

OK, great. How to apply these to the form view? Is the form view configurable in any way when it comes to having guides/limiting max line length and changing the font?

bendera commented 1 year ago

There is a maxLenght option for the textfields, see: https://github.com/bendera/vscode-commit-message-editor#tokens

The monospace editor cannot be used in the form view currently but would make sense. I will consider this idea.

l0ner commented 1 year ago

the maxLenght, when applied to the fields limit the total character count, which is fine for scope and short description, but not for body.

What i want to do is not have any limits when it comes to total character count for body, but have a limit for the length of a single line in the Body field (or a ruler, having visual indicator whould be fine, but that would require the body field to use monospace font). This limit could be implemented behind the scenes, where in the editor there is no limit, but when saving the message the commit editor automatically splits the lines on whitespace to make them fit within the limit (very long non-splittable things like urls would be kept in their entirety on a single line).

This could be implemented in the following way:

// Some long lines
const text = `
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin interdum, leo sit amet ullamcorper porttitor, ex ipsum tincidunt odio, tincidunt hendrerit leo nulla ut sapien.

(a-very-non-splittable-line)[https://github.com/bendera/vscode-commit-message-editor#tokens]

Suspendisse ornare gravida ligula ut tincidunt. Donec accumsan venenatis augue sed blandit. Suspendisse porttitor pretium felis non bibendum. Donec laoreet fringilla nisl. Ut luctus tempus varius.

Etiam fermentum arcu vitae placerat consequat. Donec eu orci vitae lacus semper efficitur. Curabitur eleifend orci dui, scelerisque tempor leo tempus non.
`

// this should come from field configuration
const maxLineLength = 40;

// split the original text on newlines
const originalLines = text.split('\n');
let splittedLines = [];

// iterate over all lines
for (let line of originalLines)
{
    let newLines = [];

    while (line.length > maxLineLength)
    {
        let splitLocation = 0;

        // find the first whitespace
        let tmp = line.indexOf(' ', splitLocation);

        // line has no whitespace on which we can split
        if(tmp < 0) {
            newLines.push(line);
            line = ''; // remove everything
            continue;
        }

        do {
            splitLocation = tmp + 1;
            tmp = line.indexOf(' ', splitLocation);

            if (tmp < 0)
                break;
        } while(tmp < maxLineLength)

        // push the line up to limit into the array
        newLines.push(line.slice(0, splitLocation - 1));

        // remove what we have found
        line = line.slice(splitLocation);
    }

    // concat the newly formed lines with we had before
    if (newLines.length > 0)
        splittedLines = [...splittedLines, ...newLines];

    // add the rest that is shorter then maxLineLength
    splittedLines.push(line);
}

// Join the new lines into single block of text.
const wrappedLines = splittedLines.join('\n');

console.log(wrappedLines);

Same goes for the footer, where having an additional limit for how may lines the footer can be would be nice too.

bendera commented 1 year ago

I'm working on a similar function but for the text view.

A "monospace editor" flag will be added to the multiline text field options.

l0ner commented 1 year ago

Great to hear about "monospace editor"!

Having a functionality that automatically makes the commit message generated from the form to adhere to the max line lenght would be great too. Not having it is essentially what blocks my team from using this plugin.

bendera commented 1 year ago

Added in v0.23.0