Browse Source

render and toggle split points for linear elements as well

Preet 1 year ago
parent
commit
bf7c91536f
2 changed files with 18 additions and 14 deletions
  1. 1 1
      src/components/App.tsx
  2. 17 13
      src/renderer/renderScene.ts

+ 1 - 1
src/components/App.tsx

@@ -3758,7 +3758,7 @@ class App extends React.Component<AppProps, AppState> {
     const selectedElements = this.scene.getSelectedElements(this.state);
 
     if (selectedElements.length === 1 && isLinearElement(selectedElements[0])) {
-      if (selectedElements[0].roundness) {
+      if (!event[KEYS.CTRL_OR_CMD]) {
         const pointUnderCursorIndex =
           LinearElementEditor.getPointIndexUnderCursor(
             selectedElements[0],

+ 17 - 13
src/renderer/renderScene.ts

@@ -266,6 +266,16 @@ const renderSingleLinearPoint = (
   }
 };
 
+const isLinearPointAtIndexSquared = (
+  element: NonDeleted<ExcalidrawLinearElement>,
+  index: number,
+) => {
+  const splitting = element.segmentSplitIndices
+    ? element.segmentSplitIndices.includes(index)
+    : false;
+  return element.roundness ? splitting : !splitting;
+};
+
 const renderLinearPointHandles = (
   context: CanvasRenderingContext2D,
   appState: InteractiveCanvasAppState,
@@ -287,19 +297,13 @@ const renderLinearPointHandles = (
     const isSelected =
       !!appState.editingLinearElement?.selectedPointsIndices?.includes(idx);
 
-    const segmented = element.roundness
-      ? element.segmentSplitIndices
-        ? element.segmentSplitIndices.includes(idx)
-        : false
-      : false;
-
     renderSingleLinearPoint(
       context,
       appState,
       point,
       radius,
       isSelected,
-      segmented,
+      isLinearPointAtIndexSquared(element, idx),
     );
   });
 
@@ -393,15 +397,15 @@ const renderLinearElementPointHighlight = (
     element,
     hoverPointIndex,
   );
-  const segmented = element.roundness
-    ? element.segmentSplitIndices
-      ? element.segmentSplitIndices.includes(hoverPointIndex)
-      : false
-    : false;
 
   context.save();
   context.translate(appState.scrollX, appState.scrollY);
-  highlightPoint(point, context, appState, segmented);
+  highlightPoint(
+    point,
+    context,
+    appState,
+    isLinearPointAtIndexSquared(element, hoverPointIndex),
+  );
   context.restore();
 };