Files
test-repo/changelog_unreleased/javascript/10938.md
T
Jed Fox 261bb0314f Fix repositioning the cursor at the end of a range format (#10938)
* Adjust the upper bound on cursorOffset when range formatting

* fix implementation

* Add changelog entry

* Update changelog entry to use PR number
2021-05-24 02:49:49 +09:00

694 B
Raw Blame History

Track cursor position properly when it’s at the end of the range to format (#10938 by @j-f1)

Previously, if the cursor was at the end of the range to format, it would simply be placed back at the end of the updated range. Now, it will be repositioned if Prettier decides to add additional code to the end of the range (such as a semicolon).

// Input (<|> represents the cursor)
const someVariable = myOtherVariable<|>
// range to format:  ^^^^^^^^^^^^^^^

// Prettier stable
const someVariable = myOtherVariable;<|>
// range to format:  ^^^^^^^^^^^^^^^

// Prettier main
const someVariable = myOtherVariable<|>;
// range to format:  ^^^^^^^^^^^^^^^