forked from vadimdemedes/ink
-
Notifications
You must be signed in to change notification settings - Fork 6
fix(scroll): correctly calculate absolute Y for nested regions #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
842c373
Fix scroll of a nested child excessive update bug.
jacob314 e5b5329
Review fixes.
jacob314 8743263
test: refactor duplicated terminal buffer logic and remove fixed time…
jacob314 cc38b0d
More fixes
jacob314 bf36693
test: fix sticky overlap test layout and pty spawn errors
jacob314 c9301fd
Code review comment fixes.
jacob314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,6 +197,10 @@ function ScrollableContent({ | |
| } | ||
| }, [recordFilename, startRecording]); | ||
|
|
||
| const [innerStates, setInnerStates] = useState< | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tweaks to this sample to reproduce an issue noticed in Gemini CLI |
||
| Record<number, {scrollTop: number; isStatic: boolean}> | ||
| >({}); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| const boxWidth = columns; | ||
| const contentWidth = showBorder | ||
|
|
@@ -205,17 +209,22 @@ function ScrollableContent({ | |
|
|
||
| const staticContent = useMemo(() => { | ||
| const elements = []; | ||
| for (let i = 0; i < listItems.length; i += 20) { | ||
| for (let i = 0; i < listItems.length; i += 4) { | ||
| const headerIndex = i; | ||
| const headerId = headerIndex / 20; | ||
| const headerId = headerIndex / 4; | ||
| const headerText = `Sticky Header ${headerId}`; | ||
| const stickyHeaderText = `Sticky Header ${headerId} (sticky top)`; | ||
| const stickyFooterText = `Sticky Footer ${headerId} (sticky bottom)`; | ||
|
|
||
| const itemsInGroup = listItems.slice(headerIndex, headerIndex + 10); | ||
| const nextItems = listItems.slice(headerIndex + 10, headerIndex + 20); | ||
|
|
||
| const itemsInGroup = listItems.slice(headerIndex, headerIndex + 2); | ||
| const nextItems = listItems.slice(headerIndex + 2, headerIndex + 4); | ||
| if (headerId % 3 === 0) { | ||
| const innerScrollTop = | ||
| innerStates[headerId]?.scrollTop ?? | ||
| (headerId === 0 || headerId === 3 ? 0 : 40); | ||
| const useStaticForInner = | ||
| useStatic && (innerStates[headerId]?.isStatic ?? true); | ||
|
|
||
| const innerBox = ( | ||
| <Box | ||
| key={`inner-scroll-${headerId}`} | ||
|
|
@@ -224,7 +233,7 @@ function ScrollableContent({ | |
| overflowY="scroll" | ||
| borderStyle="single" | ||
| borderColor="cyan" | ||
| scrollTop={40} | ||
| scrollTop={innerScrollTop} | ||
| > | ||
| <Box flexShrink={0} flexDirection="column" overflow="hidden"> | ||
| <Box | ||
|
|
@@ -260,11 +269,11 @@ function ScrollableContent({ | |
| ); | ||
|
|
||
| elements.push( | ||
| useStatic ? ( | ||
| useStaticForInner ? ( | ||
| <StaticRender | ||
| key={`static-inner-scroll-${headerId}`} | ||
| width={contentWidth} | ||
| deps={[innerBox]} | ||
| deps={[innerBox, innerScrollTop]} | ||
| > | ||
| {() => innerBox} | ||
| </StaticRender> | ||
|
|
@@ -395,12 +404,45 @@ function ScrollableContent({ | |
| ); | ||
|
|
||
| return content; | ||
| }, [contentWidth, useStatic, listItems]); | ||
| }, [contentWidth, useStatic, listItems, innerStates]); | ||
|
|
||
| useInput((input, key) => { | ||
| const handleInnerScroll = (id: number, delta: number) => { | ||
| setInnerStates(previous => { | ||
| const current = previous[id] || {scrollTop: 0, isStatic: true}; | ||
| return { | ||
| ...previous, | ||
| [id]: { | ||
| isStatic: false, | ||
| scrollTop: Math.max(0, current.scrollTop + delta), | ||
| }, | ||
| }; | ||
| }); | ||
| }; | ||
|
|
||
| if (input === '1') { | ||
| handleInnerScroll(0, -1); | ||
| return; | ||
| } | ||
|
|
||
| if (input === '2') { | ||
| handleInnerScroll(0, 1); | ||
| return; | ||
| } | ||
|
|
||
| if (input === '3') { | ||
| handleInnerScroll(3, -1); | ||
| return; | ||
| } | ||
|
|
||
| if (input === '4') { | ||
| handleInnerScroll(3, 1); | ||
| return; | ||
| } | ||
|
|
||
| if (input === ' ') { | ||
| setListItems(previous => { | ||
| const newItems = Array.from({length: 20}).map((_, i) => ({ | ||
| const newItems = Array.from({length: 4}).map((_, i) => ({ | ||
| id: Date.now() + previous.length + i, | ||
| text: `Line ${previous.length + i} - ${'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '.repeat( | ||
| ((previous.length + i) * 5) % 6, | ||
|
|
@@ -530,6 +572,7 @@ function ScrollableContent({ | |
| Press up/down arrow or w/s to scroll vertically (w/s for 30 | ||
| lines, Shift for 10). | ||
| </Text> | ||
| <Text>Press 1/2 to scroll first inner view, 3/4 for second.</Text> | ||
| <Text>Press 'space' to add a block, 'c' to clear list.</Text> | ||
| <Text> | ||
| Press 'b' to toggle scrollbar ({showScrollbar ? 'on' : 'off'}), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intentionally added for easier debugging that this sample doesn't introduce inefficient rendering.