-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
Fix auto-indent on paste, second line and after #83386
base: main
Are you sure you want to change the base?
Fix auto-indent on paste, second line and after #83386
Conversation
The failing integration tests are due to an unrelated network issue in the CI pipeline itself, it seems. |
I've been trying to find a reliable way to reproduce the issue that this PR attempts to fix. On a clean install with default settings (
Notably, in this example the editor's default tab size At the beginning of With the proposed change in this PR, the paste produces the expected result: <div>
test
</div> I hope that helps clarify the issue and the motivation/aim of the PR. For more reported examples, please see issue #32320. EDIT: I found that the proposed change in this PR is not the right solution (yet). If the pasted block is itself indented, the change will remove it.. This: <div>
test
</div> ..when pasted becomes: <div>
test
</div> So, I'll need to rethink this - I had a feeling this "solution" was too simple to be true. :) It seems the check needs to be relative to the starting indent size of the pasted block. OK, I believe I got it - please see next commit. |
Nope, those commits are not correct either. OK, I'll continue trying to solve this. |
@eliot-akira thanks for your contribution and great effort! I love reading your thoughts and analysis into this problem and indeed it's really hard. May I ask what's the current state of this pr now? |
@rebornix Thank you for reading over this prior effort. To be honest, during the last few commits I wasn't sure anymore if I was going in the right direction. I think this PR is too out of date to pursue further, and can be closed. But, I believe it was getting closer to the crux of the issue (at least a variant of it), that it's related to the logic of "reindent second line and after". |
This PR fixes #32320, fixes #31255.
In the method
AutoIndentOnPaste.trigger
, there's a logic to re-indent pasted lines based on editor tab/indent size (and optionallyeditor.detectIndentation
). At the end of that calculation is a loop that re-indents the second line and after: it was adding unnecessary indents if any of the original lines had no indentation.To illustrate, pasting the following:
..was resulting in:
The only way for the user to fix this when it happened, was to undo once after pasting.
This PR adds a check to handle that case, by not adding indent if a pasted line had no indent to start with. In the above example, that's the third line.
It was somewhat tricky to reproduce the issue - although many people have reported variations of the symptoms in HTML, CSS, JS, etc. The common precondition seems to be when the tab/indent sizes detected for the document are different from the ones detected from the pasted lines. That leads to the loop that re-indents the second line and after.