-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Quote v2: implement exiting on Enter at end #39911
Conversation
getBlockName, | ||
} = useSelect( blockEditorStore ); | ||
const propsRef = useRef( props ); | ||
propsRef.current = props; |
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.
Ideally we should make a useFreshRef
utility hook in compose.
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 wonder if this should be wrapped in a useEffect, it seems weird to assign current in render
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe even group could have it
/** | ||
* Internal dependencies | ||
*/ | ||
import { useExitOnEnterAtEnd } from './use-enter'; |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.
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