adventuregamestudio / ags

AGS editor and engine source code
Other
701 stars 160 forks source link

Editor: saving script flushes Undo buffer #462

Closed ghost closed 6 years ago

ghost commented 6 years ago

Steps to reproduce (from user):

I noticed that Undo tool button is active, but pressing it does nothing and it gets disabled afterwards.

ghost commented 6 years ago

Following code might be related to the issue:

https://github.com/adventuregamestudio/ags/blob/ags3/Editor/scintilla/src/CellBuffer.h#L129

/// The save point is a marker in the undo stack where the container has stated that
/// the buffer was saved. Undo and redo can move over the save point.
void SetSavePoint();
ghost commented 6 years ago

Nevermind above. I think I found what may be the cause of this problem

This is how Scintilla control determines whether Undo is allowed:

case SCI_CANUNDO:
        return (pdoc->CanUndo() && !pdoc->IsReadOnly()) ? 1 : 0;

Note the IsReadOnly() check.

Apparently Editor sets Scintilla in Read-only mode when it makes a save: https://github.com/adventuregamestudio/ags/blob/ags3/Editor/AGS.Editor/Panes/ScintillaWrapper.cs#L468

public void SetSavePoint()
{
    this.scintillaControl1.SetSavePoint();
    this.scintillaControl1.IsReadOnly = true;
}

But does not unset it until certain actions (like typing).

jeancallisti commented 6 years ago

Hurray for your god-like efficiency!

ghost commented 6 years ago

Well, there is still a question of how to fix this. Why does Editor put text control in the readonly mode anyway? Is it to protect it during saving/compilation process? If so, perhaps the proper solution is to put it back to writeable mode after all operations are completed.

ghost commented 6 years ago

Hmm, "resolves" keyword failed for some reason. Anyway, this was fixed by #467.