Files
feuerwerk/src/editor/documents.ts
T
adminandClaude Opus 5.5 76f5097a38
game-maker / gate (push) Successful in 3m54s
game-maker / suite (push) Successful in 15m17s
Float a document's tab in a window of its own, and dock it (#371)
The Parametric EQ has a tab of its own since #370, but Play is in the
sound FX's tab. A tab that can float keeps both in view. There is one
editor per kind, so the kind's pane is lent to the window and given
back on Dock, the way fullscreen moves the game view.

- A right-click on a document's tab opens a menu with Float and Close.
  `DocumentTab` passes the press to `TabStrip`'s new `onMenu`.
- `FloatWindow` sits on the overlay. Its title bar moves it, its lower
  right corner sizes it, Dock and the x close it. A press brings it to
  the front.
- `floating.ts` is the pure part: where a window opens, held whole on
  the screen, sized down to 320 x 200. Nothing of it is remembered.
- One window per kind. Another document of that kind opens there and
  closes the one it had. Its tab, if it had one, leaves the row.
- When the row showed the kind, it shows the nearest document whose
  kind is not in a window, else the scene (`neighbourOf`).
- Delete, Copy and Paste go to the window pressed last, and back to
  the tab showing after a press in the editor (`keyTab`).
- Previews tick and redraw for a kind in a window as for the tab
  showing. Fullscreen hides the windows. Loading a project or signing
  out closes them.
- Only documents float, Scene and Game stay in the row.
- Hooks: `floatWindows`, `floatDocument`, `keyTarget`.

Tests:
- Unit documents: 16 green, 5 new. Counter-check: `neighbourOf`
  without the window check turns its test red.
- e2e 44 (melektaus-atx, after steps 1-12 and 37): ALL PASSED,
  505 checks in the chain, 6 new for float, move, size, another
  texture, keys, Dock and x.
- Gate (melektaus-atx): CHECK EXIT 0, 274 files, 4236 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 14:27:12 +02:00

51 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* The open documents of the tab row (#171): which tabs there are, in which order, and which one is
* showing. `null` as the active one means a fixed tab (Scene, Game, Plugins, a plugin's) is showing.
*/
export interface DocumentRow<T> {
docs: readonly T[];
active: T | null;
}
/** Opens `doc`: an open one merely becomes active, a new one goes right of the active document, or last. */
export function openDocument<T>(row: DocumentRow<T>, doc: T): DocumentRow<T> {
if (row.docs.includes(doc)) return { docs: row.docs, active: doc };
const at = row.active === null ? -1 : row.docs.indexOf(row.active);
const docs = [...row.docs];
docs.splice(at < 0 ? docs.length : at + 1, 0, doc);
return { docs, active: doc };
}
/**
* Closes `doc`. Closing the one on screen shows its left neighbour, or the right one when it was
* first; with none left, `active` is null and the caller goes back to the scene.
*/
export function closeDocument<T>(row: DocumentRow<T>, doc: T): DocumentRow<T> {
const at = row.docs.indexOf(doc);
if (at < 0) return row;
const docs = row.docs.filter((d) => d !== doc);
if (row.active !== doc) return { docs, active: row.active };
return { docs, active: docs[Math.max(0, at - 1)] ?? null };
}
/**
* What shows when the document that stood at `at` in `docs` has left it (#371): the nearest one to
* its left that `fits`, else the nearest to its right – as `closeDocument` picks, but skipping the
* documents that cannot show in the tabs now. Null means the scene.
*/
export function neighbourOf<T>(docs: readonly T[], at: number, fits: (doc: T) => boolean): T | null {
for (let i = Math.min(at, docs.length) - 1; i >= 0; i--) if (fits(docs[i]!)) return docs[i]!;
for (let i = Math.max(0, at); i < docs.length; i++) if (fits(docs[i]!)) return docs[i]!;
return null;
}
/**
* Puts `to` where `from` is – a tab that goes on to another document, like a behavior followed
* into a call. Where `to` was open already, that tab goes: a document has one tab.
*/
export function replaceDocument<T>(row: DocumentRow<T>, from: T, to: T): DocumentRow<T> {
if (from === to || !row.docs.includes(from)) return row;
const docs = row.docs.filter((d) => d !== to).map((d) => (d === from ? to : d));
return { docs, active: row.active === from || row.active === to ? to : row.active };
}