Browse Source

Undo/Redo data structure memo in ASCII Art

pull/57/head
Eugenio Parodi 4 years ago
parent
commit
4b60bfa5cf
  1. 36
      TermTk/TTkGui/textdocument.py

36
TermTk/TTkGui/textdocument.py

@ -52,19 +52,21 @@ class TTkTextDocument():
[ s01, s12, s23, s34 ] [ s01, s12, s23, s34 ]
Data Structure Data Structure
Snap:
s0 . . . . . . . . .s3 Snapshot B > Snapshot C
cursor = c0 cursor = c3
next = d01 next = d34 _nextDiff _nextDiff > Next snapshot
prev = None prev = d32 _prevDiff _prevDiff or Null if at the end
Diff: V A V V
d01 d34
snap = s1 snap = s4 Diff B->A Diff B->C Diff C->B
d10 d32 slice = txtBA slice = txtBC slice = txtBA
snap = s0 snap = s2 snap snap snap
''' '''
class _snapDiff(): class _snapDiff():
''' '''
@ -75,10 +77,14 @@ class TTkTextDocument():
0 f2 t2 l2 = l1 - (t1-f1) + (t2-f2) 0 f2 t2 l2 = l1 - (t1-f1) + (t2-f2)
''' '''
__slots__ = ('_slice', '_i1', '_i2', '_snap') __slots__ = ('_slice', '_i1', '_i2', '_snap')
def __init__(self, doc, i1, i2, snap): def __init__(self, txt, i1, i2, snap):
self._slice = doc # The text slice required to change the current snap to the next one
self._slice = txt
# i1 are the num. of common lines from the starting between the 2 snaps
self._i1 = i1 self._i1 = i1
# i1 are the num. of common lines from the ending between the 2 snaps
self._i2 = i2 self._i2 = i2
# This is the link to the next _snapshot structure
self._snap = snap self._snap = snap
class _snapshot(): class _snapshot():

Loading…
Cancel
Save