feat(cli): focus-based nested scrolling in shell toolboxes to prevent scroll-jacking

This commit is contained in:
Keith Guerin
2026-03-01 00:51:12 -08:00
parent 703759cfae
commit ae04632a59
2 changed files with 7 additions and 3 deletions

View File

@@ -78,7 +78,7 @@ export const ShellToolMessage: React.FC<ShellToolMessageProps> = ({
embeddedShellFocused,
);
const { setEmbeddedShellFocused } = useUIActions();
const { setEmbeddedShellFocused, setActivePtyId } = useUIActions();
const wasFocusedRef = React.useRef(false);
React.useEffect(() => {
@@ -102,6 +102,7 @@ export const ShellToolMessage: React.FC<ShellToolMessageProps> = ({
const handleFocus = () => {
if (isThisShellFocusable) {
setActivePtyId(ptyId);
setEmbeddedShellFocused(true);
}
};

View File

@@ -119,6 +119,9 @@ export const Scrollable: React.FC<ScrollableProps> = ({
const scrollBy = useCallback(
(delta: number) => {
if (!hasFocus) {
return;
}
const { scrollHeight, innerHeight } = sizeRef.current;
const maxScroll = Math.max(0, scrollHeight - innerHeight);
const current = Math.min(getScrollTop(), maxScroll);
@@ -129,7 +132,7 @@ export const Scrollable: React.FC<ScrollableProps> = ({
setPendingScrollTop(next);
setScrollTop(next);
},
[getScrollTop, setPendingScrollTop],
[getScrollTop, setPendingScrollTop, hasFocus],
);
const { scrollbarColor, flashScrollbar, scrollByWithAnimation } =
@@ -210,7 +213,7 @@ export const Scrollable: React.FC<ScrollableProps> = ({
overflowX="hidden"
scrollTop={scrollTop}
flexGrow={flexGrow}
scrollbarThumbColor={scrollbarColor}
scrollbarThumbColor={hasFocus ? scrollbarColor : undefined}
>
{/*
This inner box is necessary to prevent the parent from shrinking