platejs

Cursor Overlay

Text 5

About

A visual overlay that renders cursor positions and selection highlights on top of a Plate rich-text editor, keeping selections visible during drag & drop and when the editor loses focus.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Cursor Overlay to your project and fits it to your theme.

Code

How Cursor Overlay is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";

import { CursorOverlay } from "@/components/ui/cursor-overlay";

import * as SelectionPlugins from "@platejs/selection/react";
import {
  Plate,
  PlateContainer,
  PlateContent,
  usePlateEditor,
} from "platejs/react";

const initialValue = [
  {
    type: "p",
    children: [
      {
        text: "Select this text, then click away from the editor — the highlight stays visible thanks to the cursor overlay.",
      },
    ],
  },
  {
    type: "p",
    children: [
      {
        text: "Try dragging a word to a new spot: a colored caret follows the drop target. The overlay renders selection rectangles and cursor positions on top of the content, powering drag & drop and external UI like AI or link toolbars.",
      },
    ],
  },
];

export default function CursorOverlayDemo() {
  const editor = usePlateEditor({
    plugins: [
      SelectionPlugins.CursorOverlayPlugin.configure({
        render: { afterEditable: () => <CursorOverlay /> },
      }),
    ],
    value: initialValue,
  });

  return (
    <div className="w-full bg-background p-6">
      <div className="mx-auto w-full max-w-2xl">
        <p className="mb-3 text-sm font-medium text-muted-foreground">
          Select text and click away, or drag a word, to see the cursor overlay.
        </p>
        <Plate editor={editor}>
          <PlateContainer className="relative w-full cursor-text overflow-y-auto rounded-lg border bg-card shadow-sm">
            <PlateContent
              className="min-h-[220px] px-6 py-5 text-base leading-7 text-foreground caret-primary selection:bg-brand/25 focus:outline-none [&>div]:mb-3"
              placeholder="Type something…"
            />
          </PlateContainer>
        </Plate>
      </div>
    </div>
  );
}

Dependencies

More by platejs

View all
  • Math Base Kit

    Math Base Kit

    15
  • Highlight Leaf

    Highlight Leaf

    6
  • Editor

    Editor

    4
  • Link Element

    Link Element

    3
  • Resize Handle

    Resize Handle

    3
  • Inline Combobox

    Inline Combobox

    1
  • List

    List

    1
  • Blockquote Element

    Blockquote Element

    1

More in Text

View all
  • Vertical Cut Reveal Characters

    Vertical Cut Reveal Characters

    103
  • Rainbow Text Effect

    Rainbow Text Effect

    47
  • Motion Blur Text

    Motion Blur Text

    36
  • Text Loop

    Text Loop

    306
  • Text Reveal

    Text Reveal

    27
  • Apple Hello Effect

    Apple Hello Effect

    609
  • Animated Text

    Animated Text

    8
  • Lightning Text

    Lightning Text

    123