gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Keyboard shortcuts support

Open jasmussen opened this issue 9 years ago • 44 comments

For accessibility and power-users both, we should always think about keyboard support. This was first brought up in #61, but deserves being fleshed out more.

The editor already has keyboard support for most formatting controls, including the "Paragraph" type switcher, which we are pondering moving to the side. Though since this will likely expand a fair bit beyond paragraphs, headings and preformatted, maybe that needs love too.

Many of these are existing keyboard shortcuts that should probably stay intact for back compat.

Inline formatting:

  • [x] Bold ⌘B
  • [x] Italic ⌘I
  • [x] Link/edit link ⌘K (or paste around selected text) Being handled in #4411.
  • [x] Unlink ^⌥S Being handled in #4411.
  • [x] Strikethrough ^⌥D Being handled in #4411.
  • [x] Change heading size ^⌥↑ for increase, ^⌥↓ for decrease See https://github.com/WordPress/gutenberg/issues/71#issuecomment-357252369.

Hidden (?) controls:

  • [x] Undo ⌘Z
  • [x] Redo ⌘Y
  • [x] Cut ⌘X
  • [x] Copy ⌘C
  • [x] Paste ⌘V
  • [x] Select All ⌘A See #4369 now.
  • [x] Keyboard shortcuts cheat sheet — currently ^⌥H, should it instead/also be Shift ?
  • [x] Underline ⌘U
  • [x] Code ^⌥X Being handled in #4411.
  • [ ] Align center ^⌥C
  • [ ] Align left ^⌥L
  • [ ] Align right ^⌥R
  • [ ] Justify ^⌥J
  • [ ] Bullets ^⌥U
  • [ ] Ordered list ^⌥O
  • [x] Remove link ^⌥S Being handled in #4411.
  • [ ] ⌘+ENTER (Ctrl+Enter for Windows) to create a separator

Markdown-esque shortcuts/syntactic sugar:

  • [x] Code: wrap text in backticks, `
  • [x] Bullets: * or - on newline
  • [x] Ordered list: 1. or 1) on newline
  • [x] Blockquote: > on newline
  • [x] H2-H6: ## - ###### on newline
  • [ ] Horizontal line: --- on newline

Insertion/block level controls:

  • [ ] Insert block: ^⌥M (for fallback) and / on newline (see #24)
  • [ ] Move block up ^⌥↑
  • [ ] Move block down ^⌥↓
  • [ ] Open block type switcher ⌘~ then ↑/↓ and Enter for select
  • [ ] Toggle between block types ~

Inserter:

  • [ ] Invoked where the cursor is, by typing / on newline or pressing ^⌥M, then ↑/↓ and Enter for select

jasmussen avatar Feb 15 '17 08:02 jasmussen

These two:

  • [ ] Open block type switcher ⌘~ then ↑/↓ and Enter for select
  • [ ] Toggle between block types ~

probably need the most discussion, as getting these right can potentially make for a killer feeling while writing.

Imagine this: type type type, churn out a blogpost, / on a newline, arrow down to image, enter, pick image with arrowkeys, enter to insert, write another line, press ~ twice to instantly switch it through heading and then to blockquote. Done.

In this situation, simply pressing ~ while inside a block switches it to the next compatible blocktype, so a paragraph would cycle over heading then to quote, whereas a gallery might cycle between gallery types. ⌘~ would actually open the switcher list so you could see the compatible blocktypes and pick one using arrowkeys.

Quip has this shortcut, worth trying out. But they use backtick `, which we are using in a markdown-esque way for code.

Important also to think of international keyboards. On US keyboards, the ~ character is in the top left, which makes it a sweet deal, easily accessible, whereas euro keyboards put the tilde under ⌥^, which is a fair bit more cumbersome. Any other ideas?

jasmussen avatar Feb 15 '17 09:02 jasmussen

This one also deserves lots of thought:

  • [ ] Change heading size ^⌥↑ for increase, ^⌥↓ for decrease

For context, these shortcuts assume that a "Heading" is a single block type, and the heading size is a block-level property of that style. Mockup:

headings

👆 Note, that mockup has a different style of block level controls than the UI prototype currently has.

So the flow would be:

  • write text
  • press ~ to switch to next compatible block type, i.e. Heading — this would convert the paragraph to a h1 (or h2?)
  • press ^⌥↓ to convert the h1 to a h2

jasmussen avatar Feb 15 '17 09:02 jasmussen

Worth reminding some of these keys are not available on all the keyboard layout, for example ~.

afercia avatar Apr 29 '17 14:04 afercia

I can look into part of this together with the other text shortcuts, and where it touches Editable.

ellatrix avatar May 22 '17 09:05 ellatrix

I think it would be nice to include keyboard shortcuts for the most used blocks. As it would be a quicker way to add the blocks one use over and over again. Perhaps even have a mention of the shortcut beside the most used blocks similar to various program list shortcuts.

paaljoachim avatar Jun 24 '17 19:06 paaljoachim

I've been thinking about the benefits of being able to write an article completely from the keyboard, without using a mouse. This has serious benefits for accessibility as well as for staying in the flow (kind of like when using Markdown and you can just keep writing while adding in quick formatting)

The ideal flow here could go like:

  • Start typing a few paragraphs
  • Type shortcut to open picker
  • Start typing “qu…” and have the quote block pop into view on the inserter and be highlighted as the number one result (https://github.com/WordPress/gutenberg/issues/1064)
  • Press return/enter on the keyboard and have the block insert into the editor
  • Write your quote
  • Press tab
  • Write your citation
  • Press enter twice
  • Continue typing

jwold avatar Jul 07 '17 19:07 jwold

Love those thoughts, @jwold, so much so that it was planned for a long time to use /, like Slack and IRC, to invoke a searchable block selector dialog. See https://github.com/WordPress/gutenberg/issues/323#issuecomment-297750766 for full mockups.

This is a feature I'd like to resurface, but we've punted for now as it isn't critical to V1.

jasmussen avatar Jul 08 '17 09:07 jasmussen

Awesome! Would love to have this revisited in the future. Agreed that it isn't needed for a V1 launch though.

jwold avatar Jul 09 '17 14:07 jwold

One keyboard shortcut request:

  • [ ] ⌘/ctrl + s to save changes.

It works fine with the existing editor and I miss it on Gutenberg.

nicolinuxfr avatar Jul 25 '17 08:07 nicolinuxfr

  • Link/edit link ⌘K (or paste around selected text)

Yes please, this is something that I miss from the old editor.

JDGrimes avatar Sep 28 '17 15:09 JDGrimes

@jasmussen What is left here? :) I'll go through your list and erase items that have been done.

ellatrix avatar Jan 10 '18 15:01 ellatrix

Also, what does ^ and ⌥ mean?

ellatrix avatar Jan 10 '18 15:01 ellatrix

Mac shortcuts for control and option/alt, respectively.

nicolinuxfr avatar Jan 10 '18 15:01 nicolinuxfr

On my keyboard, option and alt are the some buttons. Also, from googling its seems ⌥ is option?

ellatrix avatar Jan 10 '18 15:01 ellatrix

Yeah I think I meant ^ to mean Ctrl (the Mac version).

jasmussen avatar Jan 10 '18 15:01 jasmussen

Also, I'll go through this list tomorrow! Thank you!

jasmussen avatar Jan 10 '18 15:01 jasmussen

For some of these, it might be best to follow hat core does now (different for Mac and windows): https://github.com/WordPress/wordpress-develop/blob/186f963c34e64aba15294e1416a598533809ba21/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js#L235

ellatrix avatar Jan 10 '18 15:01 ellatrix

@iseulde

What is left here? :) I'll go through your list and erase items that have been done.

Wow, amazing progress. This is coming together!

Wanted to add notes on these:

Insertion/block level controls: Insert block: ^⌥M (for fallback) and / on newline (see #24) Move block up ^⌥ Move block down ^⌥ Open block type switcher ⌘~ then ↑/↓ and Enter for select Toggle between block types ~

Inserter Invoked where the cursor is, by typing / on newline or pressing ^⌥M, then ↑/↓ and Enter for select

These are suggestions, and they are so old now that they might very well not be relevant anymore. It's totally fine in implementation to decide that a different shortcut makes more sense.

For example, I think ⌘+Shift+↑/↓ might be better for moving blocks:

screen shot 2018-01-11 at 09 15 42

jasmussen avatar Jan 11 '18 08:01 jasmussen

Just to note that some of the keys suggested here are not available on some non-English keyboard layouts. For example, there's no tilde character in many keyboard layouts:

Open block type switcher ⌘~ then ↑/↓ and Enter for select Toggle between block types ~

These won't work universally. Considering also #3218 I'd tend to think the only way to make shortcuts available to all users, is to make them configurable.

afercia avatar Jan 11 '18 09:01 afercia

Agree with Andrea, that particular shortcut might need to be rethought, and keeping past shortcuts in mind (in the case of the block switcher, the inspiration is the paragraph dropdown).

jasmussen avatar Jan 11 '18 10:01 jasmussen