Skip to content

Commit

Permalink
Merge branch 'multi-select' of https://github.com/ErickSharp/ace into…
Browse files Browse the repository at this point in the history
… multi-select
  • Loading branch information
ErickSharp committed Oct 3, 2021
2 parents 9a72d43 + c40b782 commit ed1ad4c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/renderer/Pages/ProjectHome/ProjectWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,55 @@ export const ProjectWorkspace = () => {
const [liveReloadConfigHandler, setLiveReloadConfigHandler] = useState<ProjectLiveReloadHandler>(null);
const [liveReloadDispatcher, setLiveReloadDispatcher] = useState<LiveReloadDispatcher>(null);

function tryAddElementToSelected(addition: PossibleCanvasElements) {
if (!selectedCanvasElements.includes(addition)) {
setSelectedCanvasElements((canvasElements) => [...canvasElements, addition]);
}
}

useEffect(() => {
function downHandler(event: KeyboardEvent) {
if (event.key.toUpperCase() === 'SHIFT') {
setShift(true);
}
if (event.key.toUpperCase() === 'CONTROL') {
setControl(true);
}
if (event.key.toUpperCase() === 'ENTER') {
setInInteractionMode((old) => !old);
}
if (event.key.toUpperCase() === 'DELETE') {
for (const element of selectedCanvasElements) {
handleDeleteCanvasElement(element);
}
}
}

function upHandler(event:KeyboardEvent) {
if (event.key.toUpperCase() === 'SHIFT') {
setShift(false);
}
if (event.key.toUpperCase() === 'CONTROL') {
setControl(false);
}
}

window.addEventListener('keydown', downHandler);
window.addEventListener('keyup', upHandler);

return () => {
window.removeEventListener('keydown', downHandler);
window.removeEventListener('keyup', upHandler);
};
}, [selectedCanvasElements]);

function handleElementClick(element: PossibleCanvasElements) {
if (shift) {
tryAddElementToSelected(element);
} else {
setSelectedCanvasElements([element]);
}
}
const [simVarControlsHandler, setSimVarControlsHandler] = useState<SimVarControlsHandler>(null);

function tryAddElementToSelected(addition: PossibleCanvasElements) {
Expand Down

0 comments on commit ed1ad4c

Please sign in to comment.