Leaf.Collab.Log (Leaf v0.7.0)

Copy Markdown View Source

A running account of what each session believes it is holding.

The point is to make a disagreement visible at the moment it happens rather than to be inferred from two tabs of text afterwards. Every operation carries the sender's fingerprint of its own document; the room computes the same fingerprint over the result of applying that operation. If the two differ, the sender and the room have parted company — and the log says so on the line where it happened, with the caret positions and revisions in view.

Only written when a host turns diagnostics on, because it is one line per keystroke and a fingerprint of the whole document each time. Useful while something is wrong; wasteful once it is not.

Read it with:

tail -f your.log | grep '\[collab\]'

Summary

Functions

Compare what the sender ended up with against what the room did.

Where two sessions' coordinates part company, with the text either side.

FNV-1a, 32 bit, over the document's code points.

Say exactly where two documents part company, with the text either side.

Two sessions holding the same document but not the same coordinates.

Functions

caret(session, offset, debug)

compare(session, op, room_document, room_revision)

Compare what the sender ended up with against what the room did.

Returns :match, :mismatch, or :unknown when the editor sent no fingerprint. A mismatch is the moment worth catching: from here on the two are editing different documents, and everything after it is a consequence.

coordinate_gap(session, other, mine, theirs)

Where two sessions' coordinates part company, with the text either side.

The index is into the rendered text, which is what offsets are measured in, so it names the character an edit would be misplaced around.

digest(text)

FNV-1a, 32 bit, over the document's code points.

Matches the editor's _digest exactly, so the same text produces the same eight characters on both sides. Text outside the Basic Multilingual Plane hashes differently here than in the browser, which is a limitation of comparing UTF-16 code units with code points and not worth more than a note.

divergence(session, editor_markdown, room_document)

Say exactly where two documents part company, with the text either side.

Called once the editor has sent the text it holds, which is the only way to turn "these differ" into a character position.

first_difference(a, b)

misaligned(session, other, mine, theirs)

Two sessions holding the same document but not the same coordinates.

This is the state that misplaces a caret, and it is invisible to a comparison of the documents: both are correct markdown, of the same length, with the same fingerprint. They differ only in how many characters each editor believes the text has — so an offset one of them sends means a different place in the other, and typing after a full stop lands before it.

note(message, pairs)

operation(session, op, result)