Skip to the content

Capsid menu

app/components/editor/typing.ts

25 lines and 5 functions in DrDustinEdwards/carrel, at commit d5d5e82 on 2026-10-24. This file on GitHub.

Functions

The functions of typing.ts
FunctionLinesComplexityCoveredCRAPMutation
useTypingRecede7 to 271100%OkCRAP 1No data: mutation testing has not run on this repo yet
<anonymous:8>8 to 2610%OkCRAP 2No data: mutation testing has not run on this repo yet
settle10 to 1220%WatchCRAP 6No data: mutation testing has not run on this repo yet
type13 to 1870%CriticalCRAP 56No data: mutation testing has not run on this repo yet
<anonymous:21>21 to 2510%OkCRAP 2No data: mutation testing has not run on this repo yet

Imports

It imports no other module of this repo. Imported by app/routes/book.file.tsx, app/routes/editor.tsx.

Source

// The editor's chrome steps back while someone types and returns on a mouse move or when focus enters
// it. Carrel's editor always did this for its own toolbar; it now covers the shell too, so the rail and
// the top bar fall quiet with the rest. The state is one attribute on the document, read by app.css.

import { useEffect } from "react";

export function useTypingRecede() {
  useEffect(() => {
    const root = document.documentElement;
    const settle = () => {
      if (root.hasAttribute("data-typing")) root.removeAttribute("data-typing");
    };
    const type = (event: KeyboardEvent) => {
      if (event.metaKey || event.ctrlKey || event.altKey || event.key.length !== 1) return;
      // Only typing in the editing surface counts; a character typed in a dialog's field does not.
      const target = event.target;
      if (target instanceof HTMLElement && target.closest(".cm-editor, .app-rich-surface")) root.setAttribute("data-typing", "");
    };
    window.addEventListener("keydown", type);
    window.addEventListener("mousemove", settle);
    return () => {
      window.removeEventListener("keydown", type);
      window.removeEventListener("mousemove", settle);
      root.removeAttribute("data-typing");
    };
  }, []);
}