Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Negative values in column's width redistribution #27616
Comments
Hey @tellthemachines and @gziolo, I saw that you two had worked in this area somewhat recently with the PR for fixing some unit tests. I was wondering if you two had enough context here to review @lukewalczak's plan. |
I don’t know how |
@gziolo thanks for your answer, I'm planning to prepare the PR with the fix along with additional test to cover edgy cases |
Describe the bug
During the sanity testing before mobile release @chipsnyder noticed that we are able to get negative percentages in
Columns
and mentioned about it in the comment. Since the logic for width redistribution is shared the same occurs on web editor.To reproduce
Steps to reproduce the behavior:
Result:
With those numbers I got: 73.34%, -6.66% and 33.33%.
The same will happen when adding new column to the following columns:
90/5/5
and many other.The problem is the wrong math within the function called
getRedistributedColumnWidths
located in columns utils.Mentioned method is assuming that difference (difference between available width and new columns width sum) is divided equally between columns and subtracted from each of them. As a result we can get negative values, since adjustment has higher value than width.
Let's consider it on the example from reproduction steps:
availableWidth
refers to the sum of first two columns after adding the third one: 66.67 (100 - 33)total width
refer to the sum of all columns: 100difference
is -33.33 (66.67 - 100)adjustment
is -16.665 (-33.33 / 2)Finally we have
Possible problem solution
Imo the mechanism should be a bit different and width should be calculated proportionally to the totalWidth:
As a result we get positive values, divided proportionally:
Expected behavior
Columns shouldn't have negative width values
Screenshots
Attached above.
If applicable, add screenshots to help explain your problem.
Editor version (please complete the following information):
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context