Skip to content
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

Underline text when cmd + u is pressed #13117

Merged
merged 1 commit into from
Jan 15, 2019

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Dec 27, 2018

Description

Fixes: #13034

This PR adds a core/underline format option. This format option makes sure that when cmd + u is pressed the selected text gets the underline format.
This shortcut was documented but was not implemented.

How has this been tested?

I tested in chrome and firefox that when I press cmd + u inside a paragraph (or other block containing a RichText component e.g: image caption) the selected text gets underline format.

@jorgefilipecosta jorgefilipecosta added the [Type] Bug An existing feature does not function as intended label Dec 27, 2018
@davisshaver
Copy link
Contributor

+1 to merging this! Big gotcha (ran into it myself while writing this morning).

@jorgefilipecosta jorgefilipecosta requested a review from a team January 10, 2019 18:59
Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added to the keyboard shortcuts list.

Oh weird, it's already there. Does this intend to address #13034?

Looks good but see my comment about the button.

character="u"
onUse={ onToggle }
/>
<RichTextToolbarButton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this add a toolbar button or is this component just required to make the shortcut work?

If this isn't visible it's worth noting that in a comment; it's kinda confusing. (If it is visible, didn't we decided awhile back not to include underlines in the toolbar? According to #7162 the lack of a button was intentional.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No the button is not required. It should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tofumatt and @iseulde thank you for your reviews.
I am adding the button here button the button is not one of the default controls (they are formattingControls: [ 'bold', 'italic', 'link', 'strikethrough' ]) and no blocks currently use the button.
Adding the button here just opens the possibility for a block to have an underline button if the block wants to by changing the formattingControls prop. If we don't add the button here even if the block wants to show the underline the button will not render.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so it's mainly for third-party blocks that might want to extend RichText and show that button.

That makes sense, but then a comment mentioning why it's there/not rendered by default (basically what you said here) would be really helpful in explaining why it's there 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that in the past the button was explicitly removed and just the keyboard shortcode was allowed, other blocks should follow the same approach and we don't expect blocks to have the underline button so I end up removing the button as suggested by @iseulde and @tofumatt.
If a block really wants the button it is still possible using a custom format.

@youknowriad youknowriad added this to the 4.9 (Gutenberg) milestone Jan 11, 2019
export const underline = {
name,
title: __( 'Underline' ),
tagName: 'u',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a span with inline styles, just as we did in the classic editor.

This element used to be called the "Underline" element in older versions of HTML, and is still sometimes misused in this way. To underline text, you should instead apply a style that includes the CSS text-decoration property set to underline.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/u

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to use an inline style, thank you for pointing this. Now the markup is exactly the same as the one used by the classic editor.

@jorgefilipecosta jorgefilipecosta force-pushed the fix/undeline-text-when-cmd-u-is-pressed branch from 6428563 to 1532375 Compare January 11, 2019 17:11
@jorgefilipecosta jorgefilipecosta force-pushed the fix/undeline-text-when-cmd-u-is-pressed branch from 1532375 to d5ea4f3 Compare January 15, 2019 14:52
@jorgefilipecosta jorgefilipecosta merged commit 69a336f into master Jan 15, 2019
@jorgefilipecosta jorgefilipecosta deleted the fix/undeline-text-when-cmd-u-is-pressed branch January 15, 2019 15:21
};

return (
<Fragment>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Fragment wrapper necessary?

@ellatrix
Copy link
Member

This no longer works since #12249.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants