Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useCallback, useMemo } from 'react';

import { Flex, Tooltip, TooltipTrigger } from '@geti/ui';
import { isEmpty } from 'lodash-es';
import { useHotkeys } from 'react-hotkeys-hook';
import { useLocalStorage } from 'usehooks-ts';

import { Annotation } from '../../../../../core/annotations/annotation.interface';
Expand All @@ -15,6 +16,8 @@ import { useProjectIdentifier } from '../../../../../hooks/use-project-identifie
import { LOCAL_STORAGE_KEYS } from '../../../../../shared/local-storage-keys';
import { getId, getIds, hasEqualId } from '../../../../../shared/utils';
import { AnnotationToolContext, ToolSettings, ToolType } from '../../../core/annotation-tool-context.interface';
import { useAnnotatorHotkeys } from '../../../hooks/use-hotkeys-configuration.hook';
import { HOTKEY_OPTIONS } from '../../../hot-keys/utils';
import { getOutputFromTask } from '../../../providers/task-chain-provider/utils';
import { useTask } from '../../../providers/task-provider/task-provider.component';
import { LabelsHotkeys } from '../../labels/labels-hotkeys/labels-hotkeys.component';
Expand All @@ -39,6 +42,7 @@ const hasNotAnomalousNorLocalLabels = (annotation: Annotation) =>
export const LabelsShortcuts = ({ labels, annotationToolContext, isDisabled = false }: LabelsShortcutsProps) => {
const { selectedTask, tasks, setDefaultLabel } = useTask();
const { projectId } = useProjectIdentifier();
const { hotkeys } = useAnnotatorHotkeys();
const {
isDrawing,
annotations: annotationsScene,
Expand Down Expand Up @@ -111,6 +115,21 @@ export const LabelsShortcuts = ({ labels, annotationToolContext, isDisabled = fa
return isDrawingSmartTool ? smartToolHandler(label) : clickHandler(label);
};

const emptyLabel = labels.find((label) => isEmptyLabel(label));

useHotkeys(
hotkeys['empty-label'],
(event) => {
event.preventDefault();

if (emptyLabel) {
handleSelectLabelShortcut(emptyLabel);
}
},
HOTKEY_OPTIONS,
[emptyLabel, handleSelectLabelShortcut, hotkeys]
);

return (
<div aria-label='Label shortcuts' role='list'>
{!isDisabled && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const useAvailabilityOfHotkeys = (domains: DOMAIN[]): Record<HotKeyAction
close: true,
hideAllAnnotations: true,
accept: true,
['empty-label']: true,
[ToolType.EditTool]: false, // we do not have hotkey for edit tool
[ToolType.SelectTool]: true,
[SelectingToolType.SelectionTool]: false, // we do not have hotkey for selection tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export type HotKeyActions =
| 'pasteAnnotation'
| 'close'
| 'accept'
| 'hideAllAnnotations';
| 'hideAllAnnotations'
| 'empty-label';

export type Hotkeys = Record<HotKeyActions, string>;

Expand Down Expand Up @@ -76,6 +77,7 @@ export const DefaultHotkeys = (
close: 'escape',
hideAllAnnotations: 'a',
accept: 'enter',
['empty-label']: 'n',
[ToolType.SelectTool]: 'v',
[ToolType.SSIMTool]: 'd',
[ToolType.RITMTool]: 'i',
Expand Down
Loading