refactor(web): drop the dead shouldPinScroll helper and trim the reveal tests to two invariants
ChatPage no longer pins the page to (0, 0); keyboardRevealScrollDelta is the only caller-facing helper left in keyboard-inset.ts. Update the isActive-effect comment that still described the pin.
This commit is contained in:
@@ -3,7 +3,6 @@ import {
|
||||
computeKeyboardInset,
|
||||
keyboardRevealScrollDelta,
|
||||
KEYBOARD_INSET_MIN_PX,
|
||||
shouldPinScroll,
|
||||
} from "./keyboard-inset";
|
||||
|
||||
describe("computeKeyboardInset", () => {
|
||||
@@ -69,23 +68,7 @@ describe("computeKeyboardInset", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldPinScroll", () => {
|
||||
it("pins while a keyboard inset is active", () => {
|
||||
expect(shouldPinScroll(320)).toBe(true);
|
||||
});
|
||||
|
||||
it("does not pin without a keyboard", () => {
|
||||
expect(shouldPinScroll(0)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("keyboardRevealScrollDelta", () => {
|
||||
it("scrolls the page so the composer sits on the visual-viewport bottom", () => {
|
||||
expect(
|
||||
keyboardRevealScrollDelta(800, { height: 480, offsetTop: 0 }),
|
||||
).toBe(320);
|
||||
});
|
||||
|
||||
it("accounts for iOS visual-viewport offsetTop", () => {
|
||||
expect(
|
||||
keyboardRevealScrollDelta(800, { height: 480, offsetTop: 40 }),
|
||||
@@ -97,10 +80,4 @@ describe("keyboardRevealScrollDelta", () => {
|
||||
keyboardRevealScrollDelta(480, { height: 480, offsetTop: 0 }),
|
||||
).toBe(0);
|
||||
});
|
||||
|
||||
it("returns 0 for non-finite geometry", () => {
|
||||
expect(
|
||||
keyboardRevealScrollDelta(NaN, { height: 480, offsetTop: 0 }),
|
||||
).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,19 +57,6 @@ export function computeKeyboardInset(
|
||||
return inset >= KEYBOARD_INSET_MIN_PX ? inset : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the page scroll should be pinned back to the top.
|
||||
*
|
||||
* The dashboard shell is a fixed `h-dvh` column and must never scroll, but
|
||||
* iOS Safari auto-scrolls the *page* when a focused input would sit under
|
||||
* the keyboard (xterm's hidden textarea triggers this). Pin whenever a
|
||||
* keyboard is present so the terminal chrome stays put; the terminal's own
|
||||
* scrollback handles content visibility.
|
||||
*/
|
||||
export function shouldPinScroll(nextInsetPx: number): boolean {
|
||||
return nextInsetPx > 0;
|
||||
}
|
||||
|
||||
/** Pixels to `window.scrollBy` so the composer (xterm host bottom) sits on
|
||||
* the visible bottom of the visual viewport — just above the keyboard.
|
||||
* Pinning the page to (0, 0) fights iOS and can leave the input line off-screen. */
|
||||
|
||||
@@ -1597,7 +1597,7 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
|
||||
// NS-434 follow-up: attach the visualViewport keyboard-inset listeners
|
||||
// ONLY while the chat tab is actually visible. ChatPage stays mounted
|
||||
// (display:none) on every other dashboard route, so unconditional
|
||||
// listeners made the scroll pin (`window.scrollTo(0, 0)`) fire whenever a
|
||||
// listeners made the composer reveal (`window.scrollBy`) fire whenever a
|
||||
// soft keyboard opened on Settings/Sessions/etc., fighting iOS Safari's
|
||||
// own scroll-into-view for the focused input there. The handlers read
|
||||
// through refs populated by the main PTY effect, so attach/detach here is
|
||||
|
||||
Reference in New Issue
Block a user