Skip to content

Fix trailing formatting edit when range ends mid-token - #50082

Merged
Andrew Branch (andrewbranch) merged 1 commit into
microsoft:mainfrom
andrewbranch:bug/50076
Jul 28, 2022
Merged

Andrew Branch (andrewbranch) merged 1 commit into
microsoft:mainfrom
andrewbranch:bug/50076

Conversation

@andrewbranch

Copy link
Copy Markdown
Member

Fixes #50076

// with a selection from the beginning of the line to the space inside the curly braces,
// inclusive. We would expect a format-selection would delete the space (if rules apply),
// but in order to do that, we need to process the pair ["{", "}"], but we stopped processing
// just before getting there. This block handles this trailing edit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This comment should have been included with #46875.

// produce bogus edits if we try to `processPair`. Recall that the point of this logic is
// to perform a trailing edit at the end of the selection range: but there can be no valid
// edit in the middle of a token where the range ended, so if we have a non-contiguous
// pair here, we're already done and we can ignore it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This comment describes the fix for this bug.

@jakebailey Jake Bailey (jakebailey) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, I'm always suspicious of the ! but they're at least consistent with the other side-effecty previous variables, so...

@andrewbranch

Copy link
Copy Markdown
Member Author

Yeah, it’s correlated with the existence of previousRange.

Comment on lines +451 to +452
// but in order to do that, we need to process the pair ["{", "}"], but we stopped processing
// just before getting there. This block handles this trailing edit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// but in order to do that, we need to process the pair ["{", "}"], but we stopped processing
// just before getting there. This block handles this trailing edit.
// but in order to do that, we need to process the pair ["{", "}"].
// This block handles this trailing edit by ensuring we continue processing.
// the pair of tokens that the range intersects.


if (tokenInfo) {
if (tokenInfo && tokenInfo.pos === previousRangeTriviaEnd!) {
// We need to check that tokenInfo and previousRange are contiguous: the `originalRange`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// We need to check that tokenInfo and previousRange are contiguous: the `originalRange`
// We need to check that previousRange and tokenInfo are contiguous since the `originalRange`

@andrewbranch
Andrew Branch (andrewbranch) merged commit b7355e3 into microsoft:main Jul 28, 2022
@andrewbranch
Andrew Branch (andrewbranch) deleted the bug/50076 branch July 28, 2022 19:12
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Format selection (and thus format-on-paste) causes destructive edits

4 participants