Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't trim whitespace-only lines #801

Open
ValentinWalter opened this issue Sep 2, 2024 · 7 comments · May be fixed by #804
Open

Don't trim whitespace-only lines #801

ValentinWalter opened this issue Sep 2, 2024 · 7 comments · May be fixed by #804

Comments

@ValentinWalter
Copy link

The only thing holding me back from adopting swift-format is the inability to allow trailing whitespace in whitespace-only lines. This is my favorite Xcode feature!

image

Can we change PrettyPrinter to keep the surrounding context's indentation for empty lines, or would that be a breaking change? Can we add something that's based on a configuration to PrettyPrinter? I would love to get the ball rolling if someone can point me to the right place to implement this.

@ahoppen
Copy link
Member

ahoppen commented Sep 3, 2024

Synced to Apple’s issue tracker as rdar://135215957

@bnbarham
Copy link
Contributor

This is my favorite Xcode feature!

Out of interest, what's your use case for keeping whitespace on blank lines only?

@ValentinWalter
Copy link
Author

Out of interest, what's your use case for keeping whitespace on blank lines only?

I love being able to arrow down/up or click on empty lines that are already correctly indented. Makes the editing experience feel more "solid" if that makes sense.

@allevato
Copy link
Member

My personal feeling on this is that editors that want to provide that functionality should provide a "virtual cursor" where the user can navigate to a location outside the document's horizontal bounds, but only if they start typing there does it insert the spaces. (Naturally, that's out of scope for this project.)

Always inserting spaces to fill up otherwise blank lines just feels wasteful.

@TTOzzi
Copy link
Contributor

TTOzzi commented Sep 10, 2024

Always inserting spaces to fill up otherwise blank lines just feels wasteful.

I completely agree with this opinion.
However, in Xcode, if we turn off the Including whitespace-only lines option and perform automatic indentation (Command + I), it still inserts spaces according to the indent level even on empty lines.

In my opinion, if we would like the formatting to behave exactly like Xcode, it might be better to also insert spaces on empty lines according to the indent level. But if the intention is to reduce unnecessary actions, it may be more appropriate to only adjust lines that have incorrect amounts of whitespace to match the indent level. 🤔

@bnbarham
Copy link
Contributor

bnbarham commented Sep 11, 2024

IMO matching Xcode is a non-goal here. But if there's general interest for this in and of itself, we should definitely consider adding it. The next question there is whether we need both options ("remove trailing whitespace" and "indent blank lines"), or whether just the latter is enough. My preference would be just the latter.

My personal feeling on this is that editors that want to provide that functionality should provide a "virtual cursor"

I feel somewhat similar, though it's entirely possible that someone could be using very lightweight editors without this sort of feature. It would also mean that the editor has to understand how to indent (though maybe that's as simple as "match previous line").

@TTOzzi
Copy link
Contributor

TTOzzi commented Sep 19, 2024

I understand. Since the person who suggested the feature also needs blank line indentation, I'll implement that.
Thank you for your valuable input 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants