-
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
Try: Add toggle editor mode shortcut #3755
Try: Add toggle editor mode shortcut #3755
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3755 +/- ##
==========================================
- Coverage 39.08% 38.97% -0.12%
==========================================
Files 290 292 +2
Lines 6967 6987 +20
Branches 1273 1280 +7
==========================================
Hits 2723 2723
- Misses 3570 3583 +13
- Partials 674 681 +7
Continue to review full report at Codecov.
|
Thanks for the PR, it's a good one, I can't speak for the chosen shortcut but it makes sense to me. Also, I recall mockups showing these shortcuts next to the button in the ellipsis menu for discoverability (cc @jasmussen). |
@@ -0,0 +1,54 @@ | |||
/** |
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.
The editor/components
folder is only for reusable editor components without "layout" information. I think the "mode" is a layout information because it only indicates which mode is "visible". Can we move this component to the editor/edit-post
folder instead?
@youknowriad Thanks. I moved the code to edit-post/modes/keyboard-shortcuts, will that work? |
I'd agree it wouldn't make much sense since tehre are 2 separate controls: Hm the only way I can think of is merging the two controls in just one "dynamic" control:
However, I've heard some discussions about allowing plugins to add additional "modes" so I'm not sure the current UI would be so ideal in the first place. |
@afercia @vladanost @jasmussen We could show it next to the "Editor" label, can't we? |
It's true that the editor mode switch was designed to be able to scale to more types, but probably this shouldn't keep us from making improvements right now. It seems the feedback centers around having a single keyboard shortcut that would cycle between modes. So you'd invoke the shortcut to go to HTML mode, and the same shorcut would take you back. Combined with #2980, we'd want to show that keyboard shortcut in the menu, right aligned. Given the ellipsis menu for selecting the editing mode right now behaves like a radio group, it feels weird to show the same shortcut next to both items, even one that is active and unselectable. So can we just show the shortcut next to the item that's not selected? I.e. this:
and subsequently ...
Would that work? It seems like the obvious thing to try. The next step would be to make the item dynamic, like Andrea suggests. |
@youknowriad @jasmussen @afercia I tried to display the shortcuts by adding MenuItemsShortcut component. |
Really nice work. That looks good. I'd remove the [] brackets, those were just for the ASCII mockup ;) — so long as the shortcut is right aligned. In the future we might need to either change the font size and/or dropdown width, to make room for long shortcuts. But nothing to worry about in this PR. Very nice work. |
Really nice. A few questions/considerations:
On a white background, the lightest gray that can be used is
Yep, I think at some point all the shortcuts would need a final review to check for potential conflicts, I guess we can keep it as is for now! |
components/keyboard-shortcuts/map.js
Outdated
@@ -0,0 +1,3 @@ | |||
export default { | |||
toggle_editor_mode: '⌘+Shift+Alt+M', |
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 a good idea to keep "editor"'s specific shortcuts in a generic components
module? why can't we avoid this map entirely and just pass the shortcut?
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.
Yes, I can change it to use the shortcut directly. My thinking was to have a separate list in case it should be used elsewhere (like complete list of 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.
Fair enough! let's move the list to the editor/edit-post
folder then and retrieve passing the mapped value directly to the generic component.
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.
Maybe this map could also hold the actual value used to trigger the shortcut mod+shift+alt+m
. So we'll have a value
and a label
per shortcut.
@@ -31,10 +31,17 @@ const MODES = [ | |||
]; | |||
|
|||
function ModeSwitcher( { onSwitch, mode } ) { | |||
const filteredModes = MODES.map( MODE => { |
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.
Shoud we use mode
instead of MODE
? It's not a module's constant.
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.
Right. I will change it to lower case. I used uppercase to differentiate it from mode that is passed as argument.
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.
mmm right, maybe choice
or something else :)
@@ -0,0 +1,6 @@ | |||
export default { |
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.
Thanks for the changes 👍
If this map is supposed to grow over time and contain all edit-post shortcuts, should we move it to editor/edito-post/keyboard-shortcuts.js
instead?
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.
Yea, probably :) I was confused, since I already have modes/keyboard-shortcuts
folder and didn't want to create clutter. I will move them there.
@@ -0,0 +1,6 @@ | |||
export default { | |||
toggle_editor_mode: { |
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.
What if instead of exporting an object, we export several constants. This one could be
const TOGGLE_EDITOR_MODE = { label, value }
?
Alternatively, we should use camelCase for keys to be able to reference them like this shortcuts.toggleEditorMode.label
.
render() { | ||
return ( | ||
<KeyboardShortcuts shortcuts={ { | ||
'mod+shift+alt+m': this.toggleMode, |
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.
Should we use the newly introduce shortcut value
here
export default { | ||
toggleEditorMode: { | ||
value: 'mod+shift+alt+m', | ||
label: '⌘+Shift+Alt+M', |
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 ⌘
with ctrl
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 :)
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.
LGTM 👍 Can you rebase your PR?
return { | ||
switchMode: ( mode ) => { | ||
dispatch( { | ||
type: 'SWITCH_MODE', mode: mode, |
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: We could extract the SWITCH_MODE
action into an action creator in editor/store/actions.js
to factorize its usage.
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.
Also, you can replace mode: mode
here by just mode
Also, I'm not able to merge can you rebase? |
a5a1d98
to
79ebbfd
Compare
79ebbfd
to
1642d28
Compare
@@ -0,0 +1,54 @@ | |||
/** |
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.
While I'd like for us to flatten and eliminate the modes
directory altogether, I don't particularly like the creation of a new folder here, because as it was prior to these changes, the modes
directory contains exclusively the supported editing modes for the editor: visual and text. The shortcuts are not in themselves a mode.
I was wondering if we could change this shortcut to fit in with the rest of WP and this editor. We have chosen Ctrl+Alt (Mac) and Shift+Alt (Windows) in the past because it can be entirely used by us without running into issues with browsers and operating systems. Also known as the access combination (we even got TinyMCE to move to that). Could we figure out a good combination for the mode switcher in this space? Any reason I think we should also build the API around that, so plugins can also only extend in this combination space. Additionally, I can't figure out how to get the combination to work in master (Mac). |
Hi @iseulde |
@vladanost It only seems to work if the pop up is open. If it's closed, it doesn't. |
@iseulde On Linux, it works regardless of the popup being open. I will make a test later today on Mac. (I remember it worked there too) |
Sound good. |
@iseulde It works for me on Mac too. |
Description
I find switching often from Visual to Code editor mode tiring process so I wanted to add a shortcut for that.
All editor related keyboard shortcuts are grouped under EditorGlobalKeyboardShortcuts which is a great move but for this case it causes problems. EditorGlobalKeyboardShortcuts is rendered from VisualEditor block and if I add the shortcut there, once it switches to TextEditor, shortcuts are no longer available.
My temp approach is to add another component EditorModeKeyboardShortcuts and render it from Layout component.
For the moment it works but I'm wondering:
All suggestions are welcome. Thanks.
How Has This Been Tested?
npm run test-unit
Manually tested in the browser.
Types of changes
New feature (non-breaking change which adds functionality)