Skip to content

Conversation

@ryan-di
Copy link
Member

@ryan-di ryan-di commented Jul 29, 2024

draggingElement is a misnomer and implies it's related to elements being dragged, which is mostly false.

when dragging selected elements, a selection element is created (though its width and height remain 0 throughout the whole interaction), and this selection element is used to check if selected are being dragged in some places (HintViewer for instance), which is incorrect.

newElement is a more appropriate name and where draggingElement was used as described above has been replaced with selectedElementsAreBeingDragged

@vercel
Copy link

vercel bot commented Jul 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
excalidraw ✅ Ready (Inspect) Visit Preview Aug 6, 2024 11:23am
excalidraw-package-example ✅ Ready (Inspect) Visit Preview Aug 6, 2024 11:23am
excalidraw-package-example-with-nextjs ✅ Ready (Inspect) Visit Preview Aug 6, 2024 11:23am
1 Skipped Deployment
Name Status Preview Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Aug 6, 2024 11:23am

@github-actions
Copy link

github-actions bot commented Jul 29, 2024

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 66.11% (🎯 70%) 56858 / 85994
🔴 Statements 66.11% (🎯 70%) 56858 / 85994
🔴 Functions 67.79% (🎯 68%) 1699 / 2506
🟢 Branches 80.42% (🎯 70%) 7019 / 8727
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/excalidraw/appState.ts 98.23% 90% 71.42% 98.23% 16, 260-261, 268-269
packages/excalidraw/snapping.ts 28.2% 41.02% 40% 28.2% 32-33, 118-119, 131-132, 156, 159-160, 162-165, 168-169, 172-266, 269-286, 289-404, 407-574, 577-594, 597-650, 662, 672-710, 769-771, 774-785, 788-855, 858-872, 875-1071, 1085-1087, 1094-1170, 1183, 1225-1250, 1296-1357, 1360-1361
packages/excalidraw/types.ts 100% 100% 100% 100%
packages/excalidraw/actions/actionFinalize.tsx 86.93% 90% 66.66% 86.93% 47, 64, 67-68, 113-122, 155-160, 212-220
packages/excalidraw/actions/actionHistory.tsx 97.72% 75% 100% 97.72% 43-45
packages/excalidraw/components/App.tsx 69.56% 76.63% 67.87% 69.56% 474-475, 582-591, 690-691, 709-710, 731-791, 794-800, 803-806, 809-885, 888-907, 910-915, 923-933, 935-936, 941-942, 946-948, 962, 969-1230, 1290-1291, 1323-1325, 1332-1377, 1403, 1413, 1420-1423, 1432-1436, 1468-1469, 1553-1563, 1568-1583, 1587-1634, 1707-1712, 1741-1746, 1749-1779, 1787-1812, 1815-1824, 1827-1939, 1942-1950, 1959-1972, 1975-2001, 2004-2075, 2078-2119, 2122-2127, 2175-2176, 2190-2191, 2223-2224, 2228-2229, 2249-2257, 2262-2275, 2281-2282, 2286, 2291-2299, 2301-2309, 2321, 2363-2364, 2386-2387, 2394, 2467-2469, 2472-2477, 2482-2483, 2523-2531, 2536-2545, 2583-2584, 2671-2672, 2676, 2679-2680, 2688-2691, 2700-2713, 2719-2722, 2725, 2727-2728, 2735-2736, 2742-2743, 2746-2747, 2755-2756, 2759-2760, 2763-2766, 2777-2785, 2790-2791, 2842-2843, 2857-2863, 2869-2877, 2881-2889, 2893-2894, 2897-2930, 2933-2945, 2956-2957, 2968-2969, 2986-2990, 2994-2997, 3004-3006, 3024-3031, 3034, 3036-3041, 3045-3047, 3093-3094, 3101-3103, 3105-3128, 3154, 3160, 3216-3217, 3234-3236, 3258-3259, 3265-3268, 3274-3355, 3409, 3413, 3448-3449, 3508, 3518-3536, 3539-3545, 3548-3549, 3555-3568, 3654-3655, 3657-3658, 3663-3665, 3673-3674, 3697-3711, 3716-3735, 3787-3788, 3867, 3876-3877, 3879-3886, 3901-3905, 3916-3917, 3920-3924, 3926-3927, 3929-3932, 3957-3958, 3976-3978, 3980-3982, 3984, 4070-4073, 4095-4103, 4107-4109, 4119-4120, 4122-4142, 4149-4172, 4175-4181, 4198-4201, 4207-4210, 4220-4227, 4269-4273, 4277, 4282-4283, 4288-4292, 4325-4326, 4329-4330, 4342-4346, 4351-4352, 4358-4368, 4373-4400, 4405-4416, 4480, 4506-4507, 4591, 4616, 4642-4644, 4711-4712, 4730-4731, 4906-4907, 4910-4911, 4919-4920, 4970-4974, 5028-5035, 5041-5107, 5151, 5208, 5235, 5242-5243, 5256-5259, 5290, 5338-5341, 5344-5350, 5352-5355, 5372-5381, 5384-5385, 5505-5506, 5509, 5511-5516, 5522-5524, 5526, 5535, 5557-5562, 5564-5567, 5571-5572, 5582-5682, 5686-5687, 5702-5703, 5739-5745, 5772-5773, 5804, 5806-5833, 5840-5841, 5863-5864, 5883, 5885-5928, 5933-5934, 5936-5937, 5953-5954, 5960-5961, 5965-5968, 5971-5972, 5986-6013, 6021-6022, 6026-6029, 6031-6035, 6053-6057, 6104-6109, 6111-6113, 6129, 6131-6144, 6169-6172, 6216, 6233-6234, 6236-6259, 6274-6275, 6389-6417, 6523-6524, 6544-6545, 6639, 6645-6646, 6669-6688, 6703, 6832, 6854-6892, 6896-6946, 6961, 6970, 7004-7010, 7036-7038, 7206-7209, 7231-7261, 7274, 7276-7284, 7298, 7300-7308, 7315-7318, 7326-7331, 7358-7359, 7364-7366, 7369-7370, 7395-7396, 7427-7428, 7511-7512, 7559-7572, 7649-7652, 7678-7679, 7721-7722, 7735, 7750-7756, 7763-7777, 7801-7807, 7839, 7881, 7887, 7902-7909, 7912-7919, 7975, 8053-8054, 8075-8077, 8080, 8094-8118, 8222-8235, 8256-8280, 8289-8328, 8341-8342, 8351-8358, 8376-8383, 8437-8463, 8465-8466, 8540-8541, 8548, 8550-8586, 8615, 8674, 8708-8710, 8735-8740, 8742-8743, 8748-8750, 8753-8773, 8787-8788, 8794-8803, 8808, 8812-8816, 8825-8829, 8832-8837, 8841-8848, 8878, 8880-8884, 8886-8896, 8912-8914, 8925-8933, 8937-8981, 8984-9055, 9063, 9081-9088, 9090-9106, 9121-9143, 9162-9164, 9210-9211, 9327-9331, 9333-9349, 9351-9355, 9367-9368, 9378-9394, 9413-9432, 9434-9435, 9462-9463, 9467-9468, 9478, 9480-9483, 9485-9486, 9526, 9565-9566, 9576, 9618, 9631-9639, 9655-9656, 9688-9691, 9785-9792, 9818-9819, 9862-9916, 9964-9965, 9974-9977, 9982-9983, 10004-10006, 10008-10012, 10050
packages/excalidraw/components/HintViewer.tsx 94.63% 92.75% 100% 94.63% 30-31, 51-52, 55-56, 97-98
packages/excalidraw/components/hyperlink/Hyperlink.tsx 16.84% 33.33% 28.57% 16.84% 54-316, 319-331, 339-341, 343, 350-361, 364-404, 407-408, 410-412, 416-457
packages/excalidraw/data/reconcile.ts 98.3% 71.42% 100% 98.3% 50-51
packages/excalidraw/element/ElementCanvasButtons.tsx 20.63% 100% 0% 20.63% 12-24, 27-63
packages/excalidraw/element/dragElements.ts 75.49% 68.57% 100% 75.49% 35, 37-38, 45-46, 61-66, 183-207, 213-217, 222-242
packages/excalidraw/element/linearElementEditor.ts 76.22% 80.84% 86.48% 76.22% 103-104, 145, 149-206, 222-223, 228-229, 233-234, 236-237, 240-253, 256-258, 269-270, 272-294, 319-322, 393-394, 419, 439, 457-465, 553-554, 678-679, 692, 717-718, 724-725, 742-785, 882-883, 888-889, 896-897, 903-905, 907-955, 1106-1107, 1110-1179, 1194-1201, 1222-1238, 1325-1326, 1329-1330, 1371-1372, 1436, 1443, 1474-1507, 1623-1655
packages/excalidraw/element/types.ts 0% 0% 0% 0% 1-346
Generated in workflow #2990

@dwelle dwelle changed the title refactor: decouple new element from dragging element refactor: rename draggingElement -> newElement Jul 30, 2024
@dwelle dwelle marked this pull request as ready for review July 30, 2024 10:45
dwelle
dwelle previously approved these changes Jul 30, 2024
(local.id === localAppState.editingElement?.id ||
local.id === localAppState.resizingElement?.id ||
local.id === localAppState.draggingElement?.id || // TODO: Is this still valid? As draggingElement is selection element, which is never part of the elements array
local.id === localAppState.newElement?.id || // TODO: Is this still valid? As newElement is selection element, which is never part of the elements array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mrazator should we also prefer local element if it's being dragged? Not that we can detect it efficiently right now as we don't track dragged elements

Copy link
Member Author

@ryan-di ryan-di Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is potentially incorrect. If we want to preserve local element that's being dragged, we should update the logic. Otherwise, we should just remove the changed line of code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also prefer local element if it's being dragged

probably, though now thinking that these conditions could momentarily lead to an inconsistent reconciliation result on different clients; though such cases will immediately be fixed with the next update, so it is likely not necessarily a big issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, though it's incorrect in production as well. Now at least we prefer elements that are being currently created, though it likely doesn't matter and it's unlikely those will be updated on remote (unless there's a bug in sync).

If we want to prefer local dragged elements, we'd likely need to introduce a new state for all dragged elements (map preferably, for perf).

Comment on lines +7762 to +7772
} else if (points.length > 1 && isElbowArrow(newElement)) {
mutateElbowArrow(
newElement,
this.scene,
[...points.slice(0, -1), [dx, dy]],
[0, 0],
undefined,
{
isDragging: true,
},
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was removed by mistake.

Case: updating elbow arrow points as you create it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a test would be nice. Maybe just checking if points are middle points are being set/updated when creating "2-point" elbow arrow?

Comment on lines +5249 to +5253
} else if (
!this.state.newElement &&
!this.state.selectedElementsAreBeingDragged &&
!this.state.selectionElement
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't reset snapLines when we're dragging (the "when selecting" is just a perf optim as right now it's a noop)

If not checked, the snap lines flicker as they're constantly being set and reset

Comment on lines +5201 to +5206
if (
!this.state.newElement &&
!this.state.selectionElement &&
!this.state.selectedElementsAreBeingDragged &&
!this.state.multiElement
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't have any effect right now, but if we later have a :hover effect when over scrollbars or something, it would matter. So adding the checks to keep parity with prod.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not write test for this. It's actaully just half the story, and scrollbars are broken anywa.

Comment on lines +4079 to +4081
!this.state.newElement &&
!this.state.selectionElement &&
!this.state.selectedElementsAreBeingDragged
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parity with prod: don't support toolbar shortcuts while selecting or dragging

) &&
(this.state.selectionElement ||
this.state.newElement ||
this.state.selectedElementsAreBeingDragged ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parity with prod: we need to disable UI pointer events when dragging elements over UI

Copy link
Member

@dwelle dwelle Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's write a test for this by checking for existence of --ui-pointerEvents on some UI

Comment on lines +24 to +26
!appState.newElement &&
!appState.selectedElementsAreBeingDragged &&
!appState.selectionElement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's write a test checking that undo/redo is disabled while dragging/selecting

@dwelle
Copy link
Member

dwelle commented Aug 5, 2024

@ryan-di todos:

  • dragging element outside of a frame doesn't remove it from the frame
  • document what each appState newElement, multiElement, selectionElement, editingElement (the others we'll do as go over and potentially refactor them) means (roughly when is it set/unset) in packages/excalidraw/types.ts

Comment on lines +269 to +275
/**
* currently set for:
* - text elements while in wysiwyg
* - newly created linear elements while in line editor (not set for existing
* elements in line editor)
* - and new images while being placed on canvas
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added docs for editingElement. I'd say this one is ripe for refactor as well as it doesn't make much sense.

@ryan-di ryan-di merged commit 3cf14c7 into master Aug 6, 2024
@ryan-di ryan-di deleted the ryan-di/dragging-element branch August 6, 2024 11:26
aqandrew added a commit to aqandrew/excalidraw that referenced this pull request Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants