Element change logs for managing deltas, undo, and redo.
itertools
Protocol0
struct0
Summary0
Interface for communicating changes to lines and codepoints.
Used by Log.track to communicate change summaries for cursor motion and view stabilization.
SummaryEngineering
Implementing this using an abstraction that received changes the same way that a log's storage target does was not entirely trivial. Line deltas could be easily summarized, but reconstructing the codepoint deltas from Update.apply's usage required multiple levels of reconstruction.
Creating an explicit protocol is somewhat undiresable, but using an abstraction that required such tight coupling to Update.apply's implementation appeared inferior. Additionally, this provides a relevant location for checkpoint or commit reporting given the need.
Summaryline_delta10%
line_delta(self, ln_offset, deleted, inserted)
Summarycodepoint_delta10%
codepoint_delta(self, ln_offset, cp_offset, deleted, inserted)
Report that codepoints were deleted and inserted at cp_offset in the line identified by ln_offset.
Record0
An indvidial record of change.
Recordspan10%
The element offset and count of elements that were changed.
Recordchange10%
The change in the elements' length that occurred. Length of insertions minus length of deletions.
Recordusage20%
usage(self)
Memory usage of the record. The given count will measure an object's size if it hasn't already been seen.
Recordsize10%
size(self, encoding)
Change in bytes of the target resource after the record is applied.
Recordinvert10%
invert(self)
Construct the version of the record that reverses the effect of the change.
Recordrevert10%
revert(self)
Reconstruct self to perform an ineffective operation.
Recordtrack10%
track(self, target)
Communicate the change to target.
Recordapply10%
apply(self, target)
Perform the change to the given target.
Recordretract150%
retract(self, target)
Perform the inverse, restoring the target to the state that it was in prior to apply being performed.
Checkpoint0
A no-op change holding a creation timestamp.
Used to delimit Record groups for Log.undo and Log.redo.
Checkpointchange
Checkpointspan10%
Checkpointelement
element = None
Checkpointinsertion
insertion = None
Checkpointdeletion
deletion = None
Checkpointusage0
usage(self)
Checkpointinvert0
invert(self)
Checkpointtrack10%
track(self, target)
Checkpointapply0
apply(self, target)
Checkpointretract10%
retract(self, target)
Checkpointrevert10%
revert(self)
Checkpointcombine233%
combine(self, following)
Update0
Individual record update.
Updatechange10%
Change in elements. Always zero for Update.
Updatespan10%
Updateusage0
usage(self)
Updatesize10%
size(self, encoding)
Updateinvert0
invert(self)
Recreate the record where insertion and deletion are swapped.
Updatetrack70%
track(self, target)
Updateapply0
apply(self, target)
Updateretract40%
retract(self, target)
Updaterevert60%
revert(self)
Updatecombine770%
combine(self, following)
Construct a new Update instance by combining self with following. None when following cannot be combined with self.
Lines0
Insertion and/or deletion of zero or more elements.
Lineschange10%
Linesspan166%
Linesusage0
usage(self)
Linessize175%
size(self, encoding)
Linesinvert0
invert(self)
Recreate the record where insertion and deletion are swapped.
Linestrack70%
track(self, target)
Linesapply0
apply(self, target)
Linesretract340%
retract(self, target)
Linesrevert60%
revert(self)
Linescombine0
combine(self, following)
Cursor0
Change
Cursorchange10%
Cursorspan166%
Cursorusage0
usage(self)
Cursorsize0
size(self, encoding)
Cursorinvert20%
invert(self)
Recreate the record where insertion and deletion are swapped.
Cursortrack80%
track(self, target)
Cursorapply166%
apply(self, target)
Cursorretract166%
retract(self, target)
Cursorcombine
combine(self, following)
Log0
The Record vector tracking the changes.
Log__init__0
__init__(self)
Logrevert30%
revert(self, target)
Retract all committed changes on target.
Logtruncate0
truncate(self)
Logsize20%
size(self, encoding)
Total size of the logged changes.
Logusage271%
usage(self)
Logsnapshot0
snapshot(self)
Construct a reference to the current version.
Logsince378%
since(self, snapshot)
Generate a sequence of changes since version.
Logwrite0
write(self, record)
Append a delta to the log.
Logpending20%
pending(self)
Return the uncommitted deltas.
Logtrack40%
track(self, target)
Update target by reporting the change summaries.
Logapply0
apply(self, target)
Update target by applying the current transaction.
Logretract40%
retract(self, target)
Update target by previously applied retracting records.
Logcollapse286%
collapse(self)
Commit the leading deltas of the current transaction by combining records.
Primarily intended to eliminate successive character insertions and deletions when typing in insert mode.
Logcommit0
commit(self)
Update the commit position. Normally called directly after apply.
Logabort40%
abort(self)
Remove any records written since committed and update count to reflect the new records state.
Not normally used as deleting records will likely cause display inconsistencies. In most cases, undo should be used.
Logcheckpoint277%
checkpoint(self)
Write a checkpoint clearing any uncommitted writes.
Logundo0
undo(self)
Retract delta records effecting target until the given quantity of checkpoints have been traversed or the beginning of the log has been reached.
Logredo193%
redo(self, target)
Replay delta records effecting target until the given quantity of checkpoints have been traversed or the end of the log has been reached.