- Implemented `mouseActionHelper.ts` to track modifier keys (e.g. CONTROL, SHIFT) - Dynamically constructs mouse+modifier combos (e.g. left+CONTROL) - Updates Zustand store (`useMouseNoteStore`) with appropriate notes - Supports multi-key combinations and cleans up listeners on unmount
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { useMouseNoteStore } from "../../store/useUIToggleStore";
|
|
|
|
const actionNotes: Record<string, string> = {
|
|
'left+CONTROL': 'Box Select',
|
|
'left+SHIFT': 'Multi Select',
|
|
'middle+CONTROL': 'Zoom In',
|
|
};
|
|
|
|
|
|
export function mouseActionHelper() {
|
|
const setNotes = useMouseNoteStore.getState().setNotes;
|
|
|
|
const activeKeys = new Set<string>();
|
|
|
|
function updateNotesFromKeys() {
|
|
const sortedKeys = Array.from(activeKeys).sort();
|
|
const leftKey = ['left', ...sortedKeys].join('+');
|
|
const middleKey = ['middle', ...sortedKeys].join('+');
|
|
const rightKey = ['right', ...sortedKeys].join('+');
|
|
|
|
setNotes({
|
|
Leftnote: actionNotes[leftKey] || '',
|
|
Middlenote: actionNotes[middleKey] || '',
|
|
Rightnote: actionNotes[rightKey] || '',
|
|
});
|
|
}
|
|
|
|
function handleKeyDown(event: KeyboardEvent) {
|
|
activeKeys.add(event.key.toUpperCase());
|
|
updateNotesFromKeys();
|
|
}
|
|
|
|
function handleKeyUp(event: KeyboardEvent) {
|
|
activeKeys.delete(event.key.toUpperCase());
|
|
updateNotesFromKeys();
|
|
}
|
|
|
|
window.addEventListener('keydown', handleKeyDown);
|
|
window.addEventListener('keyup', handleKeyUp);
|
|
|
|
return () => {
|
|
window.removeEventListener('keydown', handleKeyDown);
|
|
window.removeEventListener('keyup', handleKeyUp);
|
|
};
|
|
}
|