Skip to content

collabui: Ctrl+Z in a shared text undoes this participant's edits, never a peer's - #592

Merged
tannevaled merged 4 commits into
mainfrom
fix/collab-undo-own-ops
Nov 18, 2026
Merged

tannevaled merged 4 commits into
mainfrom
fix/collab-undo-own-ops

Conversation

@tannevaled

@tannevaled tannevaled commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

Ctrl+Z in a CodeEditor bound to a live collabui.CollabText session undoes this participant's own edits and nothing else. Closes #591.

Verified first

collabui/collabundo_test.go was written before any fix: two (then three) CollabTexts on one session, A types, B types after it, A presses Ctrl+Z through the widget's key path. On main it fails, and B's text is deleted on every replica:

collabundo_test.go:45: timed out waiting for ada undo settled; text is ""

(expected "b"; A's undo restored the empty buffer that predated B's insertion, and syncLocal published that as a local deletion.) The three-participant variant fails the same way.

Fix

  • TextView.SetHistoryDelegate(*HistoryDelegate): while set, Ctrl+Z / Ctrl+Y / Ctrl+Shift+Z, Undo, Redo, CanUndo and CanRedo answer from the delegate and the view keeps no snapshot (pushUndo still announces the edit to OnHistory). nil returns to the snapshot history, which was left as it was.
  • CollabText sets a delegate backed by collab.Text.Undo/Redo (own-edit undo of crdt/structured, by character identity: an undo is an ordinary edit, so peers need no code), and shows the result after each undo or redo.
  • Typing groups per word: single characters typed each where the last ended are one step; a space, a deletion, a replacement or a jump ends it. Peers' typing in the middle is not part of the group.
  • Non-collaborative editors: unchanged. TestHistoryDelegateRemovedRestoresSnapshots and the existing undo tests are the control.

Depends on, before merge

go.mod pins go-crdt/collab and go-crdt/crdt to heads of open pull requests (pseudo-versions): collab Refs go-crdt/collab#286, crdt Refs go-crdt/crdt#182. Move both pins to release tags after those merge. The go directive moved to 1.27.4 as collab requires.

Checked, not changed

IsoDiagram.Undo (isodiagram.go:1282) has the same shape: a whole-document snapshot, restored by removing every entity and putting the old ones back. Over an IsoCRDTDocument that removes peers' entities and re-puts older ones as local operations. Not cheap (needs the structured Diagram's own-edit undo and an IsoDocument seam), so it is filed separately as Refs #593. Spreadsheet and CollabSheet have no undo of their own; UndoStack is an application command history and records whatever commands the application defines.

Full go test ./... green locally.

🤖 Generated with Claude Code

tannevaled and others added 4 commits November 18, 2026 10:14
…ver a peer's

The editor's snapshot undo restores a whole buffer. In a text other people
edit, that buffer predates what they typed since, and CollabText publishes
whatever the buffer became, so the restore went out as the local user deleting
their text (#591). The new test fails on main: A types, B types after it, A
presses Ctrl+Z through the widget, and B's text is gone on every replica.

TextView gains SetHistoryDelegate: while one is set the keys, Undo/Redo and
CanUndo/CanRedo answer from it and the view keeps no snapshot. CollabText sets
one backed by collab's own-edit undo, groups typing per word (a space, a
deletion or a jump ends the group), and shows the result after each undo. The
snapshot history of a view without a delegate is unchanged (control test).

go.mod points collab and crdt at the heads of go-crdt/collab and go-crdt/crdt
pull requests; the pins move to release tags before this merges.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The nested module requires the root module, so a change to the root's crdt
requirement leaves its go.mod untidy; its CI lane refuses that.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
crdt#182 and collab#286 are released. Replace the pseudo-versions of their
branches with the tags, in the root module and in rougelex, so nothing here
depends on an unreleased commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ctrl+Z in a collaborative CodeEditor deletes the other participant text, as your own operation

1 participant