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

Dirty status change event #324

Closed
flaub opened this issue Jul 1, 2011 · 11 comments
Closed

Dirty status change event #324

flaub opened this issue Jul 1, 2011 · 11 comments
Assignees

Comments

@flaub
Copy link

flaub commented Jul 1, 2011

I'm currently approximating when a document is dirty by digging into the undo manager and checking if hasUndo() is true. It would be more convenient to have a 'changeDirty' event fire whenever the document changes from having edits since the last load.

It also appears that the 'change' event is firing out to embedder's code before the internal library has a chance to finish processing the event. My hack right now is to use a timer. How about having internal vs public events?
@Gissues:{"order":64.59627329192563,"status":"backlog"}

@paulb777
Copy link
Contributor

I second the vote for a public 'isDirty' API for a document session.

@flaub - I'm not sure your hack works. What if a file save is done in the middle of a series of edits? The undo stack will no longer be in sync with dirty. My hack is to set dirty to true on an onchange event.

                    env.editor.getSession().on('change', function() {
                        session.dirty = true;
                    });

and clear it on file save.

Of course, this doesn't cover the case of making changes and undoing back to the last save.

@flaub
Copy link
Author

flaub commented Jul 12, 2011

Agreed that my approach probably doesn't cover all cases, however my hack involves doing a reset() on the undo manager whenever a file save happens. The downside with that is the user can't undo to a time before the last save.

@flaub flaub closed this as completed Jul 12, 2011
@flaub
Copy link
Author

flaub commented Jul 12, 2011

Ugh, I really didn't mean to close this issue...

@flaub flaub reopened this Jul 12, 2011
@iebuggy
Copy link
Contributor

iebuggy commented Jul 16, 2011

paulb777 's approach is the correct one. ACE already exposes enough functionality for this. I take it a step further and keep the original content around and then compare the current session's getValue() to the internally stored value. I then display an indicator to the user that the content has changed from the original. Notice how each of us took a different approach to this - that is the flexibility of ACE at work. To implement any one of our isdirty solutions in ACE itself would force one of our views onto future developers who would then take issue with the change.

@flaub
Copy link
Author

flaub commented Jul 16, 2011

iebuggy: If I understand correctly, that means every change (or keyboard event), you'll do a comparison of the entire text? That seems awfully inefficient. Will that scale very well? As the content grows, so will the loop required to compare.

@ghost ghost assigned fjakobs Jul 23, 2011
@iebuggy
Copy link
Contributor

iebuggy commented Jul 27, 2011

For my needs, I'm not expecting more than a few KB of text and modern hardware can handle that without any issues. All of my tests show similar performance and one of my pet peeves is tying faster than the computer can process. So while I understand your concern, it is a non-issue. The first non-matching character will terminate the comparison anyway so the worst case is - someone on ancient hardware gets annoyed, goes to the start of the document, plants a random character there, and then resumes editing.

@fjakobs
Copy link
Contributor

fjakobs commented Jul 28, 2011

The undo manager could track this. It is basically just a check if then redo pointer is at the beginning of the undo stack.

@kagiasoldaccount
Copy link

I would like to see this implemented for three reasons:

  1. The use case is common, to the point it's obligatory to any implementation that has a considerable post processing dependency i.e ajax, io, compilation etc.
  2. It will prevent people from trying to guess how to do it, some of the suggestions posted here are woefully inefficient and others incorrect.
  3. It will only increase the API by a single property.

@nightwing
Copy link
Member

@kagia UndoManager now provides isClean() and markClean() methods.
you can do

editor.on("input", function() {
    // input is async event, which fires after any change events
    var isClean = editor.session.getUndoManager().isClean();
    // do something ...
})

@kagiasoldaccount
Copy link

@nightwing thanks!

shaban added a commit to shaban/DefinitelyTyped that referenced this issue Jun 24, 2015
Add isClean and markClean methods.
Reference ajaxorg/ace#324
@vanillajonathan
Copy link
Contributor

The isClean() and markClean() methods are undocumented.

UndoManager.markClean() is undocumented #2719
UndoManager.isClean() is undocumented #2715

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

No branches or pull requests

7 participants