mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 12:25:44 -05:00
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`.
38 lines
949 B
TypeScript
38 lines
949 B
TypeScript
import type { Terminal } from 'ghostty-web';
|
|
|
|
export type WrappedRowSource = Pick<Terminal, 'buffer' | 'getScrollbackLength'>;
|
|
|
|
const MAX_JOINED_ROWS = 64;
|
|
|
|
export const continuesPreviousRow = (terminal: WrappedRowSource, y: number) => {
|
|
const buffer = terminal.buffer.active;
|
|
const line = buffer.getLine(y);
|
|
|
|
if (!line || y <= 0) {
|
|
return false;
|
|
}
|
|
|
|
if (y >= terminal.getScrollbackLength()) {
|
|
return line.isWrapped;
|
|
}
|
|
|
|
const previous = buffer.getLine(y - 1);
|
|
|
|
return (previous?.getCell(previous.length - 1)?.getCodepoint() ?? 0) > 32;
|
|
};
|
|
|
|
export const wrappedRowsAround = (terminal: WrappedRowSource, y: number) => {
|
|
let first = y;
|
|
let last = y;
|
|
|
|
while (y - first < MAX_JOINED_ROWS && continuesPreviousRow(terminal, first)) {
|
|
first--;
|
|
}
|
|
|
|
while (last - y < MAX_JOINED_ROWS && continuesPreviousRow(terminal, last + 1)) {
|
|
last++;
|
|
}
|
|
|
|
return { first, last };
|
|
};
|