TermTk.TTkGui.textdocument
TTkTextDocument
- class TTkTextDocument(*args, **kwargs)[source]
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 ║ ╚═══════════════╝ │ ╚═══════════════╝ ╚═══════════════╝
│ │ └─────────────────────────────┘