Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching to Visual Editor mode unconditionally reports the file as dirty if files.insertFinalNewline is on #582

Open
DavisVaughan opened this issue Oct 22, 2024 · 0 comments

Comments

@DavisVaughan
Copy link
Collaborator

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:

const editorMarkdown = await visualEditor.init(markdown, initialNav);
if (editorMarkdown && (editorMarkdown !== document.getText())) {
await updateWorkspaceDocument(document, editorMarkdown);
}

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.

Screen.Recording.2024-10-22.at.2.39.21.PM.mov
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

No branches or pull requests

1 participant