-
-
Notifications
You must be signed in to change notification settings - Fork 506
Open
Labels
triage-pendingAwaiting initial triageAwaiting initial triage
Description
Problem
The extension currently uses Prettier's format() API, which causes the cursor to jump after formatting. This is a common user complaint and differs from the expected behavior of maintaining editing context.
Proposed Solution
Use Prettier's formatWithCursor() API instead of format(). This API accepts a cursorOffset option and returns both the formatted text and the adjusted cursor offset.
Current Implementation
// PrettierEditService.ts:format() (around line 622)
const formatted = await prettierInstance.format(text, options);Proposed Implementation
const cursorOffset = document.offsetAt(editor.selection.active);
const result = await prettierInstance.formatWithCursor(text, {
...options,
cursorOffset
});
// Use result.formatted for the text
// Use result.cursorOffset to restore cursor positionImpact
- User Experience: Major improvement - cursor stays in place during format-on-save
- Effort: Medium - requires changes to how
provideEdits()returns edits and potentially using VS Code'sWorkspaceEditwith cursor positioning
Relevant Files
src/PrettierEditService.ts-format()andprovideEdits()methodssrc/types.ts-PrettierInstanceinterface may needformatWithCursoradded
References
- Prettier API docs: https://prettier.io/docs/api#prettierformatwithcursorsource-options
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
triage-pendingAwaiting initial triageAwaiting initial triage