Skip to content
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

Try/deleting multi blocks #3194

Closed
wants to merge 4 commits into from
Closed

Conversation

ephox-mogran
Copy link
Contributor

@ephox-mogran ephox-mogran commented Oct 27, 2017

Description

Fix for #3191
Stopped focusing inside editors when multi-select was enabled, and focused an appropriate block when the current block was deleted.

How Has This Been Tested?

Wrote a test for the effects.js addition DELETE_BLOCKS

Screenshots (jpeg or gifs if applicable):

Types of changes

Introduced another effect
Stopped passing focus through to blockType.edit when we have a multi-selection
Focused a block after deleting

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@ephox-mogran
Copy link
Contributor Author

One thing I was unsure of how to do was focus the post title if there are no blocks.

@codecov
Copy link

codecov bot commented Oct 27, 2017

Codecov Report

Merging #3194 into master will increase coverage by 0.16%.
The diff coverage is 73.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3194      +/-   ##
==========================================
+ Coverage   31.64%   31.81%   +0.16%     
==========================================
  Files         217      217              
  Lines        6282     6296      +14     
  Branches     1116     1119       +3     
==========================================
+ Hits         1988     2003      +15     
+ Misses       3610     3609       -1     
  Partials      684      684
Impacted Files Coverage Δ
editor/block-settings-menu/block-delete-button.js 0% <0%> (ø) ⬆️
editor/modes/visual-editor/index.js 0% <0%> (ø) ⬆️
editor/modes/visual-editor/block.js 0% <0%> (ø) ⬆️
editor/actions.js 42.55% <100%> (+3.42%) ⬆️
editor/effects.js 58.42% <100%> (+7.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa13720...cc43e66. Read the comment docs.

@@ -285,6 +285,22 @@ export function removeBlocks( uids ) {
}

/**
* Returns an action object used in signalling that the blocks
* corresponding to the specified UID set are to be removed, and then
* another block given focus. It differs from removeBlocks in that it
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want a new action. Could we just use a flag?

Copy link
Member

Choose a reason for hiding this comment

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

Or dispatch two actions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we shouldn't have two concurrent actions with hard-to-distinguish semantics.

In the new DELETE_BLOCKS effect, the removal itself is not conditional on state (only on payload, with the check for blockUids.length). Therefore, we should keep a single action, REMOVE_BLOCKS, and add a small effect for it that handles the new focus.

Now, the PR deals with two separate things:

  • Fixing deletion in multi-block selection
  • Focusing siblings after deletion

The former is a bug fix, the latter a UX improvement. I like it, but it begs the question: if we want to refocus a block after a multi-block deletion, are there any other cases (single-block deletion) where we don't want to refocus a block? Should we prefer a consistent behavior, whether that means always refocusing or never refocusing? cc @jasmussen

If still we want to make a distinction, then our effects.REMOVE_BLOCKS could look like:

if ( blockUids.length > 1 ) {
  const blockToFocus = ;
  dispatch( focusBlock( blockToFocus.uid ) );
}

Copy link
Contributor Author

@ephox-mogran ephox-mogran Oct 27, 2017

Choose a reason for hiding this comment

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

Do we really want a new action. Could we just use a flag?

I've generally found flags are much harder to reason about later, and don't scale at all --- but that's my experience. I'm happy to go with the majority.

Or dispatch two actions?

I incorrectly assumed that for multi-actions, that effects is where they should go. I'm now realising that effects is for more complicated things. I don't think I'd seen many examples of where more than one action was dispatched in a component, so I thought that if you needed to do that, you put it in effects. My mistake.

are there any other cases (single-block deletion) where we don't want to refocus a block?

My rationale for keeping the old behaviour and adding new behaviour is that you never want to enforce focus in an action. You might find that something starts removing blocks asynchronously, and it can not focus grab from where you are. We could do some other logic, like only focus another block if we know for sure the focus was in one of the blocks to be removed (because nothing about the remove semantics enforces that they were selected), but I would strongly advise against always refocusing a block on remove unless it's a bit smarter than just "always".

In regards to the actions, effects separation, I'd really welcome something fixing it with a commit, and then I can look at the diff and see by example what your preferred approach is.

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

Approving this for the bug fix itself, regardless of the decision on the refocusing after deletion.

@ephox-mogran
Copy link
Contributor Author

So after reading @iseulde 's comment (#3191 (comment)), I'm wondering if this is the approach we want to take. What this will do is focus the selectionStart outer container (but not the editable inside it). Therefore, the keyboard handling is picked up at the outer container level.

It's quite likely that at some point, we chose to focus the block settings button instead of the outer container. This was probably done by setting focus to be null in all multi-select actions. I probably find it a bit jarring to have the focus switch to a button not visually within my selection, but I also understand that the block settings button is really the primary action that you can do when multiple blocks are selected (you might also want to move). So, in summary, should we change this approach to just focus the block settings button, instead of the first container in the selection? Or should we keep it as it is, and focus the outer container and allow them to tab to the settings button?

This does highlight an advantage of storing all the known focus information in the redux state like #3195 was exploring, though. You can choose explicitly what to focus after firing a multi-select by just setting the focus appropriately in the action (e.g. block-settings). There are definitely disadvantages, though.

@ellatrix
Copy link
Member

I would prefer if we go back to focussing an action in a series of actions for multi-selection, as that's the next thing you would want to do, even if it's just clearing or extending the selection. Setting focus on one of the selected blocks is meaningless in this "mode". I'll open a new PR with an alternative fix that restores the previous behaviour.

@ellatrix ellatrix mentioned this pull request Oct 29, 2017
3 tasks
@ellatrix
Copy link
Member

Okay, I created #3222.

@ephox-mogran
Copy link
Contributor Author

@iseulde there are advantages and disadvantages I can see to focusing an action after a multi-select. Let me know if you agree?

Advantages

  • it's the next action that a user will often want to do, therefore, focusing it immediately makes it quick to use

Disadvantages

  • it becomes unintuitive to the user that they still have block selection actions (keep selecting more blocks, delete selected blocks) with the keyboard. Even though the settings button is currently a descendant of the block, that is partially an implementation detail (though it probably always will remain there). As a user (especially using a screen reader), if my focus was transferred to a menu button after selecting multiple blocks with the Shift key + arrows, I would no longer expect that I can select any more blocks or delete the current blocks with delete. It will actually work, but it's not expected. Holding Shift and pressing arrow keys on a dropdown button shouldn't do anything in my mind. Does that make sense?

So this disadvantage that I see is that selecting a button to me conveys that we are no longer able to modify our selection or interact with it outside activating button options. That's just my opinion, though.

@jasmussen
Copy link
Contributor

This ticket is a big confusing to me, so please bear with me as I ask silly questions.

Is the primary purpose of this ticket to ensure that the Delete key deletes multi-selected blocks? If so, yay, because that's broken now.

The former is a bug fix, the latter a UX improvement. I like it, but it begs the question: if we want to refocus a block after a multi-block deletion, are there any other cases (single-block deletion) where we don't want to refocus a block? Should we prefer a consistent behavior, whether that means always refocusing or never refocusing? cc @jasmussen

Just to try and understand, please correct me if I'm wrong. This concerns the following behavior?

  • You have 4 blocks
  • You multi select the two blocks in the middle
  • You press Delete, or click the ellipsis and then the Delete action

Is the question then: "where do we put focus now"?

If that is the question, I think the answer has to tie into the navigation mode/editing mode. As soon as you multi select, you are in navigation mode, and you can use the arrow keys to set focus on a block. This is useful for when you want to use keyboards to manually select or unselect individual blocks. The answer to what happens when you delete is that you fall back to this navigation mode arrow key focus being on the block before the blocks deleted, or the first block otherwise. Does that make sense?

@ellatrix
Copy link
Member

So this disadvantage that I see is that selecting a button to me conveys that we are no longer able to modify our selection or interact with it outside activating button options.

That may be true, but I don't really thing it's a problem? I guess ideally we'd focus the selection of blocks, but certainly not just one? cc @afercia Maybe you have insights. :)

@ellatrix ellatrix mentioned this pull request Oct 31, 2017
3 tasks
@ellatrix
Copy link
Member

ellatrix commented Nov 3, 2017

@ephox-mogran Do you think we still need pieces from this PR?

@ephox-mogran
Copy link
Contributor Author

Not sure @iseulde

@youknowriad
Copy link
Contributor

Closing as superseded by #3253

@youknowriad youknowriad deleted the try/deleting-multi-blocks branch December 13, 2017 13:24
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.

5 participants