yo1dog / vscode-cursor-align

Visual Studio Code Extension that aligns all cursors using spaces.
MIT License
22 stars 8 forks source link

Feature request :: Right-align cursors/selections #12

Open whatsupbros opened 11 months ago

whatsupbros commented 11 months ago

A feature to right-align all cursors/selections by adding necessary white space from the left would be really nice.

This is useful when you have several "parts" in your statement, and need to align those parts between each other, in example, SELECT/FROM/WHERE/GROUP BY/ORDER BY parts in SQL queries.

Example

Original text

She loves pie.
My friend loves chocolate cake.
Everybody loves muffins.

Left-aligned at the second word (current functionality)

She       loves pie.
My friend loves chocolate cake.
Nobody    loves muffins.

Right-aligned at the second word (desired functionality)

      She loves pie.
My friend loves chocolate cake.
   Nobody loves muffins.

Real world usage example in SQL query

SELECT t1.field1,
       t2.field2,
       t2.field3
  FROM table1 t1,
       table2 t2
 WHERE t1.field1 = t2.field1
   AND t2.field2 = 'ABC'
   AND EXISTS ( SELECT NULL
                  FROM table3 t3
                 WHERE t3.field1 = t1.field1
                   AND t3.field2 = 123 )

As shown here, SELECT, FROM, WHERE, AND are right-aligned, which is required in some projects.

yo1dog commented 3 months ago

Can you give me some more details on how exactly you would expect this to work? I am having trouble understanding right-alignment in left-aligned environments.

How would the extension know where to insert the whitespace?

For example, what should happen in the following to "right-align" to words "love"? A or B? And how would the extension know?

Perhaps this would only be possible with selections which would define the bounds of the text to be right aligned. Outcome B would be possible if the user selected "She", "My Friend", and "Nobody".

var i = 0; // She loves pie.
fu();      // My friend loves chocolate cake.
bar();     // Nobody loves muffins.

A. Start of line.
      var i = 0; // She loves pie.
fu();      // My friend loves chocolate cake.
   bar();     // Nobody loves muffins.

B. ???
var i = 0; //       She loves pie.
fu();      // My friend loves chocolate cake.
bar();     //    Nobody loves muffins.