Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·originates fromworld 07158574-5…

selection

Named selection scopes for the editor. A scope is an independently tracked, ordered set of typed refs plus a primary (the last ref added or clicked). Distinct scopes never clobber each other, so viewport, outliner, inspector and asset browser share one answer to "what is selected…

by◐lumi·posted 2mo ago
What it does

editorSelection

Named selection scopes for the editor. A scope is an independently tracked, ordered set of typed refs plus a primary (the last ref added or clicked). Distinct scopes never clobber each other, so viewport, outliner, inspector and asset browser share one answer to "what is selected" per kind.

A ref is { kind: string, id: string } — a stable id, never a display string, so rename/move never invalidates a selection.

Exports

  • M.scope(name) -> Scope — get/create a named scope handle.
  • M.set(scope, refs) — replace refs in order; primary becomes the last.
  • M.get(scope) -> { Ref } — refs in click order (fresh array).
  • M.primary(scope) -> Ref? — last-clicked ref, or nil.
  • M.clear(scope) — empty a scope.
  • M.toggle(scope, ref) — add if absent, remove if present.
  • M.add(scope, refs) — add each ref not already present; primary becomes the last added.
  • M.remove(scope, refs) — remove each of refs; primary becomes the last remaining or nil.
  • M.contains(scope, ref) -> boolean — membership by (kind, id).
  • M.count(scope) -> number — the scope's selection size.
  • M.subscribe(scope, fn) -> handle / M.unsubscribe(scope, handle) -> boolean.
  • M.context() -> { scope, refs, primary } — last-focused scope, for command ctx.

Usage

local Selection = require("@builtin::modules.api.editor.selection")
local scope = Selection.scope("entity")
Selection.set(scope, { { kind = "entity", id = "player_1" } })
Selection.subscribe(scope, function() refreshInspector() end)

Notes

  • State lives in a fixed _G slot, seeded pre-seal by the boot chain (prelude.luau); it survives hot-reload and edit↔play flips. Mutations after boot write into nested tables only.
  • set / toggle / clear mark their scope as last-focused, which drives context() and therefore which scope commands act on.
  • The service holds the editor's selection state in Luau. Refs handed back by get / primary / context are copies, so a caller can hold or mutate them without touching internal state.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

EditorSelection Module Named selection scopes for the editor. A scope is an independently tracked, ordered set of typed refs plus a primary (the last ref added or clicked). Distinct scopes ("entity", "asset", "file") never clobber each other, so the viewport, outliner, inspector and asset browser share one answer to "what is selected" per kind. A ref is `{ kind, id }`. Refs carry stable ids, not display strings, so a rename or move does not invalidate a selection. Usage: local selection = require("@builtin::modules.api.editor.selection") local entityScope = selection.scope("entity") selection.set(entityScope, { { kind = "entity", id = eid } }) selection.toggle(entityScope, { kind = "entity", id = otherEid }) local primary = selection.primary(entityScope) State lives in a fixed `_G` slot so it survives hot-reload and edit↔play flips, seeded pre-seal by the boot chain (see prelude.luau) — mirrors `modules.api.editor.registry`. Every mutation after boot writes into the pre-seeded `scopes` table (`s.scopes[name] = …`), never a new direct key on `_G`.

S( ) → void

scopeState(name: string) → void

argtypedescription
namestring

notify(name: string) → void

argtypedescription
namestring

indexOf(order: { Ref }, ref: Ref) → number

argtypedescription
order{ Ref }
refRef

scope(name: string) → Scope

Get (creating on first use) a named selection scope handle.

argtypedescription
namestringScope identity, e.g. "entity" / "asset" / "file".

set(s: Scope, refs: { Ref }) → void

Replace a scope's refs with `refs`, in order. Primary becomes the last.

argtypedescription
sScopeA scope handle from `scope`.
refs{ Ref }Array of `{ kind, id }` refs.

get(s: Scope) →

The scope's refs, in click order (a fresh array).

argtypedescription
sScopeA scope handle.

primary(s: Scope) → Ref

The primary (last-added) ref, or nil when the scope is empty.

argtypedescription
sScopeA scope handle.

clear(s: Scope) → void

Empty a scope and drop its primary.

argtypedescription
sScopeA scope handle.

toggle(s: Scope, ref: Ref) → void

Add `ref` if absent, remove it if present. Primary becomes the last remaining ref (or nil when the scope empties).

argtypedescription
sScopeA scope handle.
refRefA `{ kind, id }` ref.

add(s: Scope, refs: { Ref }) → void

Add each ref not already present (appended in order); refs already in the scope keep their position. Primary becomes the last ref added, or the existing primary when nothing new was added.

argtypedescription
sScopeA scope handle.
refs{ Ref }Array of `{ kind, id }` refs to add.

remove(s: Scope, refs: { Ref }) → void

Remove each of `refs` from the scope. Primary becomes the last remaining ref, or nil when the scope empties.

argtypedescription
sScopeA scope handle.
refs{ Ref }Array of `{ kind, id }` refs to remove.

contains(s: Scope, ref: Ref) → boolean

Whether `ref` is currently in the scope.

argtypedescription
sScopeA scope handle.
refRefA `{ kind, id }` ref.

count(s: Scope) → number

The number of refs in the scope.

argtypedescription
sScopeA scope handle.

subscribe(s: Scope, fn: (any) →

Subscribe to a scope's changes. `fn` runs after every set/toggle/clear with the scope's current state. Returns an opaque handle for unsubscribe.

argtypedescription
sScopeA scope handle.
fn(anyCallback `(state) -> ()`; treat state as opaque.

unsubscribe(s: Scope, handle: any) → boolean

Remove a subscription added with `subscribe`.

argtypedescription
sScopeA scope handle.
handleanyThe handle returned by `subscribe`.

context( ) →

The last-focused scope's name, refs and primary — the command context shape.

_resetAll( ) → void

Test-only: wipe every scope so a leak in one test can't bleed into another.

⌬ Types
Ref = { kind: string, id: string }Scope = { name: string }

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

2items
This part has no composite children. See the Files segment for its leaf payloads.
backing path · modules/api/editor/selection.module

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.