Skip to content

Conversation

@josephfrazier
Copy link
Collaborator

This partially address #1981

See #1981 (comment)

Since the `cursorOffset` option (introduced in prettier#1637) works by tracking
the cursor position relative to an AST node (rather than a CST token),
it can produce incorrect results.

See prettier#1981
const code = "return 15";
expect(prettier.formatWithCursor(code, { cursorOffset: 14 })).toEqual({
formatted: "return 15;\n",
cursorOffset: 14 // TODO fix this
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that the result offset is nevertheless outside the node, since the cursor is one space before the 15, so we still need something like #1983 (or maybe some logic that finds the "nearest" node to the cursor, rather than the smallest one containing the cursor).

@vjeux vjeux merged commit c863cbe into prettier:master Jun 6, 2017
@josephfrazier josephfrazier deleted the cursor-offset-node-granularity branch June 6, 2017 07:11
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 20, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants