Alert user before closing tab with unsaved changes #108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Prompt user with a native confirmation dialog when they are closing a file that has unsaved changes.
Solution:
We had a CodeMirror plugin already in place to update the content on a class property so the place to send a signal about code change was already in place.
Since we instantiate the
CodeMirrorEditor
instance through choo's cache, we can't pass a callback through parameters so we need to do a method overwrite. I thought it would be natural to call itonChange
and be called without arguments.On the
store.js
file, we instantiate a new file when we start the app and when we open a file. I overwrote the defaultonChange
method by a local function that sets the file object propertyhasChange
totrue
and calls for a screen re-render.The
hasChanges
property won't compare previous and current content of the tab but if the file has received any new input, it will trigger there are changes if you write and erase what you wrote.