Gin
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
TextHistory Class Reference

Undo/redo history management for text editing with efficient diff-based storage. More...

#include <gin_texthistory.h>

Public Member Functions

void setHistoryLimit (int numItems)
 
void undo ()
 
void redo ()
 
bool canUndo ()
 
bool canRedo ()
 
bool addText (const juce::String &)
 
const juce::String & getCurrentText ()
 

Public Attributes

std::function< void()> onStateChanged
 

Detailed Description

Undo/redo history management for text editing with efficient diff-based storage.

TextHistory provides unlimited undo/redo functionality for text documents using a diff-based approach (binary patches) for memory-efficient storage. Instead of storing complete text snapshots, only the differences between states are stored.

Key Features:

The implementation uses binary diff patches (forward and backward) to efficiently store changes, making it suitable for large documents or long editing sessions.

Usage:

history.setHistoryLimit(100); // Keep last 100 changes
// Register for state changes
history.onStateChanged = []() {
DBG("History state changed");
};
// Add text changes
history.addText("Initial text");
history.addText("Modified text");
history.addText("Final text");
// Undo changes
if (history.canUndo())
{
history.undo();
juce::String text = history.getCurrentText(); // Returns "Modified text"
}
// Redo changes
if (history.canRedo())
{
history.redo();
juce::String text = history.getCurrentText(); // Returns "Final text"
}
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
Undo/redo history management for text editing with efficient diff-based storage.
Definition gin_texthistory.h:65

Implementation Details:

See also
juce::UndoManager for alternative undo/redo approach

Member Function Documentation

◆ setHistoryLimit()

void TextHistory::setHistoryLimit ( int  numItems)

◆ undo()

void TextHistory::undo ( )

◆ redo()

void TextHistory::redo ( )

◆ canUndo()

bool TextHistory::canUndo ( )

◆ canRedo()

bool TextHistory::canRedo ( )

◆ addText()

bool TextHistory::addText ( const juce::String &  )

◆ getCurrentText()

const juce::String & TextHistory::getCurrentText ( )

Member Data Documentation

◆ onStateChanged

std::function<void ()> TextHistory::onStateChanged

The documentation for this class was generated from the following file: