Dirty status change event #324

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

Comments

Projects
None yet
7 participants

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"}

Contributor

paulb777 commented Jul 11, 2011

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 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 closed this Jul 12, 2011

flaub commented Jul 12, 2011

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

flaub reopened this Jul 12, 2011

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 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.

fjakobs was assigned Jul 23, 2011

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.

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.

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.
Member

nightwing commented Oct 29, 2014

@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 ...
})

nightwing closed this Nov 8, 2014

@shaban shaban added a commit to shaban/DefinitelyTyped that referenced this issue Jun 24, 2015

@shaban shaban Update ace.d.ts
Add isClean and markClean methods.
Reference ajaxorg/ace#324
39293fc

shaban referenced this issue in DefinitelyTyped/DefinitelyTyped Jun 24, 2015

Merged

Update ace.d.ts #4733

Contributor

vanillajonathan commented Oct 26, 2015

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

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

karino2 referenced this issue in karino2/editbook Dec 16, 2016

Closed

Support "modified' status #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment