Skip to content

Commit

Permalink
Add changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jan 12, 2023
1 parent e1ffc44 commit 524f648
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions changelog_unreleased/javascript/14163.md
@@ -0,0 +1,20 @@
#### Fix cursor tracking inside JSX Text (#14163 by @fisker)

<!-- prettier-ignore -->
```console
// Prettier stable
require("prettier").formatWithCursor(
["<>a", " <div>hi</div>", "</>"].join("\n"),
{ cursorOffset: 3, parser: "babel" }
).cursorOffset;

// -> 2

// Prettier main
require("prettier").formatWithCursor(
["<>a", " <div>hi</div>", "</>"].join("\n"),
{ cursorOffset: 3, parser: "babel" }
).cursorOffset;

// -> 6
```
1 change: 1 addition & 0 deletions src/language-js/print/jsx.js
Expand Up @@ -239,6 +239,7 @@ function printJsxElementInternal(path, options, print) {

/*
`printJsxChildren` won't call `print` when child "isLiteral" (Maybe only `JSXText`?)
When the cursorNode is inside `cursor` won't get print.
*/
if (
isLiteral(options.cursorNode) &&
Expand Down
1 change: 1 addition & 0 deletions tests/format/jsx/cursor/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -10,6 +10,7 @@ printWidth: 80
<>a<|>
<div>hi</div>
</>
=====================================output=====================================
<>
a<|><div>hi</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/format/jsx/cursor/in-jsx-text.js
@@ -1,3 +1,3 @@
<>a<|>
<div>hi</div>
</>
</>
2 changes: 1 addition & 1 deletion tests/format/jsx/cursor/jsfmt.spec.js
@@ -1 +1 @@
run_spec(__dirname, ["babel", "typescript", "flow"]);
run_spec(__dirname, ["babel", "typescript", "flow"]);

0 comments on commit 524f648

Please sign in to comment.