Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

🐛 Do not modify excess whitespace when modifying indentation#5658

Closed
driskell wants to merge 1 commit intoatom:masterfrom
driskell:bug/do_not_modify_excess_whitespace
Closed

🐛 Do not modify excess whitespace when modifying indentation#5658
driskell wants to merge 1 commit intoatom:masterfrom
driskell:bug/do_not_modify_excess_whitespace

Conversation

@driskell
Copy link
Contributor

This is a proposal for fixing #5642 and I'd welcome feedback on if this is the right approach or not?

The problem, is copying pasting PHPDoc code at an indented level, with hard tabs on, loses the asterisk alignment:

example

Root Cause

Seems inside Atom, in the case of encountering soft tabs in a hard tab file... it can return a floating point indentation level, such as 1.5 in this instance (tab+half-tab). When rebuilding the indentation (it calls setIndentationForBufferRow for each line), this calls @buildIndentString with 1.5 which gets converted to integer: 1. ALL leading whitespace is then replaced by this new indentation - so we lose the space that aligns the asterisk.

The tests seem to point to floating point indentation levels being allowed. Yet I can find nowhere where it is useful. Most places just Math.ceil(). And with hard tabs it doesn't even make sense.

This patch attempts to remove all the floating points (it leaves the Math.ceil calls - they're harmless and can be cleaned later if this turns out the right approach.). It then has a function for "modifying" whitespace to change its indentation level, while paying attention to straggling spacing like that in the PHPDoc comments in the image above. It also adds a couple API for handling indentation changes that can be used elsewhere.

Only thing I'm not too happy with is the overlap between my "setIndentLevelForRow" and the existing "setIndentationForBufferRow" - I'm sure mine follows correct naming convention but existing doesn't. It is the existing one that is called when pasting though.

@driskell
Copy link
Contributor Author

Edited to try reduce my usual walls of text :(

@driskell driskell changed the title WIP Proposal - 🐛 Do not modify excess whitespace when modifying indentation 🐛 Do not modify excess whitespace when modifying indentation Mar 11, 2015
@driskell
Copy link
Contributor Author

Hi @50Wliu I raise this as a proposed fix for #5642 - thanks.

@winstliu
Copy link
Contributor

@driskell driskell force-pushed the bug/do_not_modify_excess_whitespace branch from d9ea9b1 to 29be58e Compare April 4, 2015 14:07
@driskell
Copy link
Contributor Author

driskell commented Apr 4, 2015

Rebased onto master.

Please let me know if there is anything I can do to help with this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation: use is instead of ==. See this section of the contributing guide.

@izuzak
Copy link
Contributor

izuzak commented Apr 9, 2015

@driskell Thanks for submitting this PR. 🙇 I don't review PRs normally, but wanted to give it a shot here -- a 🏫 experience for me. 😄

I think @nathansobo will have more 💭 and 💡, but just wanted to say that I think these changes make sense overall.

@driskell
Copy link
Contributor Author

driskell commented Apr 9, 2015

Thanks @izuzak ! Appreciate the feedback and review!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised at how this method was counting tabs and spaces before -- just counting the number of spaces and tabs, regardless of where they're located. I think your approach in parseIndentation is much better. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it was surprising! I hope my method is better.

It also follows tab stops if there's spaces intermingled. I know mixed tab/space is REALLY bad anyway but it hopefully means indentLevelForLine returns nice correct numbers that match exactly the visual indentation we see, where as at moment it would be weird. For example "S\tS\t" would return 3 where visually it would actually be identical to "\t\t" which is 2 (assuming 2 space tab)

@driskell driskell force-pushed the bug/do_not_modify_excess_whitespace branch from 29be58e to df6f257 Compare April 12, 2015 19:22
@driskell
Copy link
Contributor Author

Again, thanks for the review @izuzak - I'll followed through and provided more info on the @modifyIndentLevelForRow logic.

@driskell
Copy link
Contributor Author

Not sure who to check with but wondering where this sits in the pipeline, if at all?

@izuzak
Copy link
Contributor

izuzak commented May 13, 2015

Sorry for the delay, @driskell. I believe @nathansobo wanted to look at this when he finds some time. 📟

@nathansobo
Copy link
Contributor

Thanks for taking the time to do this. It served as a jumping off point for a different fix in #7563, which reduces some of the complexity that led to this issue in the first place. Please let me know if there's something you think I missed with that fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants