DillanCMills / tab-stop

Utility extension for VS Code to insert spaces on the current line to a user-configured column number
MIT License
1 stars 1 forks source link

Feature request: indent (and dedent) selection #3

Open jkyeung opened 3 months ago

jkyeung commented 3 months ago

Do what normal Tab and Shift+Tab do when a selection is highlighted, except using the user-defined tab stops instead of every n spaces.

I'm guessing this goes way beyond what you had originally intended for this extension. Even if you don't implement it, maybe someone else will come along and build it. I would do it myself if I had the knowledge and the time.

DillanCMills commented 3 months ago

At least for single line highlights, the selected text is indented to the tab stop. I will see about adding support for multi-line indenting and de-indenting to roughly match the regular behavior.

DillanCMills commented 3 months ago

If you had multiple lines with different indents, would you expect each line to indent by the same amount, being the next tab-stop of the first line in the selection (even if it doesn't align with a tab-stop on subsequent lines) or would you expect each line to be independently moved to the next tab-stop?

a
        b

indent to

    a
            b

or

    a
                        b

assuming tab-stops of 4 and 24

jkyeung commented 3 months ago

Good question. Off the top of my head, I'm not completely sure. I would probably go with whatever the out-of-the-box Tab and Shift+Tab do when multiple lines are selected. I think that means indent each line independently, but I'd have to play around with it before saying anything more definitive.

DillanCMills commented 3 months ago

It's not obvious for the regular behavior since it always indents and dedents a fixed amount. All lines move left or right by your defined tab size. In this case, the tab size is dependent on the cursor position and the tab array.

I think moving each line independently to the next tab stop makes the most sense. If you want to move the block altogether you would just use a regular tab or multi-cursor to do it.

I might pull up a word processor and see how it behaves in this scenario, since that is the closest model to what this package is doing. I expect it will move each paragraph to the next available tab stop independently.

jkyeung commented 3 months ago

At least for me, the built-in behavior is to indent or dedent each line so that they all align with a tab stop. For example, if I have an indent size of 4, and the following preexisting code:

#...|...|...|
     a = b
      c = d

Then highlighting both lines and pressing Tab gets me this:

#...|...|...|
        a = b
        c = d

So, I'm good with moving each line independently. I think that is a sensible way to handle indentation of multiple lines.

Have you considered what should happen if someone has used rectangular selection to highlight their multiple lines? Presumably, if they've done this, they are trying to adjust the alignment of things within the lines, such as equals signs or comments. I don't have a strong opinion on this, because it's not something I would do. But I can imagine that someone might be hoping that the highlighted stuff becomes aligned. And if that's the case, I would imagine that it might be best to advance the rightmost-starting content to its next tab stop, and then advance all the other highlighted content to match. (Or leftmost-starting content to its previous tab stop, etc.) Alternatively, I could also imagine each highlighted partial line being moved to its respective nearest tab stop.

DillanCMills commented 3 months ago

I just published a pre-release (should be able to install within VS Code using the "Switch to pre-release version" I think. Try it out and see if anything feels weird. I tried testing every case I could think of (single cursor, multiple cursors, multi-line selection, indent and dedent each, different character strings) and I think it is behaving in a consistent way across the board.