mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fill a looped curve with the selected background color (#1315)
This commit is contained in:
parent
fe6f482e96
commit
57bbc9fe55
11 changed files with 240 additions and 32 deletions
|
@ -7,6 +7,7 @@ import { done } from "../components/icons";
|
|||
import { t } from "../i18n";
|
||||
import { register } from "./register";
|
||||
import { mutateElement } from "../element/mutateElement";
|
||||
import { isPathALoop } from "../math";
|
||||
|
||||
export const actionFinalize = register({
|
||||
name: "finalize",
|
||||
|
@ -32,6 +33,23 @@ export const actionFinalize = register({
|
|||
newElements = newElements.slice(0, -1);
|
||||
}
|
||||
|
||||
// If the multi point line closes the loop,
|
||||
// set the last point to first point.
|
||||
// This ensures that loop remains closed at different scales.
|
||||
if (appState.multiElement.type === "line") {
|
||||
if (isPathALoop(appState.multiElement.points)) {
|
||||
const linePoints = appState.multiElement.points;
|
||||
const firstPoint = linePoints[0];
|
||||
mutateElement(appState.multiElement, {
|
||||
points: linePoints.map((point, i) =>
|
||||
i === linePoints.length - 1
|
||||
? ([firstPoint[0], firstPoint[1]] as const)
|
||||
: point,
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!appState.elementLocked) {
|
||||
appState.selectedElementIds[appState.multiElement.id] = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue