kbrose / vsc-python-indent

Correctly indent python code on the fly, in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=KevinRose.vsc-python-indent
MIT License
82 stars 19 forks source link

Maybe adjust behavior of useTabOnHangingIndent? #103

Open jkyeung opened 2 years ago

jkyeung commented 2 years ago

This is more of a question or comment than a feature request or bug report: What's the rationale for putting the cursor just before the closing bracket rather than just after, upon pressing Tab?

If I've got

foo = (|)

and press Enter to get

foo = (
    |
)

and then type some elements, like

foo = (
    'spam',
    'ham',|
)

I would think that I am trying to get to

foo = (
    'spam',
    'ham',
)|

or perhaps even

foo = (
    'spam',
    'ham',
)
|

as simply and easily as possible, but Tab actually gets me to

foo = (
    'spam',
    'ham',
|)

which is probably very rarely what I want. And by that time, the closing bracket is no longer considered "automatically inserted" by VS Code, and is thus not subject to the default typeover. (Setting "editor.autoClosingOvertype": "always" could help, but some people can't stomach that option.)

I've been playing around with this a little bit, because it's close to allowing me to feel OK about letting VS Code autoclose brackets for me, but not quite there. And clearly most people don't seem to have any problem with the current VS Code behavior, with or without useTabOnHangingIndent.

kbrose commented 2 years ago

Not impossible to do, but it is more than a simple code change because we aren't inserting the ending bracket, we're just using textEditor.insertSnippet() to insert the newline and indentation, which restricts where we can put the cursor.

A possible work around would be to delete the bracket that exists, and insert our own, adding a $n (for some n) pointer after the bracket.