Commit a76b8bb
authored
Refactor/selection controller (#7765)
* refactor(activity): extract 2D drag-selection into SelectionController
Move drag-selection and multi-selection logic from activity.js into a
new js/activity/selection-controller.js module. The module exposes a
clean public API via setupSelectionController(activity) and delegates
all calls from activity to the new SelectionController class. No
behavioral changes; drag timing, rAF throttling, and selection
highlighting are preserved exactly.
What was moved
- _create2Ddrag, setupMouseEvents, _createDrag - drag lifecycle and
document-level mouse listeners
- drawSelectionArea, rectanglesOverlap, selectBlocksInDragArea,
unhighlightSelectedBlocks, isEqual - selection geometry and
highlighting helpers
- setSelectionMode, deselectSelectedBlocks, deleteMultipleBlocks,
copyMultipleBlocks, selectMode - selection mode and bulk block
operations
- State: isDragging, isSelecting, selectionModeOn, selectedBlocks,
dragArea, startX/startY/currentX/currentY, hasMouseMoved,
selectionArea, dragRect, blockRect, _dragSelectRafPending
isDragging, isSelecting and hasMouseMoved are exposed as getters/
setters on the controller rather than raw mutable fields; the render
loop, click handler, and toolbar mouseover handler in activity.js read
them via this.selectionController.<state> instead of local fields,
matching how isHelpfulSearchWidgetOn is accessed through
searchController.
loader.js: add "activity/selection-controller" to the activity/activity
shim deps list and paths map, matching the existing controller
extraction pattern.
Updated activity_toolbar_integration.test.js: its sandboxed Activity
constructor now needs setupSelectionController mocked alongside the
other setup*Controller calls.
Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
* test(selection-controller): add behavioral test coverage
Add a dedicated Jest suite for SelectionController covering setup and
delegation stubs, selection mode toggling, mouse-driven drag
initiation, selection rectangle drawing, the rectanglesOverlap and
isEqual helpers, selecting blocks within a drag area (including the
scrollBlockContainer x-offset), highlighting/unhighlighting selected
blocks, setSelectionMode's guarded on/off transitions,
deselectSelectedBlocks, deleteMultipleBlocks, copyMultipleBlocks
(including the connected-block skip logic), and _create2Ddrag's mouse
listener wiring, mouseup teardown, and rAF-throttled mousemove
handling.
Tests assert on observable state (selectionController fields, DOM
style, mock call arguments) rather than internals, and specifically
pin the requestAnimationFrame throttling behavior — at most one
pending frame per burst of mousemove events, and the pre-existing
two-frame delay before setSelectionMode flips selectionModeOn on
(since selectedBlocks starts empty on the first frame after
_create2Ddrag resets it).
Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
---------
Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>1 parent 4ce50ed commit a76b8bb
5 files changed
Lines changed: 1211 additions & 298 deletions
File tree
- js
- __tests__
- activity
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | 358 | | |
368 | 359 | | |
369 | 360 | | |
| |||
490 | 481 | | |
491 | 482 | | |
492 | 483 | | |
| 484 | + | |
493 | 485 | | |
494 | 486 | | |
495 | 487 | | |
| |||
607 | 599 | | |
608 | 600 | | |
609 | 601 | | |
610 | | - | |
| 602 | + | |
| 603 | + | |
611 | 604 | | |
612 | 605 | | |
613 | 606 | | |
| |||
3926 | 3919 | | |
3927 | 3920 | | |
3928 | 3921 | | |
3929 | | - | |
3930 | | - | |
3931 | | - | |
3932 | | - | |
3933 | | - | |
3934 | | - | |
3935 | | - | |
3936 | | - | |
3937 | | - | |
3938 | | - | |
3939 | | - | |
3940 | | - | |
3941 | | - | |
3942 | | - | |
3943 | | - | |
3944 | | - | |
3945 | | - | |
3946 | | - | |
3947 | | - | |
3948 | | - | |
3949 | | - | |
3950 | | - | |
3951 | | - | |
3952 | | - | |
3953 | | - | |
| 3922 | + | |
| 3923 | + | |
| 3924 | + | |
| 3925 | + | |
| 3926 | + | |
| 3927 | + | |
| 3928 | + | |
3954 | 3929 | | |
3955 | 3930 | | |
3956 | 3931 | | |
3957 | | - | |
| 3932 | + | |
3958 | 3933 | | |
3959 | 3934 | | |
3960 | | - | |
3961 | | - | |
3962 | | - | |
3963 | | - | |
3964 | | - | |
3965 | | - | |
3966 | | - | |
3967 | | - | |
3968 | | - | |
3969 | | - | |
3970 | | - | |
3971 | | - | |
3972 | | - | |
3973 | | - | |
3974 | | - | |
3975 | | - | |
3976 | | - | |
3977 | | - | |
3978 | | - | |
3979 | | - | |
3980 | | - | |
3981 | | - | |
3982 | | - | |
3983 | | - | |
3984 | | - | |
3985 | | - | |
3986 | | - | |
3987 | | - | |
3988 | | - | |
3989 | | - | |
3990 | | - | |
3991 | | - | |
3992 | | - | |
3993 | | - | |
3994 | | - | |
3995 | | - | |
3996 | | - | |
3997 | | - | |
3998 | | - | |
3999 | | - | |
4000 | | - | |
4001 | | - | |
4002 | | - | |
4003 | | - | |
4004 | | - | |
4005 | | - | |
4006 | | - | |
4007 | | - | |
4008 | | - | |
4009 | | - | |
4010 | | - | |
4011 | | - | |
4012 | | - | |
4013 | | - | |
4014 | | - | |
4015 | | - | |
4016 | | - | |
4017 | | - | |
4018 | | - | |
4019 | | - | |
4020 | | - | |
4021 | | - | |
4022 | | - | |
4023 | | - | |
4024 | | - | |
4025 | | - | |
4026 | | - | |
4027 | | - | |
4028 | | - | |
4029 | | - | |
4030 | | - | |
4031 | | - | |
4032 | | - | |
4033 | | - | |
4034 | | - | |
4035 | | - | |
4036 | | - | |
4037 | | - | |
4038 | | - | |
4039 | | - | |
4040 | | - | |
4041 | | - | |
4042 | | - | |
4043 | | - | |
4044 | | - | |
4045 | | - | |
4046 | | - | |
4047 | | - | |
4048 | | - | |
4049 | | - | |
4050 | | - | |
4051 | | - | |
4052 | | - | |
4053 | | - | |
4054 | | - | |
4055 | | - | |
4056 | | - | |
4057 | | - | |
4058 | | - | |
4059 | | - | |
4060 | | - | |
4061 | | - | |
4062 | | - | |
4063 | | - | |
4064 | | - | |
4065 | | - | |
4066 | | - | |
4067 | | - | |
4068 | | - | |
4069 | | - | |
4070 | | - | |
4071 | | - | |
4072 | | - | |
4073 | | - | |
4074 | | - | |
4075 | | - | |
4076 | | - | |
4077 | | - | |
4078 | | - | |
4079 | | - | |
4080 | | - | |
4081 | | - | |
4082 | | - | |
4083 | | - | |
4084 | | - | |
4085 | | - | |
4086 | | - | |
4087 | | - | |
4088 | | - | |
4089 | | - | |
4090 | | - | |
4091 | | - | |
4092 | | - | |
4093 | | - | |
4094 | | - | |
4095 | | - | |
4096 | | - | |
4097 | | - | |
4098 | | - | |
4099 | | - | |
4100 | | - | |
4101 | | - | |
4102 | | - | |
4103 | | - | |
4104 | | - | |
4105 | | - | |
4106 | | - | |
4107 | | - | |
4108 | | - | |
4109 | | - | |
4110 | | - | |
4111 | | - | |
4112 | | - | |
4113 | | - | |
4114 | | - | |
4115 | | - | |
4116 | | - | |
4117 | | - | |
4118 | | - | |
4119 | | - | |
4120 | | - | |
4121 | | - | |
4122 | | - | |
4123 | | - | |
4124 | | - | |
4125 | | - | |
4126 | | - | |
4127 | | - | |
4128 | | - | |
4129 | | - | |
4130 | | - | |
4131 | | - | |
4132 | | - | |
4133 | | - | |
4134 | | - | |
4135 | | - | |
4136 | | - | |
4137 | | - | |
4138 | | - | |
4139 | | - | |
4140 | | - | |
4141 | | - | |
4142 | | - | |
4143 | | - | |
4144 | | - | |
4145 | | - | |
4146 | | - | |
4147 | | - | |
4148 | | - | |
4149 | | - | |
4150 | | - | |
4151 | | - | |
4152 | | - | |
4153 | | - | |
4154 | | - | |
4155 | | - | |
4156 | | - | |
4157 | | - | |
4158 | | - | |
4159 | | - | |
4160 | | - | |
4161 | | - | |
4162 | | - | |
4163 | | - | |
4164 | | - | |
4165 | | - | |
4166 | | - | |
4167 | | - | |
4168 | | - | |
4169 | | - | |
4170 | | - | |
4171 | | - | |
4172 | | - | |
4173 | | - | |
4174 | | - | |
4175 | | - | |
4176 | | - | |
4177 | | - | |
4178 | | - | |
4179 | | - | |
4180 | | - | |
4181 | | - | |
4182 | | - | |
4183 | | - | |
4184 | | - | |
4185 | | - | |
4186 | | - | |
4187 | | - | |
4188 | | - | |
4189 | | - | |
4190 | | - | |
4191 | | - | |
4192 | | - | |
4193 | | - | |
4194 | | - | |
4195 | | - | |
4196 | | - | |
4197 | | - | |
4198 | | - | |
4199 | | - | |
4200 | | - | |
4201 | | - | |
4202 | | - | |
4203 | | - | |
4204 | | - | |
4205 | | - | |
4206 | | - | |
4207 | | - | |
4208 | | - | |
4209 | | - | |
4210 | | - | |
4211 | | - | |
4212 | | - | |
4213 | | - | |
4214 | | - | |
4215 | | - | |
4216 | | - | |
4217 | | - | |
4218 | 3935 | | |
4219 | 3936 | | |
4220 | 3937 | | |
| |||
4270 | 3987 | | |
4271 | 3988 | | |
4272 | 3989 | | |
4273 | | - | |
4274 | | - | |
| 3990 | + | |
| 3991 | + | |
4275 | 3992 | | |
4276 | 3993 | | |
4277 | 3994 | | |
| |||
0 commit comments