Skip to content

Commit

Permalink
Reset scroll when changing search text
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreSi committed Jan 10, 2025
1 parent 1f2c83e commit 6e112ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,13 @@ const InstructionOrObjectSelector = React.forwardRef<

React.useEffect(
() => {
if (treeViewRef.current) treeViewRef.current.updateRowHeights();
const treeView = treeViewRef.current;
if (treeView) {
treeView.updateRowHeights();
treeView.scrollTo(0);
}
},
// Recompute row heights when search changes.
// Recompute row heights when search changes and reset scroll.
[searchText]
);

Expand Down
9 changes: 9 additions & 0 deletions newIDE/app/src/UI/TreeView/ReadOnlyTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const getItemProps = memoizeOne(

export type ReadOnlyTreeViewInterface<Item> = {|
forceUpdateList: () => void,
scrollTo: (offset: number) => void,
scrollToItem: (Item, placement?: 'smart' | 'start') => void,
scrollToItemFromId: (itemId: string, placement?: 'smart' | 'start') => void,
openItems: (string[]) => void,
Expand Down Expand Up @@ -364,6 +365,13 @@ const ReadOnlyTreeView = <Item: ItemBaseAttributes>(
[getItemId, scrollToItemFromId]
);

const scrollTo = React.useCallback((offset: number) => {
const list = listRef.current;
if (list) {
list.scrollTo(offset);
}
}, []);

const openItems = React.useCallback(
(itemIds: string[]) => {
const notAlreadyOpenedNodeIds = itemIds.filter(
Expand Down Expand Up @@ -448,6 +456,7 @@ const ReadOnlyTreeView = <Item: ItemBaseAttributes>(
ref,
() => ({
forceUpdateList: forceUpdate,
scrollTo,
scrollToItem,
scrollToItemFromId,
openItems,
Expand Down

0 comments on commit 6e112ca

Please sign in to comment.