-
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
Rich text: add character shortcuts for wrapping selection #42469
Conversation
Size Change: +287 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
6b5c2fc
to
4a768d1
Compare
packages/block-editor/src/components/rich-text/use-before-input-rules.js
Outdated
Show resolved
Hide resolved
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.
Tested this and works very well. The implementation makes perfect sense alongside useInputRules
so I say let's 🚢 it 🙇🏻
*/ | ||
const wrapSelectionSettings = [ | ||
'`', | ||
'()', |
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'm a bit worried with expanding these to characters that are natural openers because I suspect it's a typical action to select a word and type the first letter of what should replace it — parentheses and quotation marks, in particular, would have a much higher incidence of cases where the intention is indeed to replace the selected text with the mark, not to wrap it in them.
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 we try it and see if it's discovered? If it's doing something unexpected, we can always remove some of the characters easily?
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'm fine with it either way, just curious how people will react to it.
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 think it's worth trying to see how it feels in practice, but I think I'd rather add them a bit more incrementally so we can focus feature announcements on the ones we are more certain about first without the ones that could be problematic tainting the feature.
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, I removed everything but `
and the quotes. Or should we remove the quotes too?
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 remember someone asking for the quotes back when we first added pasting a link over selection, but I can't find that conversation now...
4a768d1
to
944804e
Compare
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 get this in and see how it feels. We might need to reign back the quotes one if it becomes annoying.
What?
A new tiny rich text feature: when you select some text and press the back tick (
`
), it will wrap the selection around back ticks and as a result wrap it in a code tag instead of replacing the selection with a back tick.The feature is generalised to work with any characters. So if you press
(
for example, it will also wrap the selection with()
instead of deleting the selection. Same for"
etc.Why?
It's a cool shortcut.
How?
The feature is a simple behavioural hook and completely isolated. It's added to the block editor's RichText implementation. It works by listening to the
beforeinput
event.Testing Instructions
Select some text. Press
`
.Screenshots or screencast