Skip to content

[diffs/edit] feat: add decorations API - #1059

Open
ije wants to merge 5 commits into
mainfrom
ije/editor-decorations
Open

[diffs/edit] feat: add decorations API#1059
ije wants to merge 5 commits into
mainfrom
ije/editor-decorations

Conversation

@ije

@ije ije commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Decorations anchor arbitrary UI to a zero-based document position. Supply typed metadata with each decoration, then map it to an HTMLElement with the renderDecoration editor option. The editor owns positioning while your renderer owns the returned element.

import { Editor } from '@pierre/diffs/edit';

interface CursorMetadata {
  name: string;
  color: string;
}

const editor = new Editor<undefined, CursorMetadata>({
  renderDecoration({ metadata }) {
    const cursor = document.createElement('span');
    cursor.ariaLabel = `${metadata.name}'s cursor`;
    cursor.style.cssText = `display:block;width:2px;height:1lh;background:${metadata.color}`;
    return cursor;
  },
  onAttach(editor) {
    editor.setDecorations([
      {
        position: { line: 5, character: 26 },
        metadata: { name: 'Ada', color: '#7c3aed' },
      },
    ]);
  },
});

editor.edit(fileInstance);

// Each call replaces every decoration. Pass an empty array to clear them.
editor.setDecorations([]);
image

@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Aug 6, 2026 5:15pm
pierre-docs-diffshub Ready Ready Preview Aug 6, 2026 5:15pm
pierre-docs-trees Ready Ready Preview Aug 6, 2026 5:15pm
pierrejs-diff-demo Ready Ready Preview Aug 6, 2026 5:15pm

Request Review

@ije

ije commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c7a009306

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/diffs/src/edit/index.ts
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.

1 participant