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

Adjust Automatic Date Updates to Run on Save #222

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

farmerau
Copy link
Contributor

@farmerau farmerau commented Jan 6, 2022

Description

Per #221 , on-change events can be triggered twice due to the implementation of the change detection logic.

This is caused by gray-matter appending a newline character when rendering front matter content when the original file doesn't have a newline character, per: https://github.com/jonschlinkert/gray-matter/blob/master/lib/stringify.js#L51 . This is out of user control, which means that in all cases the extension will double-update the last modified property.

The effort here removes the change detection logic altogether, instead using the onWillSaveTextDocument event as a proxy for when we should automatically update the last modified date. This is similar to how a file system might update the last modified property of the file on the file system, which makes sense.

Testing

  • I validated that the new logic updates the last modified property as expected on save, when the auto-update setting is enabled.
  • I validated that the new logic continues to not update the last modified property as expected when the setting is disabled.
  • I validated that other features that update the article continue to function (like editing the title or description in the document)

@farmerau farmerau changed the base branch from main to dev January 6, 2022 20:30
@farmerau farmerau force-pushed the onWillSaveTextDocument branch 2 times, most recently from 3cf92bc to 21d5056 Compare January 6, 2022 20:42
Prefers `onWillSaveTextDocument` over `onDidChangeTextDocument` for the triggering event.
@estruyf estruyf merged commit a6dcc1e into estruyf:dev Jan 7, 2022
@estruyf
Copy link
Owner

estruyf commented Jan 7, 2022

Thanks @farmerau this is amazing! Great work! I've also included a check to exclude the new line when it is added by gray matter. This completes the whole functionality.

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.

2 participants