< Summary

Information
Class: Chronicis.Client.Utilities.DrawingCanvasUndoRedo
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Utilities/DrawingCanvasUndoRedo.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 44
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Undo(...)100%22100%
Redo(...)100%22100%
AddStroke(...)100%11100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Utilities/DrawingCanvasUndoRedo.cs

#LineLine coverage
 1namespace Chronicis.Client.Utilities;
 2
 3/// <summary>
 4/// Models the undo/redo stroke stack behavior of the drawing canvas.
 5/// Strokes are stored in a list; redo items in a separate stack.
 6/// Undo: pop last stroke from strokes → push to redoStack.
 7/// Redo: pop from redoStack → push to strokes.
 8/// </summary>
 9public static class DrawingCanvasUndoRedo
 10{
 11    /// <summary>
 12    /// Performs an undo operation: removes the last stroke and returns it as a redo candidate.
 13    /// Returns null if strokes is empty.
 14    /// </summary>
 15    public static T? Undo<T>(List<T> strokes, Stack<T> redoStack)
 16    {
 48717        if (strokes.Count == 0) return default;
 48518        var stroke = strokes[^1];
 48519        strokes.RemoveAt(strokes.Count - 1);
 48520        redoStack.Push(stroke);
 48521        return stroke;
 22    }
 23
 24    /// <summary>
 25    /// Performs a redo operation: pops from redo stack and appends to strokes.
 26    /// Returns null if redoStack is empty.
 27    /// </summary>
 28    public static T? Redo<T>(List<T> strokes, Stack<T> redoStack)
 29    {
 38730        if (redoStack.Count == 0) return default;
 38531        var stroke = redoStack.Pop();
 38532        strokes.Add(stroke);
 38533        return stroke;
 34    }
 35
 36    /// <summary>
 37    /// Adds a stroke and clears the redo stack (new input invalidates redo history).
 38    /// </summary>
 39    public static void AddStroke<T>(List<T> strokes, Stack<T> redoStack, T stroke)
 40    {
 795641        strokes.Add(stroke);
 795642        redoStack.Clear();
 795643    }
 44}