This PR improves YAML syntax highlighting, selection rendering, and
search decorations across nested structures, multiline content, and
differently styled tokens.
Issues and fixes:
- YAML tokens in nested structures were not always classified correctly,
causing inconsistent syntax highlighting. The token classification logic
was refined to handle nested structures more reliably.
- Selection highlighting could render incorrectly across multiline
content and differently styled tokens. Selection rendering was updated
to preserve consistent highlighting in these cases.
- Search decorations could become misaligned with highlighted text.
Search marker alignment was corrected so decorations match the
corresponding content.
- Scrollbar markers did not always accurately reflect search results.
Scrollbar marker handling was improved to keep markers synchronized with
search decorations.
- Decoration layers could overlap or render in the wrong order.
Decoration layering was adjusted to ensure selection and search
decorations are displayed correctly.
Files with an empty MIME type were incorrectly rejected as folders when
their size was 0 or exactly 4096 bytes. One matching file also blocked
the entire upload batch.
This removes the MIME type and size heuristic from `useFileUploader` and
checks dropped items using `webkitGetAsEntry()` instead. Actual
directories remain rejected when the browser provides directory entry
information.
## Description
This PR resolves several visual artifacts, resize desync issues, and
edge-case rendering glitches with the Ghostty-web terminal integration
in the server console:
### 1. Reliable Terminal Resizing & Layout Transitions
- **Bypass `FitAddon` throttle lock (`unlockFitResize`)**: Ghostty's
`FitAddon` sets a 50ms `_isResizing` lock via `setTimeout`, which
silently dropped subsequent `fit()` calls triggered immediately after
layout/route transitions. Unlocking this ensures post-layout re-fits are
never lost.
- **WASM Line Bounds & Viewport Clamping (`patchWasmTerminal`)**:
- Guards against potential null/undefined line reads from the WASM
terminal (`getLine` and `getScrollbackLine` fallback to empty arrays).
- Synchronizes and clamps viewport coordinates during `term.resize` to
prevent scroll desync and jumps when resizing windows or toggling
devtools.
### 2. Precise Font Metrics & Clean Canvas Redraws
- **Canvas-based Font Measurement (`measureTerminalFont`)**: Accurately
computes font cell width, baseline, ascent, and descent using a 2D
canvas context instead of relying on rough estimates.
- **Artifact Prevention in `adjustRendering`**: Automatically flushes
and repaints the canvas background with the theme background color when
viewport offsets change or full redraws occur, eliminating ghosting/text
smearing.
### 3. Clear & Output Lifecycle Improvements
- **Terminal Clear Handling**: Extends `preserveScrollPositionOnWrite`
to intercept `term.clear()`, issuing ANSI reset escapes
(`\x1b[2J\x1b[3J\x1b[H`) and resetting viewport positions.
- **Prefix Newlines**: Normalizes `term.writeln` to ensure initial logs
and scrollback buffer transitions don't overwrite the first line.
### 4. Layout & Styling Polish
- Replaced negative margin gutter compensation hacks (`-ml-4
w-[calc(100%+2rem)]`) in `Terminal.tsx` with clean `w-full` and
`overflow-hidden`.
- Ensured consistent container and input rounding across mobile and
desktop breakpoints.
---
## Changes Overview
- `resources/scripts/components/server/console/useTerminal.ts`: Added
`unlockFitResize`, `measureTerminalFont`, `patchWasmTerminal`, viewport
clamping, canvas clear on redraw, and clear handling.
- `resources/scripts/themes/classic/views/server/console/Terminal.tsx`:
Cleaned container classes and removed mobile negative-margin overrides.
Fixes some internal Discord discussions.
Most of this works around gaps in ghostty-web 0.4.0's selection and link
handling. Several fixes reach into its private internals, so the
dependency is pinned to `0.4.0` now instead of free spinning.
Ghostty seems to be an overall regression as a library over XTerm, below
are some internal hook ins to provide vital functionality back to the
console that v1 originally had.
### Selection
- Double-click selects the word on the line you clicked. Ghostty's
`getWordAtCell` reads the live screen row whatever the scroll position,
so once you'd scrolled up it picked a word from a different line.
- Triple-click now selects and copies the whole line, including every
row it wraps onto.
- Copying no longer puts a line break where a line only wrapped.
Ghostty's `getSelection` puts `\n` between every row, which broke copied
URLs and commands. The fix covers Ctrl/Cmd+C, drag-copy, right-click
copy and triple-click. If a row wrapped at a space, the space is kept.
### Links
- URLs that wrap across rows are detected as one link, and hovering any
part of them underlines the whole URL.
- Only `http:` and `https:` links can be opened. Console output comes
from the game server, so a `javascript:`, `file:` or `ssh:` link in the
output is ignored rather than passed to `window.open`.
### Focus
- The page no longer scrolls when the console takes focus. Ghostty
focuses the console on open and its hidden textarea on every press; both
now focus with `preventScroll`.