-
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: Leverage provisional block deletion for unmodified default #6452
Conversation
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.
31fba8e
to
28e735f
Compare
Nice catch @noisysocks . There's actually a couple things going on here:
I made the end-to-end tests more thorough to account for your behavior (and others) in 28e735f. cc also @youknowriad, since you may have an opinion on explicitness here. |
<!-- wp:code --> | ||
<pre class=\\"wp-block-code\\"><code>Code block</code></pre> | ||
<!-- /wp:code -->" | ||
<p>Can have multiple paragraphs</p><cite>CiteCan have line breaks as well<br/></cite></blockquote> |
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.
It's weird that the <br>
is not between "Cite" and the rest. Is this a test issue only or a real issue.
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.
It's weird that the
<br>
is not between "Cite" and the rest. Is this a test issue only or a real issue.
Hmm I totally missed this. Will look into it.
I personally don't know if we want to consider a new block created with "Enter" as provisional. Imagine this use case, you have a bunch of paragraphs and you want to add "space" between them. you can just click Enter at the end of a paragraph. With this change, the paragraph is removed. I don't have strong opinion but the code is good. |
I'm not sure what the best answer is here. Why should it be considered provisional if the paragraph block is created with the between-inserter, but not if it's created by an Enter press ? Why does the paragraph get replaced if we proceed to use the inserter after the Enter press, if it's not provisional ? For both the technical implementation and the user experience, we'd benefit from consistency here. Related: Spacer block (#6121) could be used to achieve such an intended goal for intentional spacing. cc @jasmussen Would you have any thoughts on the expected behavior here? |
Interesting discussion, I love it. We're entering an aspect of syntactic refinement that indicates polish, this fact alone is great, so awesome work. I think we're also entering a key aspect of editors, where we have to decide on a direction, choosing between freedom to do random potentially suboptimal things on the one side, and automatically doing "helpful" cleanup work on the other side and potentially going overboard. Take Medium, for example, they are definitely in the camp of doing too much cleanup work in my opinion. For example place your cursor in the middle of a word and press and hold spacebar. You'll only ever make a single space, every subsequent one will be eaten with no indication what's up. Similarly I just switched from Atom to VS Code. Atom was always kind to ensure I had a trailing linebreak at the end of code files. VS Code does not do that. This is one act of "helpfulness" that I'm missing. It's a very delicate balance in other words, and often subject to personal opinion. Having just checked out this branch, this feels right. It feels logical and consistent. Besides, you can create TWO linebreaks and both will be inserted, and there's a spacer block — we could potentially even look at auto-converting two empty paragraphs to a spacer block. It can't hurt to hear more opinions on this, CC: @karmatosed @mtias GIF: |
Tangent: You probably want to install EditorConfig for VS Code |
Whoooa nice, that looks great. Do you know if it works with Settings Sync? |
No idea, I don't use VS Code 😄 Merely remarking on the fact that you may have had a similar EditorConfig plugin for Atom, or otherwise that the project includes an Line 12 in 87638ce
|
This has stagnated from indecision. Going to close, but cherry-pick some less controversial changes into new pull requests. |
This pull request seeks to simplify the inserter's
onInsertBlock
implementation to take advantage of existing provisional block deletion (#5417). The intended behavior is preserved: When inserting a block via an inserter and the selected block is an unmodified default block, the act of insertion should trigger the deletion of the default block.Notably, this avoids the need for
selectedBlock
to be passed to the Inserter, which is a source of frequent renders for the component.Implementation notes:
Block selection state tracks from an
INSERT_BLOCKS
action type, so it was necessary to addINSERT_BLOCKS
as the triggering action for theremoveProvisionalBlock
effect handler. Alternatively, we could consider selection from insert a side-effect of the insert itself, removing handling of insertion from theblockSelection
state and leveraging the existingSELECT_BLOCK
effect handler for provisional block deletion.In future iterations, it might be worth exploring whether we can collapse the concepts of "unmodified default block" with "provisional block", as on the surface they appear to be referring to the same type of block.
Testing instructions:
Verify that when inserting a block after having created a new default block (paragraph), the unmodified default block is removed.
The "Adding Blocks" end-to-end test has been revised to test for this behavior: