Skip to content

Commit

Permalink
Toggle multi selection of scenes action changed to ctrl/cmd + click
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltby committed Nov 11, 2024
1 parent ae071b4 commit d8f50fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ladder collision tile now only visible on Platform scenes by default, edit `engine.json` to add per scene collision tile types
- New instances of prefabs use prefab's name by default
- Update "Wait" event to support using variable values for wait time [@pau-tomas](https://github.com/pau-tomas))
- Toggle multi selection of scenes action changed to ctrl/cmd + click to be more consistent with OS level defaults + new sprite editor frame selection
- Updated Polish localisation. [@ReptiIe](https://github.com/ReptiIe)
- Updated Japanese localisation. [@tomo666](https://github.com/tomo666)

Expand Down
27 changes: 12 additions & 15 deletions src/components/world/SceneView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ interface SceneViewProps {
id: string;
index: number;
editable?: boolean;
addToSelection?: boolean;
}

const SceneName = styled.div`
Expand Down Expand Up @@ -199,16 +198,8 @@ const SceneOverlay = styled.div<SceneOverlayProps>`
: ""}
`;

const SelectionWrapper = styled.div`
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
`;

const SceneView = memo(
({ id, index, editable, addToSelection }: SceneViewProps) => {
({ id, index, editable }: SceneViewProps) => {
const dispatch = useAppDispatch();
const scene = useAppSelector((state) =>
sceneSelectors.selectById(state, id)
Expand Down Expand Up @@ -620,9 +611,16 @@ const SceneView = memo(
[renderContextMenu, tool]
);

const onToggleSelection = useCallback(() => {
dispatch(editorActions.toggleSceneSelectedId(id));
}, [dispatch, id]);
const onToggleSelection = useCallback(
(e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
if (e.ctrlKey || e.metaKey) {
e.preventDefault();
e.stopPropagation();
dispatch(editorActions.toggleSceneSelectedId(id));
}
},
[dispatch, id]
);

if (!scene || !visible) {
return <></>;
Expand All @@ -638,6 +636,7 @@ const SceneView = memo(
top: scene.y,
}}
onContextMenu={onContextMenu}
onMouseDownCapture={onToggleSelection}
>
<SceneMetadata
onMouseDown={onStartDrag}
Expand Down Expand Up @@ -818,8 +817,6 @@ const SceneView = memo(
{contextMenu.menu}
</ContextMenu>
)}

{addToSelection && <SelectionWrapper onMouseDown={onToggleSelection} />}
</Wrapper>
);
}
Expand Down
27 changes: 3 additions & 24 deletions src/components/world/WorldView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ const WorldContent = styled.div`
left: 0;
`;

const SelectionWrapper = styled.div`
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
`;

const NewSceneCursor = styled.div`
position: absolute;
cursor: pointer;
Expand Down Expand Up @@ -110,7 +102,6 @@ const WorldView = () => {
scrollY: 0,
});
const isMouseOver = useRef(false);
const [addToSelection, setAddToSelection] = useState(false);
const [selectionStart, setSelectionStart] = useState<Point>();
const [selectionEnd, setSelectionEnd] = useState<Point>();
const selection = useRef<SelectionRect>();
Expand Down Expand Up @@ -221,7 +212,6 @@ const WorldView = () => {
if (e.shiftKey && tool === "select") {
setSelectionStart(undefined);
setSelectionEnd(undefined);
setAddToSelection(true);
}
if (!(e.target instanceof HTMLElement)) return;
if (e.target.nodeName !== "BODY") {
Expand Down Expand Up @@ -249,9 +239,6 @@ const WorldView = () => {
if (dragMode && (e.code === "Space" || e.key === "Alt")) {
setDragMode(false);
}
if (!e.shiftKey) {
setAddToSelection(false);
}
},
[dragMode]
);
Expand Down Expand Up @@ -600,8 +587,8 @@ const WorldView = () => {
);

const onStartMultiSelection = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
if (scrollRef.current) {
(e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
if (e.shiftKey && scrollRef.current) {
e.preventDefault();
e.stopPropagation();

Expand Down Expand Up @@ -632,7 +619,6 @@ const WorldView = () => {

const onWindowBlur = useCallback(() => {
setDragMode(false);
setAddToSelection(false);
}, []);

//#endregion Window Blur
Expand Down Expand Up @@ -679,6 +665,7 @@ const WorldView = () => {
onMouseLeave={onMouseLeave}
onMouseMove={onMouseMove}
onMouseDown={startWorldDragIfAltOrMiddleClick}
onMouseDownCapture={onStartMultiSelection}
onScroll={onScroll}
style={
dragMode
Expand All @@ -697,20 +684,12 @@ const WorldView = () => {
onMouseDown={startWorldDrag}
/>

{addToSelection && (
<SelectionWrapper
style={{ width: scrollWidth, height: scrollHeight }}
onMouseDown={onStartMultiSelection}
></SelectionWrapper>
)}

{scenes.map((sceneId, index) => (
<SceneView
key={sceneId}
id={sceneId}
index={index}
editable={!dragMode}
addToSelection={addToSelection}
/>
))}

Expand Down

0 comments on commit d8f50fe

Please sign in to comment.