microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.1k stars 29.26k forks source link

Document scroll width is not calculated when shortening lines #169485

Open aarondill opened 1 year ago

aarondill commented 1 year ago

Does this issue occur when all extensions are disabled?: Yes

VSCode Version: 1.74.1 OS: Linux x64 5.10.147-20158-g0a75306e5639

Steps to Reproduce:

  1. Create a document with contents such as:
    
    // This is a longer comment that will cause the issue to be revealed when more text is typed, expanding the width. 

// A short comment <above line but about 30 more times>


2. Reopen the document to recalculate original length.
3. Notice scroll width is only sufficient to show longest line of code.
4. Type more text on line 1 until scroll width is increased
5. remove your newly typed code so the entire line fits on screen
6. notice the scroll width does not decrease
7. click enter to recalculate scroll width

## Expected outcome:
Scroll width is updated on line width shrinking as it are on growth, thereby reducing the scroll width

## Actual outcome:
Scroll width is not update until a line is added or remove or the editor is reopened. Even saving doesn't recalculate the scroll width.

## Notes:
* This is also an issue with line decorations, since they modify the length of the line. When a long line decoration is added, then later removed, the scroll width is not updated.
* This does not seem to be an issue in extremely short files. It is slightly inconsistent, however a file with less than 10 lines seems almost guaranteed to function in the expected way.
tjx666 commented 1 year ago

https://user-images.githubusercontent.com/41773861/208291040-40a01d1c-eb0f-44fe-9fe2-ddb3420e9d38.mov

vscodenpa commented 1 year ago

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

tjx666 commented 1 year ago

@alexdima I think this is a bug, not a feature request

alexdima commented 1 year ago

I understand your expectation and I acknowledge it, but the current implementation is to:

The reason for this implementation is that lines are virtualised. We don't implement text layouting and font rendering ourselves in the editor, but we delegate that to the browser. So we actually don't know the width of all the lines in the file, we only know the width of the lines which are rendered / visible at a particular time. That is why I've classified this as a feature request, the current (very fast) implementation does its job as designed. It is a technical limitation, but one which comes with a lot of perf advantages, that the scroll width is always growing and not reflecting 100% correctly the max line width.

vscodenpa commented 1 year ago

:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!