Undo terminalsplit

How to implement an “undo” feature for text splitting operations?

Approach

Store the original string along with split information:

class TerminalSplit:
    def __init__(self, text):
        self.original = text
        self.parts = text.split()
    
    def undo(self):
        return self.original
    
    def redo(self):
        return ' '.join(self.parts)

Usage

ts = TerminalSplit("hello world from python")
print(ts.parts)  # ['hello', 'world', 'from', 'python']
print(ts.undo()) # "hello world from python"

This pattern is useful for implementing reversible text operations.