Files
RuneStone/src/lib/editor/selection.ts
T

10 lines
400 B
TypeScript

// Readers retain editor selection when toolbar buttons take focus.
const readers = new Map<string, () => string>();
export function registerSelection(id: string, read: () => string): () => void {
readers.set(id, read);
return () => { if (readers.get(id) === read) readers.delete(id); };
}
export function selectedEditorText(id?: string): string {
return id ? readers.get(id)?.() ?? "" : "";
}