# Liminalia Studio

## The Script screen

**Script** has the scene list on the left, the script in the middle, the preview and state on the right, and thumbnails at the bottom.
To the right of the script heading are the number of characters in the cursor's scene ("N characters in this scene"), the number of problems and the save state. While text is selected in the code view, or lines are extended with Shift in the block view, it shows "N characters selected"
(a selection within one line counts its characters; a selection across lines counts the text of the selected lines). It counts the same way as `lim stats` and the character count on the Check screen (the shown characters of dialogue, narration and choices; ruby counts its base characters,
and commands, inserted values, spaces and the outer brackets of dialogue aren't counted; `model/scene-chars.ts`). It waits until you stop typing, and is hidden when the panel is narrow.
At first, the scene list shows only files (with the number of scenes to the right of each name; when the panel is narrow, the middle of the name is left out, keeping the last 8 characters and the extension;
when names sharing the same beginning are listed (`episode1_2.lim` and `episode10_1.lim`), it keeps what follows the shared beginning; `model/trunc.ts`).
When sorted by name, scripts in subfolders (`part1/chapter2/side`) are listed under folder headings (`part1/`, `chapter2/` with the number of files inside), indented one step per level (`folderItems` in `panes/toc.ts`;
folders come before files at the same level, in name order). Click a heading to collapse or expand it (collapsed folders are remembered; folders are expanded by default). Story order crosses folders, so it shows names with their folders and no headings. With the switch at the top, choose name order (numbers are compared as numbers, so chapter3_2 comes before chapter3_10) or story order (following jump targets in the order they are written from "New game" in the flowchart, in the order files are first reached; files that are never reached come last, under a heading, in name order) (the choice is remembered). The › to the left of a file name expands that file's scenes (labels),
each with a small image (that scene's background and the faces of the characters in it), its name and its first line of text; click one to go to that line (expanded files are remembered).
Long lists (the scene list, variables, check problems, the asset grid) build only what is visible plus a little more, and build the rest as you scroll and the end marker comes near (`lazy-list.ts`;
the scene list builds up to the current file first, and when returning to the previous scroll position or showing the selected variable or asset, it builds up to there first).
The "＋" to the right of a file name adds a scene (label) at the end of that file. Right-click a scene (or use its "…") for "Play from Here," "Lines Leading Here" and the scene actions ("Scene actions" below). Search across files (⌘⇧F) shows a field at the top of the list.
The search is done by the dev server (`POST /search`; `server/search.ts`, with the search rules in `search.ts`), which searches every script, including files in subfolders, reusing the parse results
(if the open file has edits that aren't saved yet, that content is sent along with the search; the client doesn't fetch the files one by one).
Pack scenarios (`packs/<id>/scenario`) are searched too and listed after the main ones as `packs/<id>/scenario/<scenario>.lim` (`packs` in `SearchOptions`; read with the speakers in the pack's `cast.json` too).
Studio has no way to open and write pack scenarios, so their lines don't open when clicked, and replacing in all files skips them as read-only.
The buttons below the field change the search options (they are remembered): "Text" searches only dialogue and narration (leaving out commands, comments, labels, choice lines, speaker names, and markup inside the text
(`{@…}`, `{= expression}`, `{click}` and so on, and decoration prefixes); the base characters and readings of ruby count as text), "あア" treats hiragana and katakana as the same,
"Aa" matches case (the default ignores case), and ".*" uses a regular expression (JavaScript syntax; if it can't be read, it says so).
Matching lines are listed by file with the number of matches, and every match is marked (up to 300 lines). If there are more than 5,000 matching lines or it takes more than 3 seconds, it stops there and says so.
The two menus below the options narrow the search: where to search (all files, the open file, or a folder; `scope` in `SearchOptions`; with the open file chosen, opening another file searches again)
and speaker (only that speaker's dialogue lines, including inside `@if` and `@define`; `speaker`). Both also apply to replace in all files, and aren't remembered.
While results are shown, the scene list gets wider (`min(30rem, 32vw)`, or the width you dragged it to if that is wider; it goes back when you close the field or clear the text).

**Replace in all files** opens with "Replace" to the right of the search field (`panes/replace-panel.ts`; the logic is in `model/replace-all.ts`). Matching lines are listed by file with a preview of the characters removed and added
(up to 500 lines; any more are replaced without being listed, and can still be excluded by file). Clear the checkboxes by file or by line, then click "Replace." It searches the same way as search across files (the dev server searches with the same options in the same field). With a regular expression, the replacement can use `$1` to `$99`, `$&` and `$$`.
Changes to the open file go in as editor changes, so ⌘Z undoes them (they are saved by automatic saving). Other files are read when replacing, and if they are still as they were when searched, they are saved through the write API (`PUT /file`) with the hash from the search as baseHash, so they are kept in the change history
(it doesn't check on every save, but checks once after replacing). Files changed elsewhere after the search are skipped. Read-only files are skipped (and have no checkbox), and so are lines of the open file whose content changed after the search.
All the replaced files are remembered as one action, and "Undo" in the notice and in the replace panel undoes them all at once (including files that aren't open; it checks the same way as "Undo on screens" below,
and if a replaced file was changed elsewhere afterward, it undoes nothing and says so; if the open file was already undone with ⌘Z in the script, that file counts as undone).
Skipped files are reported at the top of the list (until you search for something else).
The script switches between "Blocks" (the block view) and "Code" (the code view) with the switch above the script (⌘E) (both edit the same document and share undo, automatic saving, the preview and the syntax check).
The block view shows labels as scene headings (with that scene's background; the "…" menu can remove the background, leaving just the name and a line), the command lines that follow as a row of one-line cards
(colored by kind; sprites show the character's face and color; details such as fade, time and volume are in the parameter panel), dialogue with the face, name and text, narration as text with the face column left empty,
and choices as a card (click "→ jump target" on a choice to go there).
Comment lines that continue from the line above (such as the explanation at the top of a file) are grouped together; while collapsed, the group shows its first line and "N more lines" (click to expand; every expanded line can be edited, and a group expands when Find in the file lands inside it).
Lines with errors and warnings get a wavy underline on their content (the text, the command card, the scene name) and a mark ("!") on the left. The diagnostics are the same as the wavy underlines in the code view
(the check as you type and the whole check on save; `editor/lint.ts`). Click the mark to show a card with the message, the suggested fix and "Fix" (when there's a fix that can be applied) (`block-marks.ts`).
**Drafts**: "Mark as draft" in the right-click menu (and "…") of a file in the scene list writes `// lim: draft` at the top of the file ("Unmark as draft" removes it; for the open file it's an editor change).
Draft files show "Draft" next to the name, and aren't in exports, the all-routes test or coverage (they can still be test played; "Drafts" in [format.md](../design/format.md)).

**Scene info**: "Scene info" in the right-click menu (and "…") of a scene in the scene list, a scene heading in the block view, a card in the flowchart, and in the script heading menu,
writes the point of view (character IDs and speaker names are suggested), the date in the story and the place to `scenes` in liminalia.json (`file` or `file#label`; `POST /scenes`, other fields are kept).
The staging rules (Check in the project settings) read it.

**Format**: "Format" in the script heading menu and in ⌘K tidies the open file the same way as `lim fmt` (spaces in command lines and expressions, and block indentation if `fmt.indent` is set).
It goes in as one editor change, so ⌘Z undoes it. Files with syntax errors aren't tidied, and the reason is shown.

The files in the scene list and the file tabs get a dot for errors and warnings (red if there are errors, yellow if there are only warnings; the check as you type for the open file, the check results for the others).
Each time the script changes, only the groups (pages, lines) where one of the following changed are rebuilt: the line number, the text, the parse result, or the look decided by the duration bars (the background of the scene heading, the face on dialogue).
Everything else reuses the elements drawn before, and only the places whose order changed are moved (`itemKey` in `blocks.ts`; groups are also rebuilt when you start editing them in place and when characters or other image sources change).
When you switch to the block view, only the groups in the 120 lines above and 360 lines below the place to show (the line you were looking at before switching, or the cursor line) are built right away.
The rest get placeholder boxes of approximate height (`.blk-pending`; the height is estimated from the kind of line by `estimateHeight` in `model/blocks.ts`, which also estimates the height of pages off screen),
which are replaced 12ms at a time, starting nearest to where you are looking (for an 8,000-line file, switching went from about 700ms to 60–80ms, and the rest is built within about a second).
When you move to, select or edit a line that isn't built yet, the area around it is built first. While building, the line you are looking at doesn't move (the browser's scroll anchoring takes care of this, and in browsers without it, the scroll is adjusted by the difference in height).
**Find and replace in the block view** (⌘F; `block-find.ts`): shows a small field at the top right of the blocks (with selected text, it looks for that). It searches the lines of the .lim file themselves (the same text as ⌘F in the code view),
and "Text", "あア", "Aa" and ".*" below the field switch the same options as the project search (text only, ignore hiragana and katakana, match case, regular expression).
The options are shared with the project search and remembered (`search-flags.ts`), so switching one in either place switches it in the other. Replacing with a regular expression can use `$&`, `$1` and so on, and a pattern that can't be read shows "Not a valid regular expression" where the count goes.
It counts lines that aren't built yet (placeholder boxes) too and shows "N of M", and builds the groups with matches before the ones around where you are looking (the 40 nearest the current match right away, the rest a little at a time).
Lines with matches get a background, the line of the current match gets an outline, and matching characters in the drawn text get a text highlight (CSS Custom Highlight; where the drawn text differs from the .lim text, such as command parameters, only the line is marked).
Enter (and the ↓ button) goes to the next match and Shift+Enter to the previous one, selecting that line (the preview follows). "Replace" opens the replace field: "Replace and find next" replaces the current match and moves on (to the next match after the replaced text, so it doesn't keep returning to the same place even when the replacement contains the search text), and "Replace all"
replaces every match in the file as one change (⌘Z undoes it in one step). Read-only files aren't replaced. Esc (even while a button in the panel has focus) or the close button closes it, and so does switching to the code view.
Click the face on a line of dialogue (only for characters with variants) to see the expressions of the sprite set shown at that line in a list of faces (`face-picker.ts`; the faces are cropped with "Face position" on the Characters screen).
Choose one to rewrite the variant of that character's `@chara` in the page of that dialogue (from after the previous text up to the dialogue), or, if there is none, to add `@chara character variant` before the dialogue (`model/expression.ts`; a character not on screen appears at the default position; ⌘Z undoes it).
The variant field in the parameter panel (parameters of the variant type, such as `@chara` and `@face`) also chooses from the same list of faces once the character is known (with "Not set" at the top if it isn't required). Completion in the code view also shows faces at the start of character and variant suggestions.
Character completion lists the characters that appear near the line (speakers of dialogue and commands that name a character) first, nearest first (`model/cast-ranking.ts`; it looks past branches and right after them as the same scene, and stops at labels, scene changes, and `@jump` and `@return` in the same flow).
For parameters that act on sprites on screen (the `shown` type: built-in and standard commands such as `@chara-hide`, `@chara-move` and `@chara-shake`, plugin commands written with `t.cast(…, { shown: true })`, and macros that first pass the parameter to such a parameter in their body),
the characters shown just before that line go further up with an "On stage" mark, and the other characters stay below them (`shownBefore` in `complete.ts`; it reads the stage played the same way as the cursor line's current position.
`@chara`, `@chara-hide`, `@chara-hide-all` and `@scene-change` written before the current position arrives are applied by the completion first. It doesn't filter, since branches and half-written lines can make it wrong. Lines without a route state use the usual order).
If a plugin has the hook (`suggestAssets`; `docs/plugins.md`), completion of asset values lists up to five assets that fit the scene being written at the top, with a "Fits the scene" mark (`suggest` in `complete.ts`; a source separate from the usual suggestions, which doesn't make you wait even when it's slow).
The list of faces is ordered by the variants the script uses most for that character and sprite set (the counts in `variants` of `GET /cast/usage`; ties and variants not yet used follow the order in `cast.json`).
Click the name on a line of dialogue, or choose "Change speaker" in the right-click menu of a text line, to choose again from the list of speakers (faces and names, with "Narration" last) (`model/speaker-change.ts`).
Changing the speaker of dialogue replaces only the name at the start of the line (`{name …}` and the text stay as they are). Changing it to narration removes the name and the outer brackets or quotation marks (and adds a leading full-width space, the Japanese paragraph indent, if more than half of the narration in that file has one).
Changing narration to dialogue removes the leading space and, if the text doesn't already start with a bracket or quotation mark, wraps it in 「」 (Japanese quotation brackets), or in `""` in a project whose source language is English (the first entry of `languages` in liminalia.json is `en`). Text that starts with a quotation mark gets a half-width space between it and the speaker name. "Emphasize dialogue" next to the name on a line of dialogue (it appears when you hover over the line), or "Emphasize this person's dialogue" in the line's right-click menu, fades every line except that person's dialogue (`speaker-focus.ts`; it only changes how it looks, doesn't change the document and isn't remembered). A text line and the command lines just before it are grouped as a page (only in how they look; wherever you move a command,
pages are redrawn with text lines as the breaks; how they are divided is in `model/blocks.ts`). Labels and flow commands are one row each,
and `@choice`, `@define` and `@script` are grouped into one row up to `@end`. Drag the handle on the left of a line (for a card, the handle that appears on its left when you hover over it), and a copy of that line follows your finger (mouse),
leaving a gap where it will go. The gap moves between lines (inside pages too) to match the height of your finger, and the lines around it slide out of the way (when the OS is set to reduce motion, they are placed without sliding).
Release to drop it into the gap, or press Esc to cancel. Dragging to the edge scrolls automatically. The handle at the top left of a frame moves the whole page
(the gap goes only between pages). Drag a part from the parts panel (opened with the icon above the script), and a gap with the part's name moves in the same way;
drop it to add it there (for a command, the form opens; double-click to add it after the selected line. The "Dialogue" part adds `Speaker「」`, or `Speaker ""` in a project whose source language is English, where the first entry of `languages` in liminalia.json is `en`). Click a selected line again to edit text in place
(Enter confirms, Esc cancels. Home and End move the cursor to the start and end of that line, and with ⌘, or PageUp and PageDown, to the start and end of what is being edited.
On the Mac, Home and End only scroll the list, so while editing they aren't passed to the list), or to open the form for a command. Delete removes it, as does the × that appears at the right end when you hover over a line (and on the selected line) (⌘Z undoes it). Markup inside the text (ruby, line breaks, click waits, inline commands) is rendered as formatting in the blocks (the text itself doesn't change).
Select a range of lines by dragging anywhere except a line's handle (for a card, the card itself), with Shift-click, or with Shift+up and down (⌘A selects all), and copy, cut, paste (after the selected line) and duplicate with ⌘C, ⌘X, ⌘V and ⌘D. ⌥↑ and ⌥↓ move the selected lines past the line above or below (the same in the code view).
Open the list of keyboard shortcuts with ? (when you aren't typing), ⌘/ (outside the code view), or "Keyboard shortcuts" in the "…" menu. The list is built only from the table in `shortcuts.ts`, and is shown with Ctrl+ on Windows and Linux (when you add a key, add it to the table too).
Keys in the code view follow VS Code (⌥↑↓ moves lines, ⇧⌥↑↓ copies lines, ⌘⌥↑↓ adds cursors, ⌘L selects the line, ⌘/ comments it out, ⇧⌘K deletes the line, ⌘D adds the next occurrence of the word to the selection). ⌥PageUp and ⌥PageDown jump to scene headings.
Copied lines can be pasted as text into other apps, and lines copied in other apps can be pasted too. Right-click a line for a menu with the same actions plus "Play from Here" (⌘⌥P), "Go to Jump Target" (F12; only on lines with a jump target), items that open what the line (for a page, every line in it) uses, such as "Open character "Akari"," "Open background "hill.webp"," "Open scene "#night"" and "Open variable "game.x""
(`model/line-refs.ts`: the speaker of dialogue and parameters of the character type, parameters of the asset type (that folder if `folder=` is given), jump targets (except one already covered by "Go to Jump Target," and expressions), and `game.`, `system.` and `temp.` variables; up to 8, each opening on the Characters, Assets, Script or Variables screen), "Add comment" (⌘⌥M), "Breakpoint," "Add to favorites" and "Delete"
(right-clicking the handle on the left of a page applies to the whole page; for a scene heading, "Lines Leading Here" and the scene actions are included too). Lines added to favorites are listed under "Favorites" at the top of the parts panel (kept per project in `favorites` in `.liminalia/studio.json`, and not included in the game; favorites from before, which were kept in localStorage and shared across projects, are copied once to the end of the project's favorites when a project is opened (identical sequences of lines aren't copied; `favorites.ts`)).
Like parts, they are added by dropping or double-clicking, and removed with a right-click.

**Keyboard and screen readers** (checked by `dev/verify-a11y.ts`):

- The block view's list is a single place for input that selects lines (a listbox). Lines are options; the up and down arrows move between them, and the selected line is announced with `aria-activedescendant`.
  The name read out is "speaker, text" for dialogue, the text for narration, the name and summary (the card's text) for command cards, "Scene #name" for scene headings and "Choice, …" for choices. Pages are groups of lines
- The "…" and × buttons on lines and the button that emphasizes a speaker aren't in the Tab order. Shift+F10 (and the menu key) opens the right-click menu of the selected line, and Esc returns to the list
- F6 and ⇧F6 move focus through scenes, script, preview, thumbnails and the top bar in that order (closed panels are skipped; on other screens, between the top bar and that screen)
- Only one row of the scene list (folders, files, scenes, New file) is in the Tab order (the current scene or the current file). ↑↓ move to the previous and next row, ← → collapse and expand files and folders
  (moving inside when already expanded; ← on a scene goes to its file), Home and End go to the first and last row, and Shift+F10 (and the menu key) opens the row's menu. The fold, "…" and + buttons on a row aren't in the Tab order
- "/" opens the list for choosing a part to add after the selected line (the same panel as ⌘K). "Insert part…" in ⌘K does the same (after the cursor line in the code view)
- Parts in the parts panel are buttons, and Enter or Space adds the part after the selected line. Enter in the search box adds the best match, and ↓ moves into the parts (arrows move between parts)
- In the flowchart, entering the canvas selects the card of the scene with the script cursor, and the arrows move to the nearest card in that direction (scrolling it to the middle if it isn't visible).
  Enter goes to that scene's script and Shift+F10 opens the card's menu. The selected card has a dashed outline and is announced with `aria-activedescendant`

**Spell check**: in projects whose source language isn't Japanese (the first of `languages` isn't `ja`), only the text of dialogue and narration is checked (`editor/spell.ts`; the code view marks that text with
`spellcheck="true"`, and command lines, speaker names and comments aren't checked; the block view checks while editing in place). Japanese projects aren't checked.
The desktop app turns spell checking on in project windows, sets the dictionary language to the project's source language (on a Mac, the OS works out the language), and adds suggestions and "Add to dictionary"
to the right-click menu of misspelled words (`studio-desktop/src/main/spellcheck.ts`). `lim studio` in a browser uses the browser's spell checking and right-click menu.

Lines in the block view also show the same comment and breakpoint marks as the code view (`block-marks.ts`; it keeps no state of its own and refers to the code view's marks; the marks sit to the left of a line, at the top left of a card, and to the left of a choice).
Click a comment mark to show its thread in the right panel, and click a breakpoint mark to remove it. Breakpoints stop at command lines, so right-clicking inside a choice puts the breakpoint on the `@choice` line (a comment goes on the choice line you clicked).

Parts are arranged in sections (Common, Text, Flow, Backgrounds and screen, Sprites, Sound, Motion, Progress and system, Custom commands). Each section opens and closes with its heading (remembered).
Inside a section, cards with an icon in the section's color and a short name are laid out in 2 columns
under subgroup headings (for Backgrounds and screen: Background, Fades and color, Shake and camera, Weather and particles and so on; `group` in `command-meta.ts`) (names wrap to at most 2 lines; the `@command-name` and long names appear on the description card shown on hover).
For built-in and standard commands, the description card (it stays when you move onto it), the right-click menu of a part and the parameter panel show "Learn more,"
which opens the command reference on the site (`/reference/<name>/`).
Rarely used commands such as waiting, stopping and resetting (`advanced` in `command-meta.ts`) are collapsed under "More commands" at the end of the section (whether it is open is remembered).
"Common" lists recently added parts (up to 6; `liminalia.studio.recentParts`) under "Recently used" and a fixed set of parts under "Everyday."
The Scenes and Parts panels close with the close button in their heading, and after closing, click the name (trace) left at the edge to open them again (in the phone app, the parts panel opens with the button in the script bar).

Custom commands are commands added by plugins. When two or more share the same first part of their name (such as `fx-`), they are grouped under that prefix
(where each command comes from is in `commandSources` in `/project`; if a plugin writes `category` in a command definition, the command is listed in that section).
The sections, the words for what you want to do and the moving previews of the built-in commands are all in the engine's `packages/lang/src/command-meta.ts`.

Searching with the field at the top removes the sections and lists the results under "Matching parts" in order of relevance: matches by name, then by words for what you want to do (such as shake, fade to black and rain;
`keywords` in `command-meta.ts` and the `keywords` of plugin commands), then by description, parameter description and syntax example.
It ignores the difference between katakana and hiragana and between upper and lower case.

Hover over a command part to show a description card beside it (description, syntax example, main settings). For commands with a sample line (`preview`) in `command-meta.ts`,
a small preview using the project's first background and its first character with variants runs that command over and over to show it (the game's `/?ui-preview=command&cmd=<command-name>`).
When there is no background or character, a short note says the sample can't be shown. Command forms also show the syntax example below the description.

Script files are handled with "New file" at the very bottom of the scene list and with the menu from a file name's "…" or a right-click (Add a scene, New file, Duplicate, Rename, Move to trash).
Names use letters, digits, `_`, `-`, and `/` to separate folders. Renaming a file also moves the jump targets in other files (`@jump`, `@call`, `@use`, choices, jump target parameters;
also jump target parameters in `{@…}` in text, and the strings in `visits("file#label")` and `read("file")` in expressions) and the change history, and if it is the "New game" file, rewrites `entry` in liminalia.json too (the game picks it up after a restart).
Other places that hold the file name are moved too: `afterLoad` in liminalia.json, the `target` of extras recollections and chapters, flowchart title keys, initial values of variables used as jump targets,
`files` in `chapters` (names without wildcards; you are told when a wildcard won't match the new name), the keys of `scenes`, `check.sound.quiet`, the keys of translations and `voice-lock.json` (`file:…`),
script tests (the places in `from` and `expect reach` in `tests/*.limtest`, and `visits` and `read` in expressions),
threads in `reviews/`, bookmarks, breakpoints and `lastOpen` in `.liminalia/studio.json`, `mapPositions` in `.liminalia/shared.json`, and the baseline images of `lim regress`.
Renaming a scene, a variable or a speaker name rewrites script tests too (`file#label` for scenes, the expressions of `set` and `expect` for variables, and `expect text` compared with the speaker name for speaker names).
If saving fails partway through a rename (of a file, asset, variable or character), what was already saved is put back before the failure is returned (`server/undo.ts`; the same as renaming a scene; anything that couldn't be put back is named).
The rewriting of scripts and settings is in `client/model/name-rename.ts`, and `lim rename` and renaming in the VS Code extension use the same code. Renaming a character also rewrites `{@chara …}` in text,
and for lines whose text was rewritten (`{= variable}`, `{@chara …}`, `{img …}`), translation keys and `voice-lock.json` keys are moved to the new key of the same line (variable names inside translations are changed too).
Rename a macro (`@define`) with "Rename macro" in ⌘K when the cursor line is a macro, or with "Rename macro…" in the menu of "Lines using this macro"
(`POST /macros/rename`; the same `renameMacro` in `server/manage.ts` as `lim rename macro` and F2 in VS Code. It rewrites `@define` and the calls, `{@…}` in text and the keys of `commandDefaults`).
When `@define` with the same name is in two or more files, "@define to rename" above the name field chooses which file's one to rename (it starts at the file of the cursor's `@define` line,
or the one a call from the open file reaches). Only that file and the files whose calls reach that file's `@define` are rewritten (files without their own `@define` where that file is the first `@use` that has it, the same as the player),
and the key in `commandDefaults` is copied to the new name, keeping the old one.
A file moved to the trash can be brought back with "Undo" in the notice or on the "Trash" screen (the "New game" file can't be deleted).

**Scene actions** are the same wherever you open them: the "…" or right-click of a scene row in the scene list, a scene heading in the block view or a flowchart card, or the script heading menu (for the cursor's scene) (`sceneItems` in `app.ts`; the logic is in `editor-actions.ts`):
"Edit tags and status," "Rename scene," "Duplicate scene," "Move to another file," "Split the file from here" and "Delete scene." In read-only files, only tags and status can be used.

- Edit tags and status: gives the scene a status (Draft, Needs review, Reviewed), a color (red, yellow, green, blue, purple, pink, gray) and tags (separated by commas; tags already in use are suggested)
  (`scene-marks-dialog.ts`; the scene at the top of a file can have them too). They are kept in Studio's shared data (`sceneMarks` in `.liminalia/shared.json`, keyed by the same scene id as the flowchart,
  `file#label`, or `file` for the scene at the top of a file) and go into neither the game nor the .lim files. Renaming the scene or the file and moving the scene to another file change the key too.
  The scene list shows a dot before the scene name (the color if set, or else the status color: gray for Draft, yellow for Needs review, green for Reviewed; hover to see the status, color and tags),
  and the menu at the top of the list (shown only when some scene has tags or a status) filters by all, scenes with tags or status, a status, a color or a tag (while filtering, matching scenes are listed even in files that aren't expanded).
  The flowchart shows the same dot before the card name and the status and tags over the bottom left of the picture, and filters the same way with a menu in the top bar. ⌘K also finds them by status name and tag (`#tag`) (`model/scene-marks.ts`)

- Duplicate: puts a copy at the end of the file with the name `name_2` (the first free number). It is an editor change, so ⌘Z undoes it. It doesn't change the flow:
  if the original scene ran straight on into the next scene, `@jump #next-scene` is added at the end of the copy, and if the last scene of the file stopped at the end of the file, `@stop` is added at its end
- Delete: deletes the scene's lines (it is an editor change, so ⌘Z and "Undo" in the notice undo it). If lines that lead to this scene remain, the notice includes how many (they appear in the check as jump target errors)
- Move to another file: asks for the destination file (existing files are suggested; a name that doesn't exist creates a new file, and "New file" appears below the field; folders such as `part2/rest` can be created too),
  and moves the scene to the end of that file (`POST /scenes/move`; the text is assembled in `model/scene-move.ts`, and the files are handled in `server/scene-move.ts`)
- Split the file from here: moves everything from that scene to the end of the file into a new file (it asks for the name; the default is `file_2`). Otherwise it is the same as Move to another file

What is rewritten when a scene is moved (the same mechanism as renaming a scene; `toFile` in `LabelTarget`):

- Jump targets anywhere in the project that point to the moved scene (`@jump`, `@call`, choices, expression candidates and `to=`, jump target type parameters, `{@…}` in the text, `data-jump` in `@html`) are pointed to the destination.
  `#scene` in the original file becomes `destination#scene`. A `#scene` put in a variable is resolved in the file doing the jump, so after a move it always becomes `file#scene`
- Among the `#label`s inside the moved scene, those that point to scenes staying in the original file become `original-file#label` (those that point to scenes moved along with it stay as `#label`)
- The flow doesn't change: `@jump destination#scene` is added at the end of a scene that ran straight on into the moved scene; if the end of the moved scene ran on into the next scene, `@jump original-file#next-scene` is added; and
  if the last scene of the destination file stopped at the end of the file, `@stop` is added at its end (the notice shows how many lines were added; whether a scene runs on is judged the same way as "Continues" in the flowchart)
- The `@use` lines of the original file, and the original file's macros that the moved scene calls (`@use original-file`), are added at the top of the destination
- `liminalia.json` (`entry`, `afterLoad`, extras recollections and chapters, flowchart titles, initial values of variables), `mapPositions` in `.liminalia/shared.json`, and the names of the `lim regress` baseline images
- The keys of translations and `voice-lock.json` (keys are made from the file and the original text, so the keys of moved lines are copied to keys for the destination file, and the original keys are removed if nothing uses them anymore). Threads in `reviews/` attached to moved lines move to the destination lines, and so do the marks in `bookmarks` in `.liminalia/studio.json` attached to moved lines
- References that couldn't be rewritten (inside `@script` and so on) are reported in the same list dialog as for renaming. The open file is updated to the rewritten content while keeping its undo history

Studio refuses when the scenes aren't next to each other, when the scene is at the top of the file, or when the destination has a scene with the same name (rename it first). If the destination or original file was changed elsewhere, it refuses without writing anything.
If saving fails partway through, what was already saved is put back, as with renaming (files it created are deleted). Saves (file and command numbers) and read marks shift by the moved lines, as with any other edit.

Rename a scene (label) with "Rename scene" in the scene actions (`POST /labels/rename`; the text is rewritten in `model/label-rename.ts`, and the files are handled in `server/labels.ts`).
Invalid names and duplicates within the same file are refused, with the reason shown below the field. It can't be used in read-only files. What it rewrites:

- Scripts (through the write API, so they are kept in the change history): label lines, `@jump`, `@call`, choice jump targets (both `#label` in the same file and `file#label`), strings inside jump targets given as expressions and `to=` candidates, `@set` and `@let` that put strings in variables used as jump targets,
  jump target type parameters (including `{@…}` in the text), `data-jump` in `@html`, and the strings in `visits("#label")` and `read("file#label")` in expressions. A `#label` put in a variable (and the initial values in the settings) is resolved in the file doing the jump, so it is rewritten only when the project has just one label with that name; if there are others, it isn't rewritten, and you are told.
  Macro (`@define`) parameters and defaults have no target type, so only `file#label` is rewritten, and `#label` is left as it is, and you are told
- `liminalia.json`: `entry`, `afterLoad`, the `target` of `extra.replay` and `extra.chapters`, the keys of `extra.flowchart.titles`, initial values of variables used as jump targets, the keys of `scenes`, and `check.sound.quiet`. If `entry` or `afterLoad` is rewritten, the dev server's current position data and the flowchart use the new place right away, and the game picks it up after a restart (you are told so)
- Script tests (`tests/*.limtest`): `file#label` in `from` and `expect reach`, and `visits("file#label")` in the expressions of `set` and `expect`. `visits("#label")` without the file has no file to resolve it in, so it isn't rewritten, and you are told
- `mapPositions` and `sceneMarks` in `.liminalia/shared.json` (keyed by `file#label`), and the baseline images in `.liminalia/regress/baseline` (named `file_label.png`)

`liminalia.json` is saved only when its content changes. If saving fails partway through, what was already saved is put back before the failure is returned (scripts go through the write API, so the writes that put things back are also kept in the change history; anything that couldn't be put back is named).
- The line content of threads in `reviews/` attached to rewritten lines
- The keys of translations (`lang/*.json`) and `voice-lock.json` are made from the file and the original text, so they have no labels. Only lines where a `{@…}` jump target in the text was rewritten have a changed original text, so the keys of those lines are replaced (jump targets inside the translated text are rewritten too)

Things left alone because they hold no labels: saves (file and command numbers), read marks (keys made from the file and from the speaker and text of each page), the change history, `lastOpen` and breakpoints (they follow the line content). The flowchart records left on players' devices (`scene:<id>`, where the id is `file#label`) can't be rewritten from Studio. References that can't be rewritten (inside `@script`, jump targets decided by expressions such as a string put in a variable being used as a jump target in another file,
jump targets a plugin command takes from project data, files that were changed elsewhere and couldn't be saved) are reported in a list dialog; click one to go to that line. The open file is updated to the rewritten content while keeping its undo history.

"Import text" above the script makes dialogue and narration lines from text or a table (CSV or TSV; a table copied from a spreadsheet is fine) and inserts them.
`Name「…」`, `Name "…"`, `【Name】…` and `Name: …` become dialogue (wrapped in 「」 if there are no brackets or quotation marks, or in `""` in a project whose source language is English), and everything else becomes narration (you can choose whether to add a full-width space, the Japanese paragraph indent, at the start).
For a table, it uses the column headed "名前" or "話者" (or name, speaker) and the column headed "本文" or "セリフ" (or text). `{`, `}` and `\` in the text, and `@`, `#` and `//` at the start of a line, are escaped, and lines already written in .lim syntax
pass through as they are. Ruby written with 《》 (`｜base《reading》` and `kanji《kana reading》`) becomes `{r base|reading}` (brackets around titles such as 「絵画《星月夜》」 are left alone). You can choose whether to add names that aren't speakers yet as speakers, and whether to insert after the cursor line or make a new file (⌘Z undoes it).
Choose Ink, Yarn Spinner, Ren'Py or Twine (Twee 3) in the format (or drop a `.ink`, `.yarn`, `.rpy` or `.twee` file, or let it detect the format automatically),
and it converts to .lim with labels, choices, conditional branches and variables, using the same conversion as `lim import-ink` / `import-yarn` / `import-renpy` / `import-twine`.
It converts into a single file, writes variable initial values as `@set` at the top, and turns parts that can't be converted into comments, showing how many and why alongside
([ink-yarn-import.md](../ink-yarn-import.md)). Characters shown with Ren'Py's `show` are listed alongside so you can add them as characters (`lim import-renpy` adds them to cast.json automatically).

The Scenes, Parts, Preview and Thumbnails panels open and close with the close button in their heading and the trace at the edge (Scenes, Preview and Thumbnails also from the "…" menu). "Enlarge" is in the preview heading. The timeline collapses with the chevron in its heading (all of this is remembered;
the timeline and the parts panel are closed at first). The widths of the scene list and the right panel can be changed by dragging the border (remembered; double-click for the original width;
the width of the right panel while enlarged is remembered separately).

From the top, the right panel has the preview (16:9), the row of controls below it (Pause, Resume, Mute, Cursor sync, device, screenshot, New window, Full screen), the line and route display, the parameter panel, the current state of the preview (background, BGM, sprites and looping sound effects, one per row, with the line that set each; click one to go to that line),
then, below a divider, the variables (each value and the line that last set it) and the timeline. The list of variables is closed at first; click "Variables" to open or close it. While paused, the same button changes to the resume icon. Click the preview to move the story forward.

Put the cursor on a command line, and the parameter panel for that line opens on the right; moving to another command line switches its contents. Moving to a text line or similar closes it. Commands inside text are edited by clicking their tags, as before. On a phone, moving the cursor alone doesn't switch the screen.
In the code view, hovering the pointer over a command's argument shows that argument's type, default and description. This also works for shorthand true/false values such as `solo`, values such as `at=left`, and unnamed arguments.
While you're typing, popovers with descriptions or diagnostics shown for another line close. The description for the line being edited stays.

**Trying values in the preview**: while the preview shows text or choices (including while it is stopped at a breakpoint or paused), click the value on a variable's row in the right panel to change it on the spot (Enter or clicking outside confirms, Esc cancels;
numbers, `true`, `false`, `null`, `"…"`, `[…]` and `{…}` are read as they are, and anything else as a string; if the current value is a string, it stays a string even if it looks like a number). This changes only the values of the runner running in the preview (`game.`, `temp.`, `system.`), and nothing at all is saved to files or initial values.
A changed row gets a "Changed" mark (click it to go back to the original value), and the script cursor moves to the preview's line and is drawn with "State at this line (preview)." Resume or click the preview to move forward, and branches follow that value.
If the script puts a different value in the same variable, the mark goes away. If you move the cursor and the preview is rebuilt, changed values go back to the values at that point, and a short note above the variables says so.
Values can't be clicked while the preview shows a command line (where the runner doesn't move forward). `system.` rows show what the preview's runner holds (`content_filter` and `packs`, which the engine sets itself, only when the script uses them or you changed their values) (`temp.` only shows the preview runner's values when the state was reached by moving the preview forward).

**Thumbnails** lists the text and choice pages of the open file side by side, each as a small preview of the background and sprites at that page (built from the duration bars).
Below each are a dot in the speaker's color (gray for narration, violet for choices) and the line number, and label names at scene breaks. The page of the cursor line (that line's page, or the next page) is marked;
click a page to go to that line.
