yatki / vscode-surround

🔥 A simple yet powerful extension to add wrapper templates around your code blocks

Home Page:https://marketplace.visualstudio.com/items?itemName=yatki.vscode-surround

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Indentation

oheyjesse opened this issue · comments

Referencing issue #2 (indentation):

Great work on the extension. It'd still be fantastic if we could somehow set the indentation to match the current selection's indentation. I see you've ruled it out as "not being part of the use case" - but I respectfully disagree.

I've taken your extension and written a few wrappers for ruby methods, and Rspec tests, and it's great! But I've found when I'm wanting to wrap existing code in existing indentation levels, that it's putting the new wrappers in at indentation 0, and leaving the rest indented as it was.

This isn't ideal as it requires me to highlight and re-indent manually, which I'm beginning to think negates the workflow speed increase for me.

Is it possible to keep the existing indentation level? I could take a look at this if you accept PR's.

Hey @oheydrew, thank you very much for your message. I'm glad to hear that it's useful for you.

I'm a bit confused because I think extension already should be working as you described. Here, I recorded an example on my pc:

saq8y-wf7hw

Please let me know if I'm missing something.

Could you please share the steps to reproduce the issue and also share

  • vscode version
  • your snippet config (copy and paste it as it is)
  • surround version
  • (if possible) also a screenshot of the final result when you wrap the selection.

Thanks.

Auto Indentation seems not to work on my PC, too. Does this feature depend on any setting or something?

vscode version: 1.38.1
surround version: 1.0.2

image

@ylc395 hmm. actually auto-indentation is not something that this plugin offers. It only wraps the selected text from its starting point. So if you are choosing empty lines before executing the surround command, indentation can break.

Also using a formatter like prettier, could also help.

Maybe it wouldn't be so hard to implement this 🤔 If one assumes that the existing code is indented correctly, the indent should be the same amount as the indent on the first line.

E.g. in the following image the indent should be 2 spaces, since there are two spaces before the first character on the first line
image

What do you think about an auto-indent feature implemented this way @yatki ? Should I try to implement this? 😊

Hey @Sti2nd thank you very much for your message. Did you also experience the same issue? Because it's not an issue with most people. Vs code is able to preserve the indentation automatically.. Could you please record your screen to show me how it happens? Also are you using tab characters or whitespace for tabs? I actually tested the extension with both settings and it was working fine.

If we can determine the root cause of the problem first, I'd appreciate any contribution 🤓👍🏻

@yatki Here is a video!

indentation_bug.mp4

2 whitespace is the indent in the video. I actually have this code in a Dev container so if you can't reproduce I could share the repo with you 🙂

Thank you very much for your efforts.. Much appreciated. Now i see the problem. So basically when i surround my code blocks i usually only select the text not the whitespaces before the line.. (whitespaces before const in your case). So i never experienced this problem. 😁😅

Maybe if you have time you can try to come up with a solution.. It might not be as straightforward as you think tho because vscode applies the changes on selected text.. There are modifiers for SELECTED_TEXT variable. Maybe you can look into those.. https://code.visualstudio.com/docs/editor/userdefinedsnippets#_transform-examples

If you don't have time no worries.. I'll look into it this week otherwise. 🖖🏻

I won't have time before the weekend, I think. I will post here if I begin to look into it! 😊 Otherwise you can just go ahead and fix it if you have time before me ✌️ 😁

The issue is resolved in version 1.2.0. Thanks for reporting the issue.

The release is available on:

Cheers 🖖,

Thank you, yatki! Good work! 🥇 👏

I think this bug came back @yatki ? Can you reproduce?

@Sti2nd which version are you using? Could you please share the code that you are trying to surround?

Version 1.2.2.

Here is a video

UserRoutes.ts.-.workspace.Dev.Container_.Node.js.PostgreSQL.-.Visual.Studio.Code.2021-09-16.20-23-32.mp4

@Sti2nd this is very weird. I am not able to reproduce this issue. Are you using tabs or spaces as whitespace?

Using spaces @yatki , but it doesn't make any difference 🤷

That is super weird. I wrote an exact copy of your code just to see if there is a weird character or something that prevents it but it works like a charm in mac and windows..

I assume you are using the latest version of vscode right? Did you try it in different files or on different code blocks? What is the encoding of the file?

The only problem I can think of a hidden character is messing up the whitespace. Because the script is trimming all the whitespace until the first non-whitespace char. And puts the surrounding block in that position. If trimming fails, the problem you are having would happen.

So maybe highlighting whitespace chars as "." could help you to identify the problem.

Let me know if this helps.. @Sti2nd

Tried in another project as well since I thought it might be because of the DEV container environment, but got the same result in a "regular" TS project. I will try to make time to test in different environments, but can't promise anything.

I have VS Code 1.62.0 User setup; extension is v1.2.2; input language in Windows is set to English with Norwegian keyboard.
When you try to reproduce you mark the whole line from the beginning of the window, right, and not only the beginning of the text inside the window.