Remove ctrl to stop drawing children
Summary: This feature is annoying and useless Reviewed By: antonk52 Differential Revision: D45696921 fbshipit-source-id: 01c007d3e196a7511b940b7973bb8e6a880e27e5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
da268f0095
commit
0f9eeda2dd
@@ -22,9 +22,8 @@ export const Visualization2D: React.FC<
|
|||||||
width: number;
|
width: number;
|
||||||
nodes: Map<Id, UINode>;
|
nodes: Map<Id, UINode>;
|
||||||
onSelectNode: (id?: Id) => void;
|
onSelectNode: (id?: Id) => void;
|
||||||
modifierPressed: boolean;
|
|
||||||
} & React.HTMLAttributes<HTMLDivElement>
|
} & React.HTMLAttributes<HTMLDivElement>
|
||||||
> = ({width, nodes, onSelectNode, modifierPressed}) => {
|
> = ({width, nodes, onSelectNode}) => {
|
||||||
const rootNodeRef = useRef<HTMLDivElement>();
|
const rootNodeRef = useRef<HTMLDivElement>();
|
||||||
const instance = usePlugin(plugin);
|
const instance = usePlugin(plugin);
|
||||||
|
|
||||||
@@ -148,7 +147,6 @@ export const Visualization2D: React.FC<
|
|||||||
<MemoedVisualizationNode2D
|
<MemoedVisualizationNode2D
|
||||||
node={focusState.focusedRoot}
|
node={focusState.focusedRoot}
|
||||||
onSelectNode={onSelectNode}
|
onSelectNode={onSelectNode}
|
||||||
modifierPressed={modifierPressed}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -159,19 +157,15 @@ export const Visualization2D: React.FC<
|
|||||||
const MemoedVisualizationNode2D = React.memo(
|
const MemoedVisualizationNode2D = React.memo(
|
||||||
Visualization2DNode,
|
Visualization2DNode,
|
||||||
(prev, next) => {
|
(prev, next) => {
|
||||||
return (
|
return prev.node === next.node;
|
||||||
prev.node === next.node && prev.modifierPressed === next.modifierPressed
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
function Visualization2DNode({
|
function Visualization2DNode({
|
||||||
node,
|
node,
|
||||||
onSelectNode,
|
onSelectNode,
|
||||||
modifierPressed,
|
|
||||||
}: {
|
}: {
|
||||||
node: NestedNode;
|
node: NestedNode;
|
||||||
modifierPressed: boolean;
|
|
||||||
onSelectNode: (id?: Id) => void;
|
onSelectNode: (id?: Id) => void;
|
||||||
}) {
|
}) {
|
||||||
const instance = usePlugin(plugin);
|
const instance = usePlugin(plugin);
|
||||||
@@ -200,18 +194,11 @@ function Visualization2DNode({
|
|||||||
nestedChildren = node.children;
|
nestedChildren = node.children;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop drawing children if hovered with the modifier so you
|
|
||||||
// can see parent views without their children getting in the way
|
|
||||||
if (isHovered && modifierPressed) {
|
|
||||||
nestedChildren = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const children = nestedChildren.map((child) => (
|
const children = nestedChildren.map((child) => (
|
||||||
<MemoedVisualizationNode2D
|
<MemoedVisualizationNode2D
|
||||||
key={child.id}
|
key={child.id}
|
||||||
node={child}
|
node={child}
|
||||||
onSelectNode={onSelectNode}
|
onSelectNode={onSelectNode}
|
||||||
modifierPressed={modifierPressed}
|
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import {useHotkeys} from 'react-hotkeys-hook';
|
|||||||
import {Id, Metadata, MetadataId, UINode} from '../types';
|
import {Id, Metadata, MetadataId, UINode} from '../types';
|
||||||
import {PerfStats} from './PerfStats';
|
import {PerfStats} from './PerfStats';
|
||||||
import {Visualization2D} from './Visualization2D';
|
import {Visualization2D} from './Visualization2D';
|
||||||
import {useKeyboardModifiers} from '../hooks/useKeyboardModifiers';
|
|
||||||
import {Inspector} from './sidebar/Inspector';
|
import {Inspector} from './sidebar/Inspector';
|
||||||
import {Controls} from './Controls';
|
import {Controls} from './Controls';
|
||||||
import {Button, Spin} from 'antd';
|
import {Button, Spin} from 'antd';
|
||||||
@@ -41,8 +40,6 @@ export function Component() {
|
|||||||
|
|
||||||
useHotkeys('ctrl+i', () => setShowPerfStats((show) => !show));
|
useHotkeys('ctrl+i', () => setShowPerfStats((show) => !show));
|
||||||
|
|
||||||
const {ctrlPressed} = useKeyboardModifiers();
|
|
||||||
|
|
||||||
const [bottomPanelComponent, setBottomPanelComponent] = useState<
|
const [bottomPanelComponent, setBottomPanelComponent] = useState<
|
||||||
ReactNode | undefined
|
ReactNode | undefined
|
||||||
>();
|
>();
|
||||||
@@ -104,7 +101,6 @@ export function Component() {
|
|||||||
width={visualiserWidth}
|
width={visualiserWidth}
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
onSelectNode={instance.uiActions.onSelectNode}
|
onSelectNode={instance.uiActions.onSelectNode}
|
||||||
modifierPressed={ctrlPressed}
|
|
||||||
/>
|
/>
|
||||||
</Layout.ScrollContainer>
|
</Layout.ScrollContainer>
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*
|
|
||||||
* @format
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {useEffect, useState} from 'react';
|
|
||||||
|
|
||||||
export function useKeyboardModifiers() {
|
|
||||||
const [state, setState] = useState({altPressed: false, ctrlPressed: false});
|
|
||||||
|
|
||||||
function handler(event: KeyboardEvent) {
|
|
||||||
setState({altPressed: event.altKey, ctrlPressed: event.ctrlKey});
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
window.addEventListener('keydown', handler);
|
|
||||||
window.addEventListener('keyup', handler);
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('keydown', handler);
|
|
||||||
window.removeEventListener('keyup', handler);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user