Skip to content

Commit

Permalink
Add support for Ctrl+Click to cycle between disabled states (#2864)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored May 18, 2024
1 parent 9e8b538 commit c0daa8c
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/renderer/components/node/NodeFooter/DisableSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PopoverContent,
PopoverTrigger,
Portal,
Text,
Tooltip,
useDisclosure,
} from '@chakra-ui/react';
Expand Down Expand Up @@ -66,6 +67,10 @@ export const DisableSwitch = memo(({ disable, passthrough }: DisableSwitchProps)
? DisableMode.Skipped
: DisableMode.Enabled;

const availableModes: readonly DisableMode[] = passthrough.canPassthrough
? [DisableMode.Enabled, DisableMode.Disabled, DisableMode.Skipped]
: [DisableMode.Enabled, DisableMode.Disabled];

const { isOpen, onToggle, onClose } = useDisclosure();

const lastMouseDownRef = useRef<number | null>(null);
Expand All @@ -92,6 +97,12 @@ export const DisableSwitch = memo(({ disable, passthrough }: DisableSwitchProps)
onClose();
};

const cycleMode = () => {
const index = availableModes.indexOf(mode);
const nextIndex = (index + 1) % availableModes.length;
setMode(availableModes[nextIndex]);
};

const tooltipState = {
[DisableMode.Enabled]: 'This node is enabled and will be executed.',
[DisableMode.Disabled]:
Expand Down Expand Up @@ -129,7 +140,11 @@ export const DisableSwitch = memo(({ disable, passthrough }: DisableSwitchProps)
cursor="pointer"
h={6}
w={7}
onClick={() => {
onClick={(e) => {
if (e.ctrlKey) {
cycleMode();
return;
}
if (
lastMouseDownRef.current &&
lastOnCloseRef.current &&
Expand All @@ -150,9 +165,14 @@ export const DisableSwitch = memo(({ disable, passthrough }: DisableSwitchProps)
isDisabled={isOpen}
label={
<>
{tooltipState}
<Box h={2} />
{tooltipActions}
<Text>{tooltipState}</Text>
<Text mt={2}>{tooltipActions}</Text>
<Text
fontSize="small"
mt={3}
>
Hint: Use Ctrl+Click to cycle through options.
</Text>
</>
}
openDelay={500}
Expand Down Expand Up @@ -205,7 +225,7 @@ export const DisableSwitch = memo(({ disable, passthrough }: DisableSwitchProps)
label="Disable"
onClick={() => setMode(DisableMode.Disabled)}
/>
{passthrough.canPassthrough && (
{availableModes.includes(DisableMode.Skipped) && (
<MenuOption
icon={IoMdFastforward}
isDisabled={mode === DisableMode.Skipped}
Expand Down

0 comments on commit c0daa8c

Please sign in to comment.