Skip to content

Alert user before closing tab with unsaved changes #108

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

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

murilopolese
Copy link
Contributor

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 it onChange 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 default onChange method by a local function that sets the file object property hasChange to true 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.

@murilopolese murilopolese requested a review from ubidefeo April 15, 2024 12:35
Copy link
Collaborator

@ubidefeo ubidefeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected

@murilopolese murilopolese merged commit 54524d1 into development Apr 15, 2024
1 check passed
@murilopolese murilopolese deleted the feature/alert-unsaved branch April 15, 2024 15:28
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