-
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: Indicate which text will be turned into a link #8807
Conversation
8dcb073
to
06c8f1a
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.
Works well, and code looks good, though I'm not particularly familiar with the workings of RichText. This was a good chance to learn a few things.
I think the test descriptions could be improved, happy with the rest.
switch ( formatName ) { | ||
case 'link' : { | ||
const anchor = find( parents, ( node ) => node.nodeName.toLowerCase() === 'a' ); | ||
return !! anchor ? { value: anchor.getAttribute( 'href' ) || '', target: anchor.getAttribute( 'target' ) || '', node: anchor } : {}; | ||
const anchor = find( parents, ( node ) => node.nodeName === 'A' ); |
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.
Just wondering why keep this a switch? Is it for future extensibility?
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.
Yeah, it's probably not useful. Removed in 7d2ffce 👌
describe( 'Managing links', () => { | ||
beforeEach( async () => { | ||
await newPost(); | ||
} ); | ||
|
||
it( 'Creating a link by selecting text and clicking the Link UI', async () => { |
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 this should be something like this, so that it makes a nice sentence:
describe( 'Creating a link by selecting text and clicking the Link UI', () => {
it( 'creates the link placeholder', async () => {
seems to be the same thing with the other test descriptions as well.
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've rejigged the describe()
and it()
descriptions in 543da2f to read like English sentences 🇬🇧
Thanks for the review! I've fixed your comments
e5ef740
to
543da2f
Compare
Played with this a bit more. Works well as far as I can tell. Was a bit concerned that we do Noticed some general inconsistencies with adding a link though. Not sure if any is related to this pr, but sometimes undo doesn't undo just the action of adding a link. It removes/reverts most of the typing together with the link as one step, and redo add everything back in one step. Testing in the Classic block, it behaves quite inconsistently, especially when the (old) link modal is used (by clicking the cogwheel there). That will probably need another issue if one doesn't exist already. |
Uh, one more: when clicking in the middle of a word (not selecting it) and clicking the Add link button in the Classic editor the word is selected automatically. Here the word is not selected. That results in inserting a link where the linked text is the whole URL. So we end up with the word split by an linked URL. Thinking this should work like in the Classic editor and select the word where the caret is as soon as Add link is clicked. It works that way when setting to "bold" for example. |
When inserting a link, the text selection disappears when the focus changes into the URLInput text field. This makes it hard to tell which text will be turned into a link. The Classic Editor solves this by inserting a placeholder <a> element, which is the approach that we borrow here.
A `switch` is overkill when there's only one format value that acts differently.
Renames managing-links → links and makes the test descriptions read like English sentences.
543da2f
to
47d0bd8
Compare
Thanks @azaozz! Since those issues you've identified exist in
Could you create an issue for this? I'm unable to reproduce it in my environment.
Agree with this. Let's tackle it in #9183. |
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
const setFixedToolbar = async ( b ) => { |
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.
b
? What is b
?
Verbose good. Cryptic bad.
Fixes #6156. Supersedes #4909.
When inserting a link, the text selection disappears when the focus changes into the
URLInput
text field. This makes it hard to tell which text will be turned into a link.The Classic Editor solves this by inserting a placeholder
<a>
element, which is the approach that I'm borrowing here.The placeholder
<a>
is removed when the selection changes or when the block is deselected. We setdata-mce-bogus
on the placeholder<a>
so that it doesn't ever get serialised into post content.To test:
I've included E2E tests for most basic link interactions, so look for the ✅!
It's worthwhile manually testing that no undo levels are created when placeholder links are created and destroyed. To do this:
console.log( 'undo level created' )
toRichText::onCreateUndoLevel()