Skip to content

feat(editor): format pasted text by default - #334

Merged
fcoury-oai merged 1 commit into
mainfrom
fcoury/format-on-paste
Aug 23, 2026
Merged

fcoury-oai merged 1 commit into
mainfrom
fcoury/format-on-paste

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Pasting code currently preserves the clipboard text exactly, even when the active language server can safely format only the affected range. This adds opt-out format-on-paste behavior so pasted snippets adopt the surrounding document style without triggering an unrelated whole-document rewrite.

The editor now requests textDocument/rangeFormatting for the changed character range after terminal, normal/visual, block, and multi-cursor paste operations. Requests are only sent to language servers that advertise range-formatting support, are skipped for external whole-document formatters, and are guarded by the buffer revision so stale responses cannot overwrite newer edits.

Format on paste defaults to enabled and can be disabled with:

[formatting]
on_paste = false

How to Test

  1. Open a file backed by a language server that advertises range formatting and paste an unformatted snippet such as let value=1;. Confirm only the pasted range is formatted and the surrounding document remains unchanged.
  2. Set formatting.on_paste = false, repeat the paste, and confirm the clipboard text remains unchanged.
  3. Run cargo test paste and the pasted_text_is_formatted_by_a_range_capable_language_server test to cover normal, visual, block, multi-cursor, stale-response, and end-to-end LSP behavior.
  4. Run cargo clippy --all-targets --all-features -- -D warnings.

@fcoury-oai
fcoury-oai merged commit 73bd541 into main Aug 23, 2026
11 checks passed
@fcoury-oai
fcoury-oai deleted the fcoury/format-on-paste branch August 23, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant