Skip to content

Commit

Permalink
fix: image insertion bugs (excalidraw#7278)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Nov 13, 2023
1 parent adfd95b commit 029c3c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4740,9 +4740,13 @@ class App extends React.Component<AppProps, AppState> {
});

const { x, y } = viewportCoordsToSceneCoords(event, this.state);

const frame = this.getTopLayerFrameAtSceneCoords({ x, y });

mutateElement(pendingImageElement, {
x,
y,
frameId: frame ? frame.id : null,
});
} else if (this.state.activeTool.type === "freedraw") {
this.handleFreeDrawElementOnPointerDown(
Expand Down Expand Up @@ -5609,9 +5613,11 @@ class App extends React.Component<AppProps, AppState> {
private createImageElement = ({
sceneX,
sceneY,
addToFrameUnderCursor = true,
}: {
sceneX: number;
sceneY: number;
addToFrameUnderCursor?: boolean;
}) => {
const [gridX, gridY] = getGridPoint(
sceneX,
Expand All @@ -5621,10 +5627,12 @@ class App extends React.Component<AppProps, AppState> {
: this.state.gridSize,
);

const topLayerFrame = this.getTopLayerFrameAtSceneCoords({
x: gridX,
y: gridY,
});
const topLayerFrame = addToFrameUnderCursor
? this.getTopLayerFrameAtSceneCoords({
x: gridX,
y: gridY,
})
: null;

const element = newImageElement({
type: "image",
Expand Down Expand Up @@ -7554,6 +7562,7 @@ class App extends React.Component<AppProps, AppState> {
const imageElement = this.createImageElement({
sceneX: x,
sceneY: y,
addToFrameUnderCursor: false,
});

if (insertOnCanvasDirectly) {
Expand Down
2 changes: 1 addition & 1 deletion src/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const setCursorForShape = (
interactiveCanvas.style.cursor = `url(${url}), auto`;
} else if (!["image", "custom"].includes(appState.activeTool.type)) {
interactiveCanvas.style.cursor = CURSOR_TYPE.CROSSHAIR;
} else {
} else if (appState.activeTool.type !== "image") {
interactiveCanvas.style.cursor = CURSOR_TYPE.AUTO;
}
};

0 comments on commit 029c3c4

Please sign in to comment.