-
Notifications
You must be signed in to change notification settings - Fork 742
refactor: compute unsaved state from file hashes #1811
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
Conversation
TODO: make this consistent with removing/adding editors
dsanders11
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave it for a follow-up PR, but we should build on this to fix bugs with the gist uploading. Currently if you just spam the "Update" button you'll upload a bunch of empty revisions to the gist because we unconditionally do updates and GitHub is happy to take them as empty commits it appears.
We'll want to update src/renderer/components/commands-action-button.tsx to only do the initial revision after publishing if the content has changed from the default (edge case), and also only update the gist if the content has changed.
We can also disable the "Update" button depending on the isEdited state so that it's clear when you actually have changes to upload to the gist.
Motivation
In its current state, Fiddle marks the current document as "edited" as soon as a change is made when the saved state applies. This means there's no going back to a "Saved" state even if you Undo all your changes.
Solution
This PR saves a Map of SHA-1 hashes generated via
window.crypto.subtle.digestfor each file and derives theisEditedproperty via a getter function instead:This makes it so that:
isEditedstate is more intuitive to users (prior to this, it was just "was this untouched since the last saved state?")isEditedstate for each file individually.Reviewer notes
The diff here got pretty big, but the core logic just lives in
src/renderer/editor-mosaic.ts. Most of the diff follows from that:digestfunction is asynchronous, anything that sets editor contents is now anasyncfunction.There's just one big ugly hack where the save state gets loaded on a timeout because it's a bit tricky to properly wait for when all content is being properly stored and to figure out when to save the hash: