TTkTextDocument🌢️

class TTkTextDocument(*, text: TTkString = ' ')[source]🌢️

Bases: object

Undo,Redo Logic

Old:

_snapshotId: = last saved/undo/redo state
                       3 = doc4
_snapshots:
    [doc1, doc2, doc3, doc4, doc5, doc6, . . .]

New:

SnapshotId:
                  2
Snapshots:                  _lastSnap     _dataLines (unstaged)
    ╒═══╕ ╒═══╕ ╒═══╕ ╒═══╕ ╒═══╕         ╒═══╕
    β”‚ 0 β”‚ β”‚ 1 β”‚ β”‚ 2 β”‚ β”‚ 3 β”‚ β”‚ 4 β”‚         β”‚ 5 β”‚
    β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜         β””β”€β”€β”€β”˜
Cursors:
     c0,   c1,   c2,   c3,   c4 = _lastCursor
Diffs:
    [   d01,  d12,  d23,  d34   ] = Forward  Diffs
    [   d10,  d21,  d32,  d43   ] = Backward Diffs
Slices: = common txt slices between snapshots
    [   s01,  s12,  s23,  s34   ]
Data Structure
            ╔═══════════════╗                         ╔═══════════════╗
            β•‘   Snapshot B  β•‘          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β•‘   Snapshot C  β•‘
            β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’          β”‚              β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
            β•‘ _nextDiff     ║──────┐   β”‚              β•‘ _nextDiff     ║───> Next snapshot
        β”Œβ”€β”€β”€β•‘ _prevDiff     β•‘      β”‚   β”‚          β”Œβ”€β”€β”€β•‘ _prevDiff     β•‘  or Null if at the end
        β”‚   β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•      β”‚   β”‚          β”‚   β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
        V              A           V   β”‚          V
    ╔═══════════════╗  β”‚  ╔═══════════════╗   ╔═══════════════╗
    β•‘   Diff B->A   β•‘  β”‚  β•‘   Diff B->C   β•‘   β•‘   Diff C->B   β•‘
    β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’  β”‚  β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’   β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
    β•‘ slice = txtBA β•‘  β”‚  β•‘ slice = txtBC β•‘   β•‘ slice = txtBA β•‘
    β•‘ snap          β•‘  β”‚  β•‘ snap          β•‘   β•‘ snap          β•‘
    β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•  β”‚  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•   β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
                       β”‚                             β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Methods🌢️

appendText(text)[source]🌢️
changed()[source]🌢️
characterCount()[source]🌢️
hasSnapshots()[source]🌢️
isRedoAvailable()[source]🌢️
isUndoAvailable()[source]🌢️
lineCount()[source]🌢️
redo()[source]🌢️
restoreSnapshotNext()[source]🌢️
restoreSnapshotPrev()[source]🌢️
saveSnapshot(cursor)[source]🌢️
setChanged(c)[source]🌢️
setModified(m=True)[source]🌢️
setText(text)[source]🌢️
snapshootId()[source]🌢️
toAnsi()[source]🌢️
toPlainText()[source]🌢️
toRawText()[source]🌢️
undo()[source]🌢️

TTkTextDocument Attributes🌢️

contentsChange

contentsChanged

cursorPositionChanged

modificationChanged

redoAvailable

undoAvailable

undoCommandAdded