-
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
RichText: add non breaking space shortcut on Windows #43150
Conversation
Size Change: +173 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
} | ||
|
||
// Shift + Ctrl + Space shortcut is built in on the Mac. | ||
if ( isAppleOS() ) { |
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 it hurt to override the 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.
I deleted it, but I don't have a Mac, could you test it?
|
||
return ( | ||
<RichTextShortcut | ||
type="primaryShift" |
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.
Btw, the original issue had a typo. It should be Shift+Alt+Space. But apparently Alt+Space also works so we could simplify it to just Alt+Space?
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.
As shown in this source, Alt+Space
is often used to access the menu of the program itself.
For example, in Chrome, it would appear as follows (this was also the case in FireFox and Edge):
Shift+Alt+Space
also showed the same behavior.
If we override this shortcut, we will not be able to access the browser menu unless we remove focus from RichText.
I recommend Ctrl+Shift+Space
, which is a continuation of the Microsoft Word 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.
Shift+Alt+Space
has the same behaviour? I think it's fine to override the Shift combination then.
I think we should stick to an Alt combination because Alt indicates an alternative for the current key/character. I think this is the same for Windows? Alt combinations input different characters, whereas Ctrl is more for commands/controls.
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 we should stick to an Alt combination because Alt indicates an alternative for the current key/character. I think this is the same for Windows? Alt combinations input different characters, whereas Ctrl is more for commands/controls.
Yes, that is correct.
But unfortunately, Alt+Space
(Alt+Shift+Space
) didn't respond to triggering RichtextShortcut
, and the browser menu opens.
From my research here, it appears that Alt + Space
is not a browser shortcut, but is implemented at the OS level.
Alt + Spacebar | Open the shortcut menu for the active window.
Then, possible patterns and possibilities are as follows.
- ✅
Ctrl + Shift + Space
: Confirmed to work correctly - ✅
Ctrl + Space
: Confirmed to work correctly - ❗
Shift + Space
: Switch character width between full-width and half-width. (OS shortcut) - ❗
Ctrl + Space
: Turn the Chinese input method editor (IME) on or off. (OS shortcut)
package-lock.json
Outdated
@@ -17435,6 +17435,7 @@ | |||
"@wordpress/html-entities": "file:packages/html-entities", | |||
"@wordpress/i18n": "file:packages/i18n", | |||
"@wordpress/icons": "file:packages/icons", | |||
"@wordpress/keycodes": "file:packages/keycodes", |
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.
This needs to be removed.
Ignore this message. Testing if this subscribes me in the mentioned notifications. @ellatrix |
@@ -46,4 +46,8 @@ export const textFormattingShortcuts = [ | |||
'Convert the current paragraph or heading to a heading of level 1 to 6.' | |||
), | |||
}, | |||
{ | |||
keyCombination: { modifier: 'primaryShift', character: 'SPACE' }, |
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.
Can we use a literal space here as you did below for the rich text 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.
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.
Ah, this is for displaying the shortcut? Sorry it wasn't clear from the code.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @rezeau, @pierrefrance, @burnuser, @zackkatz. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
name, | ||
title, | ||
tagName: 'span', | ||
className: 'nbsp', |
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.
This could cause existing span tags with this class to be wrongly processed as this format. I wonder if we could set the tagName to nbsp
to work around the rules. 🤔
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.
Even if I changed the tagName
to nbsp
, it worked fine! Does tagName
not have to be an element that is allowed as HTML?
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.
Not if we're not going to use 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.
Let's do it
Unlinked contributors: rezeau, pierrefrance, burnuser, zackkatz. Co-authored-by: t-hamano <[email protected]> Co-authored-by: ellatrix <[email protected]> Co-authored-by: yankiara <[email protected]> Co-authored-by: tybor <[email protected]> Co-authored-by: fr-laurentn <[email protected]> Co-authored-by: TonyGravagno <[email protected]> Co-authored-by: noisysocks <[email protected]> Co-authored-by: benjaminpwarren <[email protected]>
Fix: #18523
What?
This PR adds non-breaking space shortcut (Ctrl + Shift Space) for Windows.
Why?
As seen in the source here, this shortcut is well known in Word and its compatibility software and should be introduced in Gutenberg as well.
How?
I added a format type (
core/non-breaking-space
) and appliedRichTextShortcut
in it. This shortcut is built-in on Mac and valid only on Windows.However, this shortcut is not for formatting. It might not be necessary to add a format type, but
RichTextShortcut
is used in only format types or blocks, and I couldn't find a way to implement it directly into RichText.At the same time, I added it to the keyboard shortcut modal. I think this should be no problem to display without limiting the OS.
Testing Instructions
Press
Ctrl+Shift+Space
in rich text.This behavior follows the behavior of Microsoft Word.
Screenshots or screencast
bdad4fc264ebf129bf30d4e8f42f849e.mp4