Skip to content

Editor#601

Draft
ije wants to merge 94 commits intopierrecomputer:mainfrom
ije:editor
Draft

Editor#601
ije wants to merge 94 commits intopierrecomputer:mainfrom
ije:editor

Conversation

@ije
Copy link
Copy Markdown

@ije ije commented Apr 23, 2026

Architecture

The editor is a plugable system for the File and FileDiff components. It provides:

  • Text Editing
  • Selection management
  • History (undo, redo)

The editor is using a hidden textarea element as the input controller, which allows you to use UNIX system key binding(control + F/B/A/E/etc...), emoji/non-ascii input without implement them from scratch.

const textarea = document.createElement("textarea")
// make the textarea element invisible
textarea.style.opacity = '0'
// when change text
textarea.addEventListener("input", syncTextareState)
// moving caret
textarea.addEventListener("selectionchange", syncTextareState)

Selections are created via the native web selection API, multiple cursors has been supported.

document.addEventListener('selectionchange', () => {
  const selectionRaw = document.getSelection();
  const composedRanges = selectionRaw?.getComposedRanges({
    shadowRoots: [fileContainerShadowRoot],
  });
  const selection = convertSelection(composedRanges);
  if (selection) {
    // Text in the editor has been selected.
    // You can now get the `start.line`, `start.column`, `end.line` and `end.column` from the selection
  }
})

API

import { Editor, File } from "@pierre/diffs"

// render a file
const fileInstance = new File({ ... });
fileInstance.render({ ... });

// make the file editable
const editor = new Editor()
editor.edit(fileInstance, {
  onChange: file => console.log("change", file.name, file.contents)
})

TODOS

  • Basic editing
  • Selection & cursor
  • Multiple cursors (Pressing ⌘)
  • History(undo/redo)
  • Shortcuts
    • 'copy' ⌘ + C
    • 'cut' ⌘ + X
    • 'paste' ⌘ + V/Y
    • 'indent' Tab
    • 'outdent' Shift + Tab
    • 'documentStart' ⌘ + ↑
    • 'documentEnd' ⌘ + ↓
    • 'undo' ⌘ + Z
    • 'redo' ⌘ + Shift + Z
    • 'selectAll' ⌘ + A
  • Browser compatibility
    • Chrome
    • Firefox
    • Safari
    • Mobile phone
  • LSP next version

ps, should have many bugs :)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

@ije is attempting to deploy a commit to the Pierre Computer Company Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

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

Project Deployment Actions Updated (UTC)
pierrejs-diff-demo Ready Ready Preview Apr 28, 2026 3:16am
pierrejs-docs Ready Ready Preview Apr 28, 2026 3:16am

Request Review

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