Activate cursorBack when clicking the hidden thought#1128
Conversation
There was a problem hiding this comment.
I appreciate the succinct description of the cause of the problem, existing infrastructure, and choice of solution. I tested and it fixes the issue, but it unfortunately breaks a test case when tapping on an uncle.
This only occurs when isTouch is true. Tested on mobile safari and emulated on desktop by hardcoding isTouch = true.
Steps to Reproduce
- a
- b
- c
- d
(d is indented one level compared to the original test case in #1029.)
- Set the cursor on
c - Tap one line height below
c, just to the right of wheredwould be.
Current Behavior
Cursor moves to a.
Expected Behavior
Cursor and caret should move to d.
|
Hi @raineorshine, I reproduced your issue and I saw that onClick event of the Content div triggered. First, I suspected event bubbling, but it was not. In onTap of Editable we have already prevented the default events. The problem was that if we click the thought 'd', the 'b' thought will be collapsed and the place where we touch up is on I made some changes to Content component. Can you review it, please? |
src/components/Content.tsx
Outdated
| const clickOnEmptySpace = () => { | ||
| const clickOnEmptySpace = (e: any) => { | ||
| // Stop event bubbling. We need to handle this event if we click really on content element not other elements. | ||
| if (e.target.id !== 'content') { |
There was a problem hiding this comment.
I couldn't get id from React.MouseEvent so I used any for here.
There was a problem hiding this comment.
f546841 results in incorrect behavior when clicking on empty space.
Can you see if this is reproducible on desktop with isTouch = true? That will tell us if we can write an e2e case for this as well.
Steps to Reproduce
- a
- b
- c
- d
- Set the cursor on
c - Tap on empty space below
d
Current Behavior
If edit mode is enabled, edit mode is disabled and the cursor doesn't move.
If edit mode is disabled, the cursor moves to a.
Expected Behavior
Cursor and caret should move to db.
I apologize if I am misunderstanding, but
I'm not sure I understand yet. Can you explain this more? What happens before the |
|
Yes, but e.stopPropogation() doesn't work for touch events. But we can prevent event bubbling using e.preventDefault() for touch events. Here is an example for you, you can test in https://qf8e8.csb.app/ with forcing mobile view by developer tools. But our problem was not about event bubbling. I will try to explain more clearly. Think about the case above, when the cursor is on I will also look into the case you wrote and will try to make some explanation. |
Okay, thanks! I didn't know the touch and click events were competing like that.
Got it, that makes sense now! |
|
I made an in-depth review. I think the only option is that using the onMouseDown event instead of onClick. I explained the reason why we should not use onClick above. But when we use onMouseDown, another issue will occur. Because click/touch operation is not completed yet selection will be on Editable, so it will not pass the condition below. So I added a guard, to make sure onClick is triggered only if the user starts the action by pressing the Content element. Lines 108 to 110 in a08761a |
fixes: #1029
This issue occurs because we are clicking the editable area of hidden thoughts. I added border for .editable class to show you the boundaries of editable elements.
There is already a function written for handle this situation
isElementHiddenByAutoFocus. But the problem was in tap handler, it was not entering the if block becauseeditingOrOnCursoris true when we click the area ofdem/src/components/Editable.tsx
Lines 612 to 630 in e303756
I was thinking solve this issue with css
visible: hiddenproperty but this will cause other issues. For example, if we add.distance-from-cursor-3 > .child { visibility: hidden }then we can not see the thoughts in.distance-from-cursor-3We were going to need to add other css properties for visible thughts in.distance-from-cursor-3