-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try: Add toggle editor mode shortcut #3755
Changes from all commits
2b5cac6
dfb2f2e
953d072
769a2c2
ddcb3b1
2d472af
ed153fe
a4ea260
e64a4c5
ece8fa5
3d5f255
a949fb8
ec1e3dc
a605451
1e8eac6
ebe176f
61b2fc6
22cb50a
97d8a0e
cb564dd
1800042
08650fe
1642d28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function MenuItemsShortcut( { shortcut } ) { | ||
if ( ! shortcut ) { | ||
return null; | ||
} | ||
return ( | ||
<span style={ { float: 'right', opacity: .5 } }>{ shortcut }</span> | ||
); | ||
} | ||
|
||
export default MenuItemsShortcut; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
toggleEditorMode: { | ||
value: 'mod+shift+alt+m', | ||
label: '⌘+Shift+Alt+M', | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
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. While I'd like for us to flatten and eliminate the |
||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { KeyboardShortcuts } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import shortcuts from '../../keyboard-shortcuts'; | ||
import { getEditorMode } from '../../../store/selectors'; | ||
import { switchEditorMode } from '../../../store/actions'; | ||
|
||
class EditorModeKeyboardShortcuts extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.toggleMode = this.toggleMode.bind( this ); | ||
} | ||
|
||
toggleMode() { | ||
const { mode, switchMode } = this.props; | ||
switchMode( mode === 'visual' ? 'text' : 'visual' ); | ||
} | ||
|
||
render() { | ||
return ( | ||
<KeyboardShortcuts shortcuts={ { | ||
[ shortcuts.toggleEditorMode.value ]: this.toggleMode, | ||
} } /> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
( state ) => { | ||
return { | ||
mode: getEditorMode( state ), | ||
}; | ||
}, | ||
( dispatch ) => { | ||
return { | ||
switchMode: ( mode ) => { | ||
dispatch( switchEditorMode( mode ) ); | ||
}, | ||
}; | ||
}, | ||
|
||
)( EditorModeKeyboardShortcuts ); |
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.
Minor: I wonder if we should detect the platform and replace
⌘
withctrl
if not on MacOS.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.
Is it reliable to use navigator.platform? I can't find any example in the Gutenberg code.
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 it is but that's the first time we need it :)