-
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
Add new keyboard shortcuts help modal #8316
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
1da0ece
Create a simple modal for showing keyboard shortcuts that displays wh…
talldan a6a0061
Add more shortcuts and place them in sections with a title and descri…
talldan 7175829
Add styles for shortcut modal
talldan dbe8e48
Add missing shortctuts
talldan 634cccf
Remove unecessary shortcut section descriptions
talldan 374acbb
Display shortcut keys in a kbd element
talldan b611aa4
Styling changes
talldan 9c2e6c8
Regroup shortcuts
talldan be364fc
Fix invalid style rule
talldan a1c19c5
Change copy for slash inserter shortcut
talldan 22b776c
Map over config to produce ShortcutSections
talldan 9a92615
Change where keyboard shortcut help modal is rendered
talldan 6f8158a
Move keyboard-shortcut-help-modal to edit-post from editor package
talldan d2cdc0f
Add some border between rows in the keyboard shortcuts list
talldan 845e68a
Add reduxy things for opening and closing a modal
talldan acf1851
Use actions to open/close modal and selector to determine current state
talldan 542567b
Migrate the activeModal state from preferences to normal state so tha…
talldan 7384e36
Add a menu item tot he more menu for toggling keyboard shortcut help
talldan 5f9d83e
Modify some shortcuts and description text
talldan 09b655e
Add snapshot tests for help modal
talldan a08466e
Destructure props
talldan f7928bd
Modify header styling
talldan 8cd1a3d
Rename class name to reflect component is now in edit-post, and reord…
talldan 941771b
Display shortcut for more menu menu item
talldan 886f147
Disable WP_Help TinyMCE command for classic block
talldan 2f0bd3d
Change keyboard shortcut for triggering help to access + h, the same …
talldan bb9be30
Add utility to keycodes for returning key combinations in an array
talldan 282b3af
Avoid ugly regular expression to split key combination into array
talldan 79d4a58
Add e2e test for shortcut help modal
talldan cd508ba
Vertically center shortcut text (if adjacent label wraps onto multipl…
talldan 1e8c7b4
Close more menu when keyboard shortcuts modal is opened using the men…
talldan 2e5fdce
Use castArray over lengthy ternary
talldan 99ac0ca
Styling linter fixes
talldan 0fe9a1c
JSDoc fixes
talldan 223718b
Group activeModal unit tests in a describe
talldan f3c8056
Add test for initial activeModal state
talldan 6020c68
Fix incorrect state used in test
talldan 3374379
Update list of key shortcuts for the help modal
talldan d7aedc2
Remove unecessary return
talldan 52aa738
Make KeyboardShortcutsHelpMenuItem only open the help modal
talldan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
edit-post/components/header/keyboard-shortcuts-help-menu-item/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { withDispatch } from '@wordpress/data'; | ||
import { displayShortcut } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { MenuItem } from '@wordpress/components'; | ||
|
||
export function KeyboardShortcutsHelpMenuItem( { openModal, onSelect } ) { | ||
return ( | ||
<MenuItem | ||
onClick={ () => { | ||
onSelect(); | ||
openModal( 'edit-post/keyboard-shortcut-help' ); | ||
} } | ||
shortcut={ displayShortcut.access( 'h' ) } | ||
> | ||
{ __( 'Keyboard Shortcuts' ) } | ||
</MenuItem> | ||
); | ||
} | ||
|
||
export default withDispatch( ( dispatch, ) => { | ||
const { | ||
openModal, | ||
} = dispatch( 'core/edit-post' ); | ||
|
||
return { | ||
openModal, | ||
}; | ||
} )( KeyboardShortcutsHelpMenuItem ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
edit-post/components/keyboard-shortcut-help-modal/config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having this all in a |
||
* WordPress dependencies | ||
*/ | ||
import { displayShortcutList } from '@wordpress/keycodes'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const { | ||
// Cmd+<key> on a mac, Ctrl+<key> elsewhere | ||
primary, | ||
// Shift+Cmd+<key> on a mac, Ctrl+Shift+<key> elsewhere | ||
primaryShift, | ||
// Shift+Alt+Cmd+<key> on a mac, Ctrl+Shift+Akt+<key> elsewhere | ||
secondary, | ||
// Ctrl+Alt+<key> on a mac, Shift+Alt+<key> elsewhere | ||
access, | ||
ctrl, | ||
ctrlShift, | ||
shiftAlt, | ||
} = displayShortcutList; | ||
|
||
const globalShortcuts = { | ||
title: __( 'Global shortcuts' ), | ||
shortcuts: [ | ||
{ | ||
keyCombination: access( 'h' ), | ||
description: __( 'Display this help.' ), | ||
}, | ||
{ | ||
keyCombination: primary( 's' ), | ||
description: __( 'Save your changes.' ), | ||
}, | ||
{ | ||
keyCombination: primary( 'z' ), | ||
description: __( 'Undo your last changes.' ), | ||
}, | ||
{ | ||
keyCombination: primaryShift( 'z' ), | ||
description: __( 'Redo your last undo.' ), | ||
}, | ||
{ | ||
keyCombination: primaryShift( ',' ), | ||
description: __( 'Show or hide the settings sidebar.' ), | ||
}, | ||
{ | ||
keyCombination: ctrl( '`' ), | ||
description: __( 'Navigate to a the next part of the editor.' ), | ||
}, | ||
{ | ||
keyCombination: ctrlShift( '`' ), | ||
description: __( 'Navigate to the previous part of the editor.' ), | ||
}, | ||
{ | ||
keyCombination: shiftAlt( 'n' ), | ||
description: __( 'Navigate to a the next part of the editor (alternative).' ), | ||
}, | ||
{ | ||
keyCombination: shiftAlt( 'p' ), | ||
description: __( 'Navigate to the previous part of the editor (alternative).' ), | ||
}, | ||
{ | ||
keyCombination: secondary( 'm' ), | ||
description: __( 'Switch between Visual Editor and Code Editor.' ), | ||
}, | ||
], | ||
}; | ||
|
||
const selectionShortcuts = { | ||
title: __( 'Selection shortcuts' ), | ||
shortcuts: [ | ||
{ | ||
keyCombination: primary( 'a' ), | ||
description: __( 'Select all text when typing. Press again to select all blocks.' ), | ||
}, | ||
{ | ||
keyCombination: 'Esc', | ||
description: __( 'Clear selection.' ), | ||
}, | ||
], | ||
}; | ||
|
||
const blockShortcuts = { | ||
title: __( 'Block shortcuts' ), | ||
shortcuts: [ | ||
{ | ||
keyCombination: primaryShift( 'd' ), | ||
description: __( 'Duplicate the selected block(s).' ), | ||
}, | ||
{ | ||
keyCombination: '/', | ||
description: __( `Change the block type after adding a new paragraph.` ), | ||
}, | ||
], | ||
}; | ||
|
||
const textFormattingShortcuts = { | ||
title: __( 'Text formatting' ), | ||
shortcuts: [ | ||
{ | ||
keyCombination: primary( 'b' ), | ||
description: __( 'Make the selected text bold.' ), | ||
}, | ||
{ | ||
keyCombination: primary( 'i' ), | ||
description: __( 'Make the selected text italic.' ), | ||
}, | ||
{ | ||
keyCombination: primary( 'u' ), | ||
description: __( 'Underline the selected text.' ), | ||
}, | ||
{ | ||
keyCombination: primary( 'k' ), | ||
description: __( 'Convert the selected text into a link.' ), | ||
}, | ||
{ | ||
keyCombination: access( 's' ), | ||
description: __( 'Remove a link.' ), | ||
}, | ||
{ | ||
keyCombination: access( 'd' ), | ||
description: __( 'Add a strikethrough to the selected text.' ), | ||
}, | ||
{ | ||
keyCombination: access( 'x' ), | ||
description: __( 'Display the selected text in a monospaced font.' ), | ||
}, | ||
], | ||
}; | ||
|
||
export default [ | ||
globalShortcuts, | ||
selectionShortcuts, | ||
blockShortcuts, | ||
textFormattingShortcuts, | ||
]; |
119 changes: 119 additions & 0 deletions
119
edit-post/components/keyboard-shortcut-help-modal/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { castArray } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { Modal, KeyboardShortcuts } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { rawShortcut } from '@wordpress/keycodes'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { compose } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import shortcutConfig from './config'; | ||
import './style.scss'; | ||
|
||
const MODAL_NAME = 'edit-post/keyboard-shortcut-help'; | ||
|
||
const mapKeyCombination = ( keyCombination ) => keyCombination.map( ( character, index ) => { | ||
if ( character === '+' ) { | ||
return ( | ||
<Fragment key={ index }> | ||
{ character } | ||
</Fragment> | ||
); | ||
} | ||
|
||
return ( | ||
<kbd | ||
key={ index } | ||
className="edit-post-keyboard-shortcut-help__shortcut-key" | ||
> | ||
{ character } | ||
</kbd> | ||
); | ||
} ); | ||
|
||
const ShortcutList = ( { shortcuts } ) => ( | ||
<dl className="edit-post-keyboard-shortcut-help__shortcut-list"> | ||
{ shortcuts.map( ( { keyCombination, description }, index ) => ( | ||
<div | ||
className="edit-post-keyboard-shortcut-help__shortcut" | ||
key={ index } | ||
> | ||
<dt className="edit-post-keyboard-shortcut-help__shortcut-term"> | ||
<kbd className="edit-post-keyboard-shortcut-help__shortcut-key-combination"> | ||
{ mapKeyCombination( castArray( keyCombination ) ) } | ||
</kbd> | ||
</dt> | ||
<dd className="edit-post-keyboard-shortcut-help__shortcut-description"> | ||
{ description } | ||
</dd> | ||
</div> | ||
) ) } | ||
</dl> | ||
); | ||
|
||
const ShortcutSection = ( { title, shortcuts } ) => ( | ||
<section className="edit-post-keyboard-shortcut-help__section"> | ||
<h2 className="edit-post-keyboard-shortcut-help__section-title"> | ||
{ title } | ||
</h2> | ||
<ShortcutList shortcuts={ shortcuts } /> | ||
</section> | ||
); | ||
|
||
export function KeyboardShortcutHelpModal( { isModalActive, toggleModal } ) { | ||
const title = ( | ||
<span className="edit-post-keyboard-shortcut-help__title"> | ||
{ __( 'Keyboard Shortcuts' ) } | ||
</span> | ||
); | ||
|
||
return ( | ||
<Fragment> | ||
<KeyboardShortcuts | ||
bindGlobal | ||
shortcuts={ { | ||
[ rawShortcut.access( 'h' ) ]: toggleModal, | ||
} } | ||
/> | ||
{ isModalActive && ( | ||
<Modal | ||
className="edit-post-keyboard-shortcut-help" | ||
title={ title } | ||
closeLabel={ __( 'Close' ) } | ||
onRequestClose={ toggleModal } | ||
> | ||
|
||
{ shortcutConfig.map( ( config, index ) => ( | ||
<ShortcutSection key={ index } { ...config } /> | ||
) ) } | ||
|
||
</Modal> | ||
) } | ||
</Fragment> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => ( { | ||
isModalActive: select( 'core/edit-post' ).isModalActive( MODAL_NAME ), | ||
} ) ), | ||
withDispatch( ( dispatch, { isModalActive } ) => { | ||
const { | ||
openModal, | ||
closeModal, | ||
} = dispatch( 'core/edit-post' ); | ||
|
||
return { | ||
toggleModal: () => isModalActive ? closeModal() : openModal( MODAL_NAME ), | ||
}; | ||
} ), | ||
] )( KeyboardShortcutHelpModal ); |
56 changes: 56 additions & 0 deletions
56
edit-post/components/keyboard-shortcut-help-modal/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.edit-post-keyboard-shortcut-help { | ||
&__title { | ||
font-size: 1rem; | ||
font-weight: bold; | ||
} | ||
|
||
&__section { | ||
margin: 0 0 2rem 0; | ||
} | ||
|
||
|
||
&__section-title { | ||
font-size: 0.9rem; | ||
font-weight: bold; | ||
} | ||
|
||
&__shortcut { | ||
display: flex; | ||
align-items: center; | ||
padding: 0.6rem 0; | ||
border-top: 1px solid $light-gray-500; | ||
|
||
&:last-child { | ||
border-bottom: 1px solid $light-gray-500; | ||
} | ||
} | ||
|
||
&__shortcut-term { | ||
flex: 1; | ||
order: 1; | ||
text-align: right; | ||
font-weight: bold; | ||
margin: 0 0 0 1rem; | ||
} | ||
|
||
&__shortcut-description { | ||
order: 0; | ||
margin: 0; | ||
} | ||
|
||
&__shortcut-key-combination { | ||
background: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
&__shortcut-key { | ||
padding: 0.25rem 0.5rem; | ||
border-radius: 8%; | ||
margin: 0 0.2rem 0 0.2rem; | ||
|
||
&:last-child { | ||
margin: 0 0 0 0.2rem; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wondering if
editor.shortcuts.remove( 'ctrl+alt+h' )
might be a nicer way of doing this? Not sure.https://www.tiny.cloud/docs/api/tinymce/tinymce.shortcuts/
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.
Doesn't seem to work unfortunately. I also thought
editor.editorCommands.addCommand( 'WP_Help', noop )
might also work but it doesn't. It suggests a race condition - that the WP_Help command is added after freeform block's setupEditor runs.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.
Does what we're doing in RichText help?
gutenberg/packages/editor/src/components/rich-text/index.js
Line 169 in 4a78cae
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.
Sadly not. Guessing it works there because Redo is already bound by TinyMCE at this point.