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

Add remaining editable shortcuts #4411

Merged
merged 15 commits into from
May 4, 2018
Merged

Add remaining editable shortcuts #4411

merged 15 commits into from
May 4, 2018

Conversation

ellatrix
Copy link
Member

Description

See #71.

This PR adds the remaining shortcuts for editable:

  • access+d for strikethrough (<del> tag).
  • access+c for code.
  • access+a and meta+k to add a link.
  • access+s to remove a link.

access means ctrl+alt on Mac and shift+alt on Windows.
meta means cmd on Mac and ctrl on Windows.

How Has This Been Tested?

  1. Press access+d and the text should be struck through. Press it again and the formatting should be removed.
  2. Press access+x and the text should be code. Press it again and the formatting should be removed.
  3. Press access+a and the pop up to add a link should appear focussed.
  4. Press meta+k and the pop up to add a link should appear focussed.
  5. Press access+s after putting the caret on a link. The link should be removed.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@ellatrix ellatrix added [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... labels Jan 11, 2018
@jasmussen jasmussen mentioned this pull request Jan 11, 2018
35 tasks
@ellatrix
Copy link
Member Author

Oh, these could actually use something in the tooltip!

@ellatrix
Copy link
Member Author

I don't know if that lost commit makes sense. Can always remove it, or @jasmussen, feel free to edit. :)

@@ -19,22 +19,22 @@ const { ESCAPE, LEFT, RIGHT, UP, DOWN } = keycodes;
const FORMATTING_CONTROLS = [
{
icon: 'editor-bold',
title: __( 'Bold' ),
title: __( 'Bold — ⌘B' ),
Copy link
Member

@jorgefilipecosta jorgefilipecosta Jan 11, 2018

Choose a reason for hiding this comment

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

Should we use ${ __( 'Bold') } — ⌘B instead? As we are not expecting keyboard shortcuts to be changed during translation, this way translations for 'Bold' get reused.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, though I'm not sure dash and order should not be translatable. Maybe we can just omit the shortcut itself from the translation.

Copy link
Member

Choose a reason for hiding this comment

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

Should we use ${ __( 'Bold') } — ⌘B instead?

Alas, this wouldn't work for RTL languages like Hebrew and Arabic.

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be safe to use something like ${ __( 'Bold' ) } ${ __( '-' ) } ⌘B. This way translations are reused and we address the point raised by @iseulde.
Regarding the RTL point, It's a nice question, honestly, I don't know if in RTL normally the shortcuts appear inverted, but in LTR, if the shortcuts appeared like "⌘B — Bold" it would be ok so maybe in RTL both ways are also "ok". To be safe be on the safe side we can use the original version, I don't have a strong opinion here.

@jasmussen
Copy link
Contributor

This is working really well for me. Except for access+c for code, I can't get that to work for some reason. Mac/chrome.

I love that you added the keyboard shortcuts to the tooltips, starting work on #2980:

screen shot 2018-01-12 at 09 31 33

However can we make it look like this instead?

31429137-76098bf4-ae6d-11e7-8e33-2c954afb130a

If not, then we should replace the — with a couple of spaces (like &nbsp; or a CSS margin — and ideally a slightly tweaked color as well). Regarding color, I understand we need sufficient contrast, but I'd rather we use our darkest gray for the tooltip background, fully opaque, white text for label, and the darkest gray we can within AAA ranges for the tooltip.

Is this doable? If not, then probably good to keep the shortcuts still, then we can look at improving the look in a separate PR.

@ellatrix
Copy link
Member Author

@jasmussen Updating the PR, but now wondering what colour you have in mind? :)

@jasmussen
Copy link
Contributor

How about this:

  • fully opaque $dark-gray-900 for tooltip background
  • $white text, 13px system font
  • $dark-gray-200 text for keyboard shortcuts

Those all pass AA contrasts. Mockup:

screen shot 2018-01-15 at 10 55 12

@ellatrix
Copy link
Member Author

@jasmussen I added it as a separate attribute on the toolbar/iconbutton/tooltip, so it can be styled all the same. Let me know if this is what you have in mind, and feel free to change to styles of course. :) Thank you!

@ellatrix
Copy link
Member Author

Ah, I missed your comment now, I'm so slow.

@ellatrix
Copy link
Member Author

Updated. :)

@ellatrix
Copy link
Member Author

Except for access+c for code, I can't get that to work for some reason. Mac/chrome.

I can't reproduce. Are you sure it's the right combination? I also found myself trying cmd+x before, which is cut. :D

@jasmussen
Copy link
Contributor

screen shot 2018-01-15 at 11 06 31

This looks amazing to me. @jorgefilipecosta does this particular layout fix issues with RTL?

I can't reproduce. Are you sure it's the right combination? I also found myself trying cmd+x before, which is cut. :D

I think the reason it's not working is that I have that keyboard shortcut assigned to the magnifier in OSX. If it works for another Mac user then 👍 👍 from me :D

@ellatrix ellatrix mentioned this pull request Jan 16, 2018
3 tasks
@afercia afercia added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Mar 5, 2018
@ellatrix
Copy link
Member Author

ellatrix commented Apr 2, 2018

Rebased. What's left here?

@jasmussen
Copy link
Contributor

What's left here?

Took it for a quick spin. Experience wise, this feels solid to me. I don't know if we need any more code reviewing.

I would be happy to get this merged in sooner rather than later. If it needs a code review, @youknowriad can you take a look? Looks good to me.

@@ -19,21 +19,25 @@ const FORMATTING_CONTROLS = [
{
icon: 'editor-bold',
title: __( 'Bold' ),
shortcut: '⌘B',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned about the hard-coding of the modifier key as , which is meaningless to non-macOS users. IMO, this is a blocker.

There's precedent of cross-platform handling:

const isMac = window.navigator.platform.toUpperCase().indexOf( 'MAC' ) >= 0;
const mod = isMac ? '⌘' : 'Ctrl';

@tofumatt tofumatt self-assigned this May 1, 2018
@@ -16,6 +16,7 @@ import { prependHTTP } from '@wordpress/url';
/**
* Internal dependencies
*/
import { primaryShortcut, primaryAltShortcut } from 'utils/keycodes';
Copy link
Member Author

Choose a reason for hiding this comment

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

What's primaryAlt? So primary but not really? So secondary? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Oops, it should totally be secondary.

*
* @return {string} The keyboard shortcut.
*/
export function metaShortcut( character, _isMacOS = isMacOS ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

What will this be used for?

Copy link
Member

Choose a reason for hiding this comment

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

If we want keyboard shortcuts using Ctrl+Q on Mac, though admittedly I don't see any yet. It'd be Windows+Q on Windows… should I just remove it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think across the whole application, we should only ever implement two combinations: primary and access.

*
* @return {string} The keyboard shortcut.
*/
export function primaryAccessShortcut( character, _isMacOS = isMacOS ) {
Copy link
Member Author

@ellatrix ellatrix May 2, 2018

Choose a reason for hiding this comment

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

Could we drop this combination in favour of the standard access combination that is now called accessShortcut ?

Copy link
Member

Choose a reason for hiding this comment

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

That'll change an existing keyboard shortcut: https://github.com/WordPress/gutenberg/blob/add/editable-shortcuts/edit-post/keyboard-shortcuts.js#L8

Which I presume has many modifiers as it isn't common. But we could call it tertiary. I am now realising I made a terrible API by surfacing its underlying implementation.

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 think we should change it be an access shortcut. It was just a random combination that didn't clash with anything.

Copy link
Member Author

@ellatrix ellatrix May 2, 2018

Choose a reason for hiding this comment

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

See #3755 (comment) for history on that.

No particular reason for that combination, it should be revised.

Copy link
Member

Choose a reason for hiding this comment

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

I just tried Control + Alt + M on Mac and it outputs a unicode character in Gutenberg:

2018-05-03 00 23 52

But Shift + Alt works on MacOS. I guess it would be confusing to name this "access" when its rules are different… but I think just using Shift on both platforms would work. It worked in MacOS:

2018-05-03 00 25 52

Copy link
Member Author

Choose a reason for hiding this comment

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

Would be nice to have a combo that is the same on all OS though. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@tofumatt tofumatt May 3, 2018

Choose a reason for hiding this comment

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

Oddly enough the Mu doesn't appear outside of Gutenberg. If I type Ctrl+Alt+M into this text field it seems like an invisible unicode character is inserted instead.

Looks like Cmd+Alt on Mac will work, though Cmd+Alt+M is also the shortcut to enable responsive design mode in Firefox so that's a bit annoying. 😆

Maybe this needs to stay a three-character combo, just to be safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

If there's one clash in that namespace, there's likely to be more. Would be nice to find a maximum two-modifier namespace that can be used in WordPress.

I wonder if we can adopt one of https://en.wikipedia.org/wiki/Access_key...

Curiously enough it list Ctrl+Alt as reserved on Firefox on Mac for accesskey, so I wonder why it decided to use that.

I'm fine with just picking one non primary combination in this PR and revise it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

format: 'italic',
},
{
icon: 'editor-strikethrough',
title: __( 'Strikethrough' ),
shortcut: primaryAltShortcut( 'D' ),
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Arg, yes, thanks, I think all these code names have confused my brain. Sorry! 😓

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's why I think two is enough for now. :) #4411 (comment)

@tofumatt
Copy link
Member

tofumatt commented May 3, 2018

I kept the codes as they were before but added the keycode/shortcut text functions that work across platforms.

I tested the key combos here and they worked in Windows/Mac/Linux, Edge/Firefox/Chrome/Safari.

It would be nice to simplify the shortcuts but I don't think there are simpler ones we can use that won't cause an error somewhere. 😢

So I think this is ready to go 😄

const isMac = _isMacOS();

const alt = isMac ? '⌥' : 'Alt';
const meta = isMac ? '⌃' : '⊞';
Copy link
Member Author

Choose a reason for hiding this comment

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

Just to note: I know this is a common way to display shortcuts on the Mac, but my built-in keyboard doesn't have any of these symbols, so this always confuses me. 🙈

Copy link
Member

Choose a reason for hiding this comment

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

Huh, good point! Mine too; the only symbol is for Command, and this is a US keyboard:

img_0831

I just checked and it's not even standard on the Apple keyboards anymore. These symbols are cute and idiomatic for Mac users but they're not that helpful if you're new. Shall we just move them to strings instead?

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 don't mind keeping the command symbol since it's still on the keyboard (and I know that one), the rest I'm not so sure. I don't know how people make sense of the shortcuts shown on the Mac menus... :)

When I see or I just make a guess until I get what I want hahaha.

So... it's up to you. I just wanted to make a note here it may not make sense to some people.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if someone will try to press the caret key. :D

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I was about to file an issue and ask people what they think, but I say we eschew Mac conventions here for usability. I'll keep the command glyph but change the rest to text. 👍


export const ALT = 'alt';
export const CTRL = 'ctrl';
export const PRIMARY = 'mod';
Copy link
Member Author

Choose a reason for hiding this comment

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

Minor: should this become 'primary'? Not that it matters. :)

Copy link
Member

@tofumatt tofumatt May 4, 2018

Choose a reason for hiding this comment

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

So I noticed "mod" was actually used as the key code in https://github.com/WordPress/gutenberg/pull/4411/files#diff-cb4a97a77964e94dc29c6d9caf74f9ccL6... I figured it was good to internally keep it as "mod".

@ellatrix
Copy link
Member Author

ellatrix commented May 4, 2018

@tofumatt I can't approve my own PR (Github doesn't let me), but it looks good to me!

@tofumatt
Copy link
Member

tofumatt commented May 4, 2018

Fixed up @mcsf's issue and since @iseulde reviewed my additions I'd say we are good to go.

@tofumatt tofumatt merged commit c37a222 into master May 4, 2018
@tofumatt tofumatt deleted the add/editable-shortcuts branch May 4, 2018 21:34
@jasmussen
Copy link
Contributor

💥💥💥💥💥

isEditingLink: false,
settingsVisible: false,
opensInNewWindow: !! nextProps.formats.link && !! nextProps.formats.link.target,
newLinkValue: '',
} );
}

this.setState( {
isAddingLink: !! nextProps.formats.link && nextProps.formats.link.isAdding,
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is causing issues to the format toolbar. When the modal is renrendered (it can happen when you move the mouse over a block), it disappears if you just clicked the link button.

That's because isAddingLink is a state value controlled from within this component without changing the formats on the RichText component.

@@ -10,3 +20,117 @@ export const DOWN = 40;
export const DELETE = 46;

export const F10 = 121;

export const ALT = 'alt';
Copy link
Member

@aduth aduth Oct 17, 2018

Choose a reason for hiding this comment

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

Every other key exported in this module is its key code, yet for this and other modifiers we export a string? Even though Alt has a code (18)?

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 think this comes from @tofumatt.

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 believe it's used to pass to mousetrap and tinymce which wouldn't accept the codes?

Copy link
Member

Choose a reason for hiding this comment

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

Oops, I should have at least left a comment. I honestly forget at this point; it could have just been terrible newbie-ness. 😅

Copy link
Member

Choose a reason for hiding this comment

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

These are a public API of @wordpress/keycodes, which describes exports as:

Contains keycodes constants for keyboard keys like DOWN, UP, ENTER, etc.

https://www.npmjs.com/package/@wordpress/keycodes

Yet...

import * as keycodes from '@wordpress/keycodes';

keycodes.DOWN // 40 ✅
keycodes.UP // 38 ✅ 
keycodes.ENTER // 13 ✅ 
keycodes.ALT // 'alt' 😱 

@jcklpe
Copy link

jcklpe commented Dec 6, 2018

I'm having trouble finding documentation on what all the new keycodes are for Gutenberg. I know how to add a code tag, but how do I actually make a code block? I can make a heading just by using markdown. Same with bolding stuff or making an ul or ol but not sure how to get the code block?

@aduth
Copy link
Member

aduth commented Dec 6, 2018

@jcklpe A Code block can be added either using the inserter, or by key sequence using three tick (`) characters, then Enter. Inline code fragments can be made by typing "`", the code fragment, then a closing "`".

My understanding is that a user guide should become available shortly in the Gutenberg Handbook.

https://wordpress.org/gutenberg/handbook/

@jcklpe
Copy link

jcklpe commented Dec 6, 2018

@aduth Awesome! I tried doing ``` like on github but duh, should have tried just one. Thanks!

@ellatrix
Copy link
Member Author

ellatrix commented Dec 7, 2018

You should be able to insert a code block by typing ``` followed by pressing enter. Does this not work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet