Files
edentext/src/lib/components/ribbon/selection.ts
T
Steffen Becker 2aeac7a574 feat: a Word-style ribbon can take the toolbar's place
A second chrome, chosen by odf-editor-chrome and switchable from either side so
the two can be compared. The shell only — tab strip, File menu, quick-access
save/undo/redo; the tab bodies follow. The classic island stays untouched.

Word's palette lives in --w-* outside the theme blocks, and .ribbon remaps the
app's own tokens onto it, so a reused picker adopts the ribbon's look without
an edit of its own.
2026-08-12 01:20:47 +02:00

21 lines
754 B
TypeScript

import type { Editor } from '@tiptap/core';
export type SavedRange = { from: number; to: number } | null;
// A popover steals focus, which collapses the ProseMirror selection. Snapshot it
// when the popover opens, replay it before the command runs.
export function saveRange(editor: Editor | null): SavedRange {
if (!editor) return null;
const { from, to } = editor.state.selection;
return { from, to };
}
// Runs `fn` with the saved range restored; the chain it builds must be `.run()` by
// the caller, as usual.
export function withRange(editor: Editor | null, range: SavedRange, fn: () => void): void {
if (!editor) return;
if (range) editor.chain().focus().setTextSelection(range).run();
else editor.chain().focus().run();
fn();
}