Skip to the content

Capsid menu

app/components/editor/save-keys.ts

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

Functions

The functions of save-keys.ts
FunctionLinesComplexityCoveredCRAPMutation
useSaveShortcut9 to 201100%OkCRAP 1No data: mutation testing has not run on this repo yet
<anonymous:10>10 to 1910%OkCRAP 2No data: mutation testing has not run on this repo yet
onKey11 to 1640%WatchCRAP 20No data: mutation testing has not run on this repo yet
<anonymous:18>18 to 1810%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

// What the post editor and the book file editor share about saving: how long autosave waits after
// typing stops, and Cmd+S (Ctrl+S) as a save in place.

import { useEffect } from "react";

export const AUTOSAVE_DELAY_MS = 1200;

/** Cmd+S calls `save` instead of the browser's own save; `save` decides whether a save may run now. */
export function useSaveShortcut(save: () => void) {
  useEffect(() => {
    const onKey = (event: KeyboardEvent) => {
      if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "s") {
        event.preventDefault();
        save();
      }
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  });
}