-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Automatic DateTime Updates are Triggered Twice When File Doesn't Have Trailing Newline #221
Comments
The trailing line is something I think VS Code adds for you in this case, so it will indeed trigger an update when you added your content, and VS Code adds the new line, which triggers it again.
Another way would be to disable the new line setting for markdown files. |
Yeah, the newline being appended by VS Code makes total sense. My concern, albeit minor, was that the newline being appended is being triggered by the extension, even if indirectly. Any change to the document triggers another If this isn't a concern, since it's certainly an edge case, I'm happy to close the issue. It's worth some thought, though, about whether or not |
@farmerau we could certainly try to update it to the I do not use this functionality myself, so never ran against this issue, but I can see what could go wrong if there are multiple extensions listening to changes. Although, this might be the same for the save event. |
Sure, that makes sense! I don't think the |
Let us give it a try! |
Cheers! I'll get a PR out! |
After doing some debugging, I learned that the newline is actually coming from gray-matter:
This would mean that there are no controls from VS Code that could prevent the newline from being appended, meaning that there would be no way for a user to prevent the double updates in the current state. I've opened a PR to run on save instead of on-change. |
I've merged your PR @farmerau, thanks again for the help on this one! 🙏 Included a check for the gray-matter new line as well. When the content does not contain a newline before the stringify function, it will remove it when included. Combined with your change, I think this will complete the issue. |
Released in |
Describe the bug
When
frontMatter.content.autoUpdateDate
is enabled and editing a document that doesn't have a trailing newline, the automatic date updates are triggered twice. This doesn't happen when the file does have a trailing new line. For example, after it updates twice (the newline is added for you), subsequent updates happen only once.To Reproduce
Steps to reproduce the behavior:
frontMatter.content.autoUpdateDate
is enabled.Expected behavior
I'd expect the lastmod field to be updated only once.
Screenshots
A gif which demonstrates the behavior:
VS Code Version
Extension Version
v5.9.0
Additional context
This is likely due to the autoupdate logic defined here:
vscode-front-matter/src/commands/Article.ts
Lines 243 to 265 in 4d38a08
One way to solve this might be to adjust the change detection logic, but this may introduce new bugs.
Another possible solution would be to do away with change detection entirely-- moving away from
vscode.workspace.onDidChangeTextDocument
toonWillSaveTextDocument
: https://code.visualstudio.com/api/references/vscode-api#3591 . This would move auto-updates to the pre-save lifecycle which would prevent the extension from updating the lastmod timestamp while the user is actively editing the document.The text was updated successfully, but these errors were encountered: