@samitouri / QOS-React-2 / commits / 6ac558df2d

Reset max indentation when entering/exiting the owner tree

Brian Vaughn committed Jun 3, 2019 at 09:32 UTC 6ac558df2df79c750ca2f0af464281ee2712fa84
1 file changed +11 -8
src/devtools/views/Components/Tree.js
+11 -8
@@ -430,13 +430,23 @@ function InnerElementType({ children, style, ...rest }) {
430 // e.g. clicking to toggle/collapse a row might otherwise jump horizontally beneath your cursor,
431 // e.g. scrolling a wide row off screen could cause narrower rows to jump to the right some.
432 //
433 - // The one exception for this is when the width of the tree increases.
433 + // There are two exceptions for this:
434 + // 1. The first is when the width of the tree increases.
435 // The user may have resized the window specifically to make more room for DevTools.
436 // In either case, this should reset our max indentation size logic.
437 + // 2. The second is when the user enters or exits an owner tree.
438 const indentationSizeRef = useRef<number>(DEFAULT_INDENTATION_SIZE);
439 const prevListWidthRef = useRef<number>(0);
440 + const prevOwnerIDRef = useRef<number | null>(ownerID);
441 const divRef = useRef<HTMLDivElement | null>(null);
442
443 + // We shouldn't retain this width across different conceptual trees though,
444 + // so when the user opens the "owners tree" view, we should discard the previous width.
445 + if (ownerID !== prevOwnerIDRef.current) {
446 + prevOwnerIDRef.current = ownerID;
447 + indentationSizeRef.current = DEFAULT_INDENTATION_SIZE;
448 + }
449 +
450 // When we render new content, measure to see if we need to shrink indentation to fit it.
451 // TODO The lint warning is valid, but we are intentionally ignoring it for now.
452 // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -451,13 +461,6 @@ function InnerElementType({ children, style, ...rest }) {
461 }
462 });
463
454 - // We shouldn't retain this width across different conceptual trees though,
455 - // so when the user opens the "owners tree" view, we should discard the previous width.
456 - const [prevOwnerID, setPrevOwnerID] = useState(ownerID);
457 - if (ownerID !== prevOwnerID) {
458 - setPrevOwnerID(ownerID);
459 - }
460 -
464 // This style override enables the background color to fill the full visible width,
465 // when combined with the CSS tweaks in Element.
466 // A lot of options were considered; this seemed the one that requires the least code.