Skip to the content
v1.0.1-beta.17

Track changes

Premium add-on. This page covers a premium add-on, included in Scriviamo Pro and Pro + Collaboration. See pricing

The premium trackchanges add-on adds a suggesting mode: while it's on, edits to text become changes that someone accepts or rejects. Added text shows green and underlined; removed text stays, red and struck through, until the change is accepted. Each change records who made it and when.

Turn suggesting on with Suggest Changes in the Track Changes tool's menu, or in the inspector's Changes tab, which lists every change with Accept and Reject, and Accept All and Reject All. Clicking a change in the text shows who made it, with Accept and Reject.

import {TrackChanges} from "./dist/addons/scriviamo.trackchanges.js"

TrackChanges.setSuggesting(editor, true)
let changes = TrackChanges.changes(editor)        // [{id, kind, author, time, text, host, start, end}]
TrackChanges.accept(editor, changes[0])
TrackChanges.resolveAll(editor, false)           // rejects them all, as one undo step

Who resolves changes

On a shared document, set its owner, by name as the collaboration add-on names users; your application knows who that is. Then only the owner accepts changes, and a change can be rejected by the owner or by whoever made it:

TrackChanges.setOwner(editor, "Grace Hopper")   // or TrackChanges.owner for every editor
The ownerA change's authorAnyone else
Accept a changeYesNoNo
Reject a changeYesTheir ownNo

Buttons the user can't use are turned off, with the reason. For someone who isn't the owner, Reject All becomes Reject My Changes. accept and reject return false, and resolveAll returns how many it resolved, so code follows the same rules. Without an owner, everyone resolves every change.

The current user is the collaborating user's name, or editor.annotations.authorName; names match ignoring case. For other rules, such as letting editors accept changes too, set TrackChanges.permission to a function of (editor, change, action) that returns true or false, or null to use the owner rule.

These rules are kept by the editor. Someone who changes the editor's code could get around them, so check changes on your server where it matters.

What's tracked

While suggesting:

  • typing, pasting and dropping text add it as a change; typing over a selection also suggests removing the selection, and the new text goes after it;
  • Backspace, Delete, cutting, and their word and line forms mark text as removed; removing text you suggested adding takes it out at once;
  • typing next to your own change continues it, so a word typed is one change.

Changes are made of text inside blocks. Adding, removing and moving whole blocks, splitting and joining paragraphs, and formatting, aren't tracked.

The author is the collaborating user's name, or editor.annotations.authorName.

Saving and sharing

Changes are part of the document's text, so they're saved with it, survive undo and redo, and, with the collaboration add-on, everyone in the document sees and resolves the same changes.

The base package draws changes and keeps them in every format, so a document with changes opens correctly in an editor without this add-on; only suggesting and resolving need it. In HTML, a change is an <ins> or <del> element with data-scriviamo-change, data-scriviamo-author and datetime, which imports back as the change; Markdown has the same elements. In JSON, the text styles carry change ("insert" or "delete"), changeID, changeAuthor and changeTime.