diffs

Use when an app uses @pierre/diffs to render or edit code files, diffs, patches, merge conflicts, or CodeView review surfaces, including React, vanilla JavaScript, SSR, workers, annotations, selection, and custom Shiki languages or themes.

Install
npx skills add 'https://github.com/pierrecomputer/pierre/tree/main/skills/diffs'
Download bundle ↓
main · 1831817Scanned 2026-09-15

Contributors

GitHub-linked commit authors for this SKILL.md at the saved revision. Co-authors and history before file renames are not included.

File history ↗
View on GitHub
← Back to SKILL.md

Editor API

This reference lists the primary exports from @pierre/diffs/edit and the editor APIs used by common integrations.

Exports

ExportKindPurpose
CaretMetadataTypeSupplies the color shared by a remote caret and its highlight.
EditorClassAdds text editing to a File or FileDiff instance.
EditorCaretTypeDescribes an externally owned caret or highlighted selection.
EditStateManagerValueManages keyed in-memory edit history and state.
ClearEditStateOptionsTypeSelects retained state parts to clear.
EditStateTypeHolds one complete live editing session.
EditorInitialStateTypeSelects state fields to supply on first attachment.
EditorChangeTypeDescribes one normalized editor change.
EditorChangeEventTypeProvides normalized edits and the current document.
EditorActiveLineOptionsTypeConfigures reveal behavior for an editor active line.
EditorEditCompleteEventTypeUnites file and diff completion events for editor observation.
FileEditCompleteEventTypeDescribes a completed file edit session.
FileDiffEditCompleteEventTypeDescribes a completed diff edit session.
EditorCommandTypeNames an editor command.
EditorTypeTypeSelects a file or file-diff editor surface.
EditorFactoryTypeDefines an editor-type-aware editor factory.
EditorFocusOptionsTypeSelects a focus target and scroll behavior.
EditorKeymapTypeDefines ordered custom shortcut groups.
EditorOptionsTypeConfigures history, initial state, behavior, and events.
EditorShortcutTypeDefines one command shortcut.
EditorSelectionTypeAdds caret direction to an editor range.
EditorViewStateTypeHolds selections and editor-owned viewport offsets.
EditorViewportStateTypeHolds horizontal and optional vertical scroll offsets.
KeyboardKeyTypeNames a key accepted by an editor shortcut.
KeyboardModifierTypeNames a modifier accepted by an editor shortcut.
TextDocumentClassStores text, positions, edits, search, and undo history.
TextDocumentChangeTypeDescribes the lines and characters changed by an edit.
PositionTypeIdentifies a zero-based line and character.
RangeTypeIdentifies a start and end position.
ResolvedTextEditTypeStores an edit with resolved document offsets.
SelectionDirectionTypeSelects backward, neutral, or forward selection direction.
TextEditTypeReplaces one range with new text.
MarkerTypeDescribes an editor diagnostic marker.
MarkerSeverityTypeSelects an editor marker severity.

Lower-level exports

The edit entrypoint also exposes the state-management, keyboard-resolution, marker-rendering, and popover-placement building blocks used by Editor.

ExportKindPurpose
ManagedEditSessionTypeSelects mutable in-progress editor state by editor type.
ManagedFileEditSessionTypeHolds mutable state for an active file editor session.
ManagedFileDiffEditSessionTypeHolds mutable state for an active file-diff editor session.
cloneEditorViewStateFunctionClones editor selections and viewport state.
toManagedEditStateFunctionReturns complete edit state when a managed session has required data.
resolveEditorCommandFromKeyboardEventFunctionResolves a keyboard event through custom and default editor keymaps.
resolveFindAgainShortcutFunctionRecognizes the next or previous native find shortcut.
MarkerRenderOptionsTypeSupplies marker rendering, measurement, and popover dependencies.
MarkerRendererClassRenders marker ranges and marker hover popovers.
markerSeverityDatasetKeyFunctionMaps a marker severity to its DOM dataset key.
POPOVER_BOUNDARY_LINESValueSets the document-edge fallback threshold for popover placement.
POPOVER_FLIP_HYSTERESIS_PXValueSets the clearance required before a flipped popover returns.
PopoverPlacementBoundsTypeDescribes vertical popover placement bounds.
PopoverViewportBoundsTypeDescribes all visible viewport edges for popover clamping.
PopoverManagerOptionsTypeSupplies active-popover state callbacks to PopoverManager.
PopoverManagerClassTracks viewport geometry and stable popover placement.
setPopoverPositionStylesFunctionWrites the CSS properties used to position and clamp a popover.

EditorOptions fields

FieldPurpose
historyMaxEntriesLimits the undo stack.
ownsVerticalViewportOpts into vertical scroll retention at construction.
initialStateSupplies partial or complete state on first attach.
keymapAdds shortcut groups checked before the defaults.
roundedSelectionControls rounded selection corners.
matchBracketsControls matching-bracket highlights.
autoSurroundControls quote and bracket insertion around a selection.
languageCommentConfigOverrides comment tokens by language.
enabledSelectionActionEnables the selection action surface.
clipboardSupplies a text clipboard reader.
renderSelectionActionProduces the selection action element.
renderCaretProduces an externally owned caret element.
onAttachReceives the editor and attached surface.
onChangeReceives the event, including its editor instance.
onCompleteObserves the completed file or diff event.
onFocusRuns after the editor gains focus.
onBlurRuns after the editor loses focus.

For a file-diff editor, view-only initialState can omit document and diff metadata. Transferring an edited document and its undo/redo history requires the matching document, fileInfo, and diffSession from one complete EditState.

onComplete receives the exact frozen event that is also passed to the component's onEditComplete or CodeView's onItemEditComplete. The editor observer runs first and still runs when the component callback is missing. You cannot accept or reject from this API. It is here for symmetry, but most integrations should use those component callbacks instead.

Use editStateKey for ordinary same-runtime restoration. It retains the draft, undo/redo history, selections, horizontal code scroll, eligible vertical scroll, and FileDiff resume metadata without an application synchronization loop. It is bounded in-memory state and does not survive a reload.

Use getViewState() and setViewState() for an isolated selection/view copy or durable application persistence. An attached surface reports horizontal scrollLeft. It reports scrollTop only when ownsVerticalViewport: true was passed to the constructor and the surface exclusively owns an element viewport. Virtualization alone does not imply ownership; page, ancestor, and CodeView shared scrolling remain application/viewer state.

getEditState() exposes the raw objects from the latest complete edit-lifecycle checkpoint. Checkpoints run after synchronization, document edits, explicit setViewState() calls, recycling, and completion. Selection or scroll movement alone does not update it; use getViewState() for an exact live copy. State remains available while rendering is recycled and during onComplete, and returns undefined before synchronization or after completion. The result is borrowed editor-owned state rather than a serialization format.

Editor members

MemberPurpose
new Editor(type, options?, editStateKey?)Creates an editor with optional keyed state retention.
typeIdentifies the editor as file or file-diff.
edit(instance)Attaches and returns the normal completion disposer.
setOptions(options)Merges editor options.
applyEdits(edits, updateHistory?)Applies programmatic text edits.
canUndoReports whether undo has an entry.
canRedoReports whether redo has an entry.
undo()Reverts the latest edit.
redo()Reapplies the latest reverted edit.
getFile()Gets the current file contents.
getText()Gets the current text.
getViewState()Gets selections and editor-owned view state.
setViewState(state)Sets selections and editor-owned view state.
getEditState()Gets the latest edit-lifecycle state checkpoint.
setSelections(selections)Sets directed selection ranges.
setCarets(carets)Replaces the externally owned caret and highlight list.
setMarkers(markers)Sets diagnostic markers.
focus(options?)Focuses the editor.
blur()Removes editor focus.
cleanUp(reason?: 'discard' | 'recycle' | 'complete')Suspends rendering or completes the editing session.

editStateKey opts an editor into retained in-memory sessions across editor instances. File and file-diff namespaces are independent and each keeps up to 100 inactive entries by default. The same type/key cannot be active in two editors at once.

Call the disposer returned by edit(instance) for the normal session-ending path; it is equivalent to cleanUp('complete') and installs an accepted completion result. cleanUp('discard') still publishes the completion event but does not install its result. cleanUp('recycle') suspends rendering without ending the session or changing the editor-component association. Calling edit(instance) again resumes rendering for that same component.

EditStateManager members

MemberPurpose
get(type, editStateKey)Borrows active or inactive complete state without touching LRU.
clear(type, editStateKey, parts?)Clears inactive complete or granular state.
clearAll()Clears all inactive state without mutating active editors.
setCapacity(capacity)Sets each namespace's inactive retained-state capacity.

clear() returns false for active or missing state. Omit parts to remove the complete entry. { document: true } also removes the complete entry because all other parts depend on it. Use { history: true }, { selections: true }, { view: true }, or { editor: true } to keep the document while clearing undo history, cursor state, scroll state, or both view-state parts respectively.

For durable persistence, store FileContents and optional JSON-safe EditorViewState separately, then construct a fresh TextDocument when restoring. Complete EditState and undo/redo history are not serialization contracts.

TextDocument members

MemberPurpose
new TextDocument(uri, text, languageId?, version?)Creates a text document.
uriGets the document identifier.
languageIdGets the language identifier.
versionGets the document version.
lineCountGets the line count.
eolGets the line-ending sequence.
canUndoReports whether undo has an entry.
canRedoReports whether redo has an entry.
positionAt(offset)Converts an offset to a position.
positionsAt(offsets)Converts several offsets to positions.
offsetAt(position)Converts a position to an offset.
getText(range?)Gets all text or one range.
getLineText(line, includeLineBreak?)Gets one line.
normalizeEol(text)Converts text to the document line ending.
getLineLength(line, includeLineBreak?)Gets one line length.
charAt(offsetOrPosition)Gets one character.
getTextSlice(start, end)Gets text between two offsets.
findNextNonOverlappingSubstring(needle, occupied)Finds an unused substring range.
search(params)Finds text ranges.
applyEdits(edits, ...)Resolves and applies position-based edits.
resolveEdits(edits)Converts position-based edits to offset edits.
applyResolvedEdits(edits, ...)Applies offset-based edits.
setLastUndoSelectionsAfter(selections)Associates selections with the latest history entry.
setLastUndoLineAnnotations(before, after)Associates annotations with the latest history entry.
undo()Reverts one document history entry.
redo()Reapplies one document history entry.
normalizePosition(position)Clamps a position to the document.
Referenced from SKILL.md