Skip to content

Commit

Permalink
Recompute row heights when collapsing items
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreSi committed Jan 10, 2025
1 parent f62a0c1 commit 1f2c83e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import * as React from 'react';
import { AutoSizer } from 'react-virtualized';
import Fuse from 'fuse.js';
import { I18n } from '@lingui/react';
import { type I18n as I18nType } from '@lingui/core';
import { t, Trans } from '@lingui/macro';

Expand Down
7 changes: 4 additions & 3 deletions newIDE/app/src/UI/TreeView/ReadOnlyTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type FlattenedNode<Item> = {|
|};

export type ItemData<Item> = {|
onOpen: (FlattenedNode<Item>) => void,
onOpen: (FlattenedNode<Item>, index: number) => void,
onClick: (FlattenedNode<Item>) => void,
onSelect: ({| node: FlattenedNode<Item>, exclusive?: boolean |}) => void,
flattenedData: FlattenedNode<Item>[],
Expand All @@ -50,7 +50,7 @@ export type ItemData<Item> = {|
const getItemProps = memoizeOne(
<Item>(
flattenedData: FlattenedNode<Item>[],
onOpen: (FlattenedNode<Item>) => void,
onOpen: (FlattenedNode<Item>, index: number) => void,
onClick: (FlattenedNode<Item>) => void,
onSelect: ({| node: FlattenedNode<Item>, exclusive?: boolean |}) => void,
isMobile: boolean,
Expand Down Expand Up @@ -273,7 +273,7 @@ const ReadOnlyTreeView = <Item: ItemBaseAttributes>(
);

const onOpen = React.useCallback(
(node: FlattenedNode<Item>) => {
(node: FlattenedNode<Item>, index: number) => {
if (isSearching) {
if (node.collapsed) {
setOpenedDuringSearchNodeIds([...openedDuringSearchNodeIds, node.id]);
Expand All @@ -293,6 +293,7 @@ const ReadOnlyTreeView = <Item: ItemBaseAttributes>(
}
}
}
if (listRef.current) listRef.current.resetAfterIndex(index);
},
[
openedDuringSearchNodeIds,
Expand Down
10 changes: 5 additions & 5 deletions newIDE/app/src/UI/TreeView/ReadOnlyTreeViewRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ const TreeViewRow = <Item: ItemBaseAttributes>(props: Props<Item>) => {
event => {
if (!node || node.item.isPlaceholder) return;
if (node.item.isRoot) {
onOpen(node);
onOpen(node, index);
return;
}
onSelect({ node, exclusive: !(event.metaKey || event.ctrlKey) });
onClick(node);
},
[onClick, onSelect, node, onOpen]
[onClick, onSelect, node, onOpen, index]
);

const onDoubleClickItem = React.useCallback(
e => {
if (!node || !node.hasChildren || node.disableCollapse) return;
onOpen(node);
onOpen(node, index);
},
[node, onOpen]
[node, onOpen, index]
);

const displayAsFolder = node.canHaveChildren;
Expand Down Expand Up @@ -86,7 +86,7 @@ const TreeViewRow = <Item: ItemBaseAttributes>(props: Props<Item>) => {
size="small"
onClick={e => {
e.stopPropagation();
onOpen(node);
onOpen(node, index);
}}
disabled={node.disableCollapse}
>
Expand Down

0 comments on commit 1f2c83e

Please sign in to comment.