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
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| useSaveShortcut | 9 to 20 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| <anonymous:10> | 10 to 19 | 1 | 0% | OkCRAP 2 | No data: mutation testing has not run on this repo yet |
| onKey | 11 to 16 | 4 | 0% | WatchCRAP 20 | No data: mutation testing has not run on this repo yet |
| <anonymous:18> | 18 to 18 | 1 | 0% | OkCRAP 2 | No 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);
});
}