prev 2021-07-19Movidea Development Diary
The problem around the mouse event, the last time I did Regroup, I was not able to understand it properly because I became aware of it after it became quite complicated, but this time I was able to understand it.
The preferred, natural, âmeaning chunkâ for humans is the one on the left.
- Moving groups by dragging
- range selection
- Moving a selection by dragging
In reality, however, the browser specifications
- The drop event of a drag move is the same in both cases
- mousemove and mouseup are called no matter which operation is being performed.
At the time of Regroup, everything started mousedown, partly because everything was operated on the Canvas element.
- The crossed-out mark means âprocessing performed when mouseup occurs without mousemove after mousedownâ.
- In short, click
Therefore, these
- Group a âlump of processesâ into a handler object to determine which handler to use at the timing of mousedown.
Looks good at first glance, but no.
- There is processing that must be done in common by multiple handlers.
- If I write in each one, there will be an omission.
- To solve this problem, a design change was made to âput another layer between the layers and perform common processing all together.
- It was implicitly assumed that the process would be finalized at the mousedown stage.
- Cases that didnât were harder to handle.
- What if another mousedown comes right after the mousedown and itâs multi-touch?
- Drop a sticky into a group by dropping it into the groupâ is divided into cases depending on the situation at the time of drop.
- Cases that didnât were harder to handle.
With that in mind, how do we sort this situation out this time around?
- I thought I had it figured out, but then I lost it againâŠ
- I thought that since the state was implicitly occurring, it would be a good idea to manage it yang!
- The current code is flagging isDragging on mousedown.
- No, no, the current implementation already shows a difference between the right diagram I wrote in âmy understandingâ and the actual behavior.
- mouseDown, mouseMove, dragStart, drop are executed in this order
- As a result, the flag remains up.
- Actual behavior
- In this case, the element at the start of the upper process is DOMically contained in the element of the lower process, so there is a way to add mousedown to the upper process, grab it there, and stopPropagate.
- I mean, there doesnât seem to be any other way to do it.
- In short, just as source code has a lexical scope based on its inclusion in the code, the DOM has a scope based on its inclusion.
- So, if you think about it, flagging with mousedown and doing a specific process with mousemove only when the flag is up is cutting off a section on the time axis with a dynamic scope.
- A graphical representation of it would look like this
- Based on this, hereâs what we need to do this time
- This time itâs still simple enough that we could design it, but if we get a couple more cases of this, we wonât be able to draw it on the diagram.
What to do this time in light of this
- I donât rush to add weird layers.
- No rushing to divide
Implement âMove Selectionâ and âMove Stickies Out of Groupâ and write a test case before refactoring.
2021-07-21 What I noticed after a nightâs sleep
- If you want to transfer the elements of the selection at the time of selection
- After a selection is made, clicking outside the selection must be undone
- So thereâs another state of affairs occurring here.
Condition should be subject to testing
Now the local variable has state, but make it global before ts
after ts
test test.ts
Now we can detect when weâre in a strange state.
- Deliberate bugs were fixed only after testing was done to make sure they would rub properly.
Yesterdayâs âI didnât realize that mousedown comes before dragstartâ was verified with a test case. test.ts
I thought this would fail, but it doesnât. I see.
- Mousedown occurs first when humans operate.
- In the test case, Iâm just issuing the dragstart event, so no mousedown occurs.
If you test this as if it were a real event, it would look like this test.ts
This fails as expected. And then stopPropagation and confirm that it works as expecteddone
So far, so good. Next, weâll discuss the âpost-selectionâ condition I noticed this morning.
- Selection should not be released by dragging
- Should be canceled on mousedown outside the selection
- If you dare to draw a diagram, it looks like this
- đ€
-
- I can write the release code in A.
- But Iâm afraid Iâll leave it out when more similar ones come along in the future.
- You canât automatically put a release code on all of them.
- Because you canât unlock it with a B.
- In natural language, âmousedown outside the selection to releaseâ.
- What is this âexceptâ?
- What about mousedown on a sticky that is DOM-included in the selection?
- This is âDOM stacking orderâ (oops, another new scope)
- The selection is before the selected stickies (most of them) in the stacking order of the DOM, so it should block the event.
-
- Clicking C does not cause mousedown on stickies
- D is a click outside the selection, so you can deselect it.
- Wait, so when you do the âadd selected to divâ thing, you need another div?
- Can I use z-index?
- No, itâs not. Thereâs no need to use a div to visualize the selection to summarize the selection.
- What is this âexceptâ?
Decided to highlight the selected ones by lowering the opacity of the ânot selected ones.â
- This still doesnât implement state deactivation.
Oh, no, if dragging the âShow Selectionâ and the div that wraps the selected object are separated, then dragging the âShow Selectionâ wonât move the selected objectâŠ
I was able to get to the point where I could select multiple items and drag them around, but the âShow Selectionâ is not moving.
Itâs done.
After writing the test case, it became clear that the position was off by only 2 pixels vertically from the expected position.
- Dragstart the (0, 2) of the div with top:150px and the event that actually occurs is (150, 150)
- Seems to be reproduced only in the Cypress environment⊠test.ts
This page is auto-translated from /nishio/2021-07-20Movideaéçșæ„èš using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. Iâm very happy to spread my thought to non-Japanese readers.