quarto-dev / quarto-dev/quarto
Switching to Visual Editor mode unconditionally reports the file as dirty if `files.insertFinalNewline` is on
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 645
- Forks
- 62
- Avg merge
- 17h 42m
- Merged PRs (30d)
- 13
Description
The sync manager between the underlying text document and the webview has this nice feature where when you first switch to Visual Mode, it tries not to write an "edit" with applyEdit() if it looks like the document is already canonical:
The problem is, even if your document is in canonical form, if you have the incredibly common setting of "files.insertFinalNewline": true on, then it will still try and apply an edit, making your file look "dirty" and in need of a save after switching to visual mode. This always weirds me out, especially if I'm not using git in the project yet.
I believe that the canonical output emitted by visualEditor.init() trims off a "final" newline, which is why you get that diff no matter what you do. Is there any way that we can tweak that to allow a final newline to still be treated as something that is considered canonical? I think the idea would be to always push a final newline to the canonical text if one exists in the original document text.
https://github.com/user-attachments/assets/67a1add5-f497-405d-a1a1-50e47d300653
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/vscode/src/providers/editor/sync.ts around lines 132-135, then inspect the canonical output from visualEditor.init(). Reproduce switching to Visual Mode with files.insertFinalNewline enabled and compare documents that already end with a newline. Done means a canonical document with that setting does not receive an unnecessary edit or appear dirty.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100