namespace Terminal.Gui.Views; /// /// Event arguments for item events. Used by and . /// /// /// This class encapsulates information about changes to text, such as the affected lines, cursor positions, and the type of change. /// It is primarily used to support undo/redo functionality in text editing controls like and . /// public class HistoryTextItemEventArgs : EventArgs { // TODO: these should all be properties /// /// Gets or sets the cursor position at the time of the change. /// public Point CursorPosition; /// /// Gets or sets the final cursor position after the change is applied. /// public Point FinalCursorPosition; /// /// Gets or sets a value indicating whether the change is part of an undo operation. /// public bool IsUndoing; /// /// Gets or sets the lines of text affected by the change. /// /// /// Each line is represented as a list of objects, which include the text and its attributes. /// public List> Lines; /// /// Gets or sets the status of the line(s) affected by the change. /// /// public TextEditingLineStatus LineStatus; /// /// Gets or sets the associated for a removed line when an added line replaces it. /// /// /// This property is used to track the relationship between added and removed lines during undo/redo operations. /// public HistoryTextItemEventArgs? RemovedOnAdded; /// /// Initializes a new instance of the class with the specified lines, cursor position, line status, and associated removed line. /// /// The lines of text affected by the change. /// The cursor position at the time of the change. /// The status of the line(s) affected by the change. /// The associated for a removed line when an added line replaces it. public HistoryTextItemEventArgs (List> lines, Point curPos, TextEditingLineStatus linesStatus, HistoryTextItemEventArgs removedOnAdded) { Lines = lines; CursorPosition = curPos; LineStatus = linesStatus; RemovedOnAdded = removedOnAdded; } /// /// Initializes a new instance of the class by copying an existing instance and associating it with a removed line. /// /// The existing to copy. /// The associated for a removed line when an added line replaces it. public HistoryTextItemEventArgs (HistoryTextItemEventArgs historyTextItem, HistoryTextItemEventArgs removedOnAdded) { RemovedOnAdded = removedOnAdded; Lines = [.. historyTextItem.Lines]; CursorPosition = new Point (historyTextItem.CursorPosition.X, historyTextItem.CursorPosition.Y); LineStatus = historyTextItem.LineStatus; } /// /// Initializes a new instance of the class with the specified lines, cursor position, and line status. /// /// The lines of text affected by the change. /// The cursor position at the time of the change. /// The status of the line(s) affected by the change. public HistoryTextItemEventArgs (List> lines, Point curPos, TextEditingLineStatus linesStatus) { Lines = lines; CursorPosition = curPos; LineStatus = linesStatus; } /// /// Initializes a new instance of the class by copying an existing instance. /// /// The existing to copy. public HistoryTextItemEventArgs (HistoryTextItemEventArgs historyTextItem) { Lines = [.. historyTextItem.Lines]; CursorPosition = new Point (historyTextItem.CursorPosition.X, historyTextItem.CursorPosition.Y); LineStatus = historyTextItem.LineStatus; } /// /// Returns a string representation of the instance. /// /// A string containing the count of lines, cursor position, and line status. public override string ToString () { return $"(Count: {Lines.Count}, Cursor: {CursorPosition}, Status: {LineStatus})"; } }