mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix single selected arrow highlight after delete, undo, redo
This commit is contained in:
parent
4619e88b98
commit
689179f428
2 changed files with 56 additions and 18 deletions
|
@ -96,6 +96,7 @@ export const actionDuplicateSelection = register({
|
||||||
elements: nextElements,
|
elements: nextElements,
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
|
...updateLinearElementEditors(nextElements),
|
||||||
...selectGroupsForSelectedElements(
|
...selectGroupsForSelectedElements(
|
||||||
{
|
{
|
||||||
editingGroupId: appState.editingGroupId,
|
editingGroupId: appState.editingGroupId,
|
||||||
|
@ -131,3 +132,24 @@ export const actionDuplicateSelection = register({
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const updateLinearElementEditors = (clonedElements: ExcalidrawElement[]) => {
|
||||||
|
const linears = clonedElements.filter(isLinearElement);
|
||||||
|
if (linears.length === 1) {
|
||||||
|
const linear = linears[0];
|
||||||
|
const boundElements = linear.boundElements?.map((def) => def.id) ?? [];
|
||||||
|
const onlySingleLinearSelected = clonedElements.every(
|
||||||
|
(el) => el.id === linear.id || boundElements.includes(el.id),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (onlySingleLinearSelected) {
|
||||||
|
return {
|
||||||
|
selectedLinearElement: new LinearElementEditor(linear),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
selectedLinearElement: null,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -51,7 +51,13 @@ import {
|
||||||
} from "../scene/scrollbars";
|
} from "../scene/scrollbars";
|
||||||
import { getCornerRadius } from "../shapes";
|
import { getCornerRadius } from "../shapes";
|
||||||
import { type InteractiveCanvasAppState } from "../types";
|
import { type InteractiveCanvasAppState } from "../types";
|
||||||
import { arrayToMap, invariant, throttleRAF } from "../utils";
|
import {
|
||||||
|
arrayToMap,
|
||||||
|
invariant,
|
||||||
|
isDevEnv,
|
||||||
|
isTestEnv,
|
||||||
|
throttleRAF,
|
||||||
|
} from "../utils";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bootstrapCanvas,
|
bootstrapCanvas,
|
||||||
|
@ -886,24 +892,34 @@ const _renderInteractiveScene = ({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
// Arrows have a different highlight behavior when
|
||||||
isElbowArrow(selectedElements[0]) &&
|
// they are the only selected element
|
||||||
appState.selectedLinearElement &&
|
if (appState.selectedLinearElement) {
|
||||||
appState.selectedLinearElement.segmentMidPointHoveredCoords
|
if (isTestEnv() || isDevEnv()) {
|
||||||
) {
|
invariant(
|
||||||
|
selectedElements.length <= 1,
|
||||||
|
`There is an active selectedLinearElement on app state but the selectedElements length is ${selectedElements?.length} not 1`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const editor = appState.selectedLinearElement;
|
||||||
|
const firstSelectedLinear = selectedElements.find(
|
||||||
|
(el) => el.id === editor.elementId, // Don't forget bound text elements!
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isElbowArrow(firstSelectedLinear)) {
|
||||||
|
if (editor.segmentMidPointHoveredCoords) {
|
||||||
renderElbowArrowMidPointHighlight(context, appState);
|
renderElbowArrowMidPointHighlight(context, appState);
|
||||||
} else if (
|
} else if (
|
||||||
appState.selectedLinearElement &&
|
editor.hoverPointIndex !== 0 &&
|
||||||
appState.selectedLinearElement.hoverPointIndex >= 0 &&
|
editor.hoverPointIndex !== firstSelectedLinear.points.length - 1
|
||||||
!(
|
|
||||||
isElbowArrow(selectedElements[0]) &&
|
|
||||||
appState.selectedLinearElement.hoverPointIndex > 0 &&
|
|
||||||
appState.selectedLinearElement.hoverPointIndex <
|
|
||||||
selectedElements[0].points.length - 1
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
renderLinearElementPointHighlight(context, appState, elementsMap);
|
renderLinearElementPointHighlight(context, appState, elementsMap);
|
||||||
}
|
}
|
||||||
|
} else if (editor.hoverPointIndex >= 0) {
|
||||||
|
renderLinearElementPointHighlight(context, appState, elementsMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Paint selected elements
|
// Paint selected elements
|
||||||
if (!appState.multiElement && !appState.editingLinearElement) {
|
if (!appState.multiElement && !appState.editingLinearElement) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue