-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inserter: Fix the insertion point #994
Conversation
Can confirm the inserter works great now, with no JS breakage that I can see. |
onMultiSelect( { start, end } ) { | ||
dispatch( { type: 'MULTI_SELECT', start, end } ); | ||
}, | ||
} ) | ||
)( clickOutside( VisualEditorBlockList ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we can't deselect a block by clicking on the canvas now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and I think you explicitly suggested this somewhere? Am I wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is that focused and selected should be two different states, where focus also means selected. Clicking on the canvas should deselect the block, what I meant before is that clicking on the inserter should unfocus but not deselect (same for sidebar inspector).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so we shouldn't leverage onClickOutside for this but maybe onClick
on the canvas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now in aba596f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm 🤔 Making a selection doesn't seem like the sort of action you take when you want to insert something. If anything, that would mean, delete the selection and insert something instead, but then I'd rather have it explicitly separate.
The inspector toggle is currently hidden when the multi-select header takes over, not sure if we want to keep something there, but both the inserter and inspector would then be actions tied to multi-selection and would not remove the selection on click.
To me is seems better that clicking or moving focus anywhere outside the UI that has to do with multi-selection should deselect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd think of the multi-select header as having tabIndex="-1"
and being some weird kind of modal. It would contain the focus, and if you click outside of it, or press escape, the selection is cleared, just like a modal would be closed. As long as the selection is there, backspace always deletes the selection content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need a decision somehow? I'm a bit confused on the details, but I'd like to help work through the flow if need be, and if someone can clarify the conflict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep we definitely need a decision here. So for now on master, we're considering the browser selection (and focus) as separate from the selectedBlock and multiSelectedBlocks (which should probably be merged into one unique concept).
We're doing so because we want to be able to open the inserter and the sidebar without losing the selection (note that clicking buttons moves the focus to the button).
But multi-selection allows us to delete the selected blocks by hitting "backspace" which has no sense if the selection is not focused (backspace should work on the focused input or text area ...)
also Ella is saying
The inspector toggle is currently hidden when the multi-select header takes over
This was not the case when this PR was merged.
So should we tie the selection to the focus which means clicking anywhere deselect everything or should we find a middle-ground where we do so only for multi-selection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is complex, and I think I'm not getting all the nuance, so please correct me if I'm wrong here — it seems like we have two types of selection:
- selection when you click the block
- selection when a block is selected via multi select
1 is important for the inspector, as we need to be able to adjust parameters there without deselecting the block. So far so good.
But multi-selection allows us to delete the selected blocks by hitting "backspace" which has no sense if the selection is not focused (backspace should work on the focused input or text area ...)
I feel very daft here, the behavior in master feels pretty okay with me:
- I select across blocks, press backspace, and the blocks are deleted
- I select ... oh I think I see what you're getting at.
If I click inside a text block and press backspace, I delete text. If I then click on the border, the text is unfocused and it seems like the block is focused. Then backspace deletes the block. This is especially important, I think, for the bigger blocks, like image, where you almost always select the block.
If I understand you correctly, the big challenge here is that there's confusion between selecting blocks, setting focus on text, and selecting across blocks, correct?
It seems like you're saying selecting a block (clicking on the border), should highlight the block the same way as multi select does, because it's technically almost the same? Let's imagine what would happen if we did that — would this be desirable or not? Hmm. Thinking.
02b9fdf
to
a10a8b8
Compare
This is working well for me. Let's merge. We may want to tweak the appearance of the selected block when hovering within the inserter (maybe fainter outlines, maybe hiding the block toolbar) as further explorations. @jasmussen do you have any ideas for adding clarity? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the stopPropagation
introduced in #836 .
} | ||
|
||
onClick( event ) { | ||
if ( event.target === this.container ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Between this and #836, I think I like this approach better. But it also means we probably don't need the stopPropagation
anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updating
@@ -68,10 +68,15 @@ class InserterMenu extends wp.element.Component { | |||
} | |||
|
|||
hoverBlock() { | |||
const { lastMultiSelectedBlock, selectedBlock } = this.props; | |||
let insertionPoint = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a subsequent pull request, we should think about consolidating or simplifying some of this shared logic between the menu and the root component. I still think it's a bit bizarre how we assign insertion point in the hover intent, but IIRC the reasoning was to show the indicator in the post.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, right! Actually, I thought about passing a prop from the inserter
to themenu
to void recomputing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conflicts introduced by #992 but otherwise LGTM 👍
Hah, sorry :) |
209842c
to
3d16e47
Compare
@mtias not sure what the purpose is. The inserter insertertion indicator feels pretty good to me. But I could be missing something? |
There were some regressions to the insertion point feature due to multi-selection #896
The behaviour of this PR:
Open questions:
I think we should unify the concept of selected block and multi-selection into a unique state