Quote v2: implement exiting on Enter at end#39911
Conversation
There was a problem hiding this comment.
Ideally we should make a useFreshRef utility hook in compose.
There was a problem hiding this comment.
I wonder if this should be wrapped in a useEffect, it seems weird to assign current in render
There was a problem hiding this comment.
If I'm not mistaken this looks like a "Latest Ref Pattern":
function useLatestRef(value) {
const ref = useRef(value);
useLayoutEffect(() => {
ref.current = value;
});
return ref;
}|
Size Change: +416 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
c711621 to
5008ec0
Compare
| if ( | ||
| ! hasBlockSupport( | ||
| getBlockName( wrapperClientId ), | ||
| '__experimentalExitOnEnterAtEnd', |
There was a problem hiding this comment.
Maybe even group could have it
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { useExitOnEnterAtEnd } from './use-enter'; |
There was a problem hiding this comment.
As the name suggests this only exits the block at the end, but I'm wondering if we also want to "split" it in the middle if we're in an empty paragraph but in the middle. (Like lists). Any thoughts @oandregal
There was a problem hiding this comment.
It seems good with split in the middle and since you have pushed changes for this, we should rename the block supports and hook.
Also noting that it seems kind of weird to have a generic named block support but is implemented in paragraph which is specific. I'm wondering if we could do this in RichText directly, similar to the onSplit functions and utilize default block? 🤔
There was a problem hiding this comment.
I don't know about whether we should move this to RichText but I agree with you that it's weird. Moving to RichText won't work for blocks that use RichText for more than a single RichText.
But yeah we should rename.
|
@oandregal In the last commit, I implemented splitting in the middle of a quote block as well. Let me know what you think. The algorithm is the following:
I was hesitant between "duplicating" (keeping all styles and attributes) or just creating a new unstyled quote block without citation... but I thought duplicating is a bit better WDYT. |
feb6a18 to
9ae5c6a
Compare
|
Had to rebase this to test (there were errors due to class overload), and also renamed it as suggested and fixed split on the middle. |
|
I've also tried both exit & split in group block: they work well. They didn't in list or columns, though. I guess we can look at those sort of blocks (+two level deep) in a follow up. |
youknowriad
left a comment
There was a problem hiding this comment.
Approving this even tough I worked a bit on it.
|
I also think this is ready. I'm going to merge to rebase #25892 |
What?
Allows the user to exit a wrapper block (like quote) when pressing Enter from an empty paragraph at the end of that wrapper block. This could be useful for other blocks too like group.
Why?
Feature parity. It's nice to be able to exit a quote and continue writing.
How?
Testing Instructions
Screenshots or screencast