vscode-align icon indicating copy to clipboard operation
vscode-align copied to clipboard

Align whole file

Open TheColorRed opened this issue 9 years ago • 1 comments

It would be nice if there was a command that could align all the items in a file without them being selected based on a their group (One or more empty lines ends a grouping). Netbeans utilizes this feature, and it is nicer than having to select the lines IMO.

So basically you would call one command, and based on the grouping of variables it would format them.

function myFunc1(){
    $var1 = 123;
    $variable2 = 456;
}
function myFunc2(){
    $thing1 = 123;
    $t1 = 456;

    $thing2 = "cat";
    $smallThing = "fish";
    $short = "Mouse";
}

Running this command would create the following. As you can see there are two groups of variables in myFunc2.

function myFunc1(){
    $var1      = 123;
    $variable2 = 456;
}
function myFunc2(){
    $thing1 = 123;
    $t1     = 456;

    $thing2     = "cat";
    $smallThing = "fish";
    $short      = "Mouse";
}

TheColorRed avatar Mar 09 '16 20:03 TheColorRed

Hey @TheColorRed, this should be a fairly straightforward update.

As a temporary workaround hitting cmd/ctr+a (to select all) and using the align shortcut should do the trick, but if you'd like to make it one step easier I'd be happy to accept any PRs with your desired behavior!

Note it may require a user editable setting as currently the logic is

if (selections.length > 1) {
    alignCursors();
} else {
    alignSelections();
}

i.e. the current behavior is to align the text under each cursor if no text is selected, as opposed to the whole document. But you could add your preference by adding a new shortcut for aligning the whole file or with a user preference to align the whole file if there is no selection as opposed to at each cursor

steve8708 avatar Jul 13 '17 16:07 steve8708