private void StopEditing(bool finalize) { imContext.ClientWindow = null; if (!PintaCore.Workspace.HasOpenDocuments) { return; } if (!is_editing) { return; } is_editing = false; //Make sure that neither undo surface is null, the user is editing, and there are uncommitted changes. if (text_undo_surface != null && user_undo_surface != null && CurrentTextEngine.State == TextMode.Uncommitted) { Document doc = PintaCore.Workspace.ActiveDocument; RedrawText(false, true); //Start ignoring any Surface.Clone calls from this point on (so that it doesn't start to loop). ignoreCloneFinalizations = true; //Create a new TextHistoryItem so that the committing of text can be undone. doc.History.PushNewItem(new TextHistoryItem(Icon, Name, text_undo_surface.Clone(), user_undo_surface.Clone(), undo_engine.Clone(), doc.CurrentUserLayer)); //Stop ignoring any Surface.Clone calls from this point on. ignoreCloneFinalizations = false; //Now that the text has been committed, change its state. CurrentTextEngine.State = TextMode.NotFinalized; } RedrawText(false, true); if (finalize) { FinalizeText(); } }