-
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
Changes from 9 commits
2b459da
79e8afd
0d9d4ee
2697e83
824462a
a7c1a47
1075635
c16b857
bab769d
dd6cca7
758ceb6
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,29 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { insert } from '@wordpress/rich-text'; | ||
import { RichTextShortcut } from '@wordpress/block-editor'; | ||
|
||
const name = 'core/non-breaking-space'; | ||
const title = __( 'Non breaking space' ); | ||
|
||
export const nonBreakingSpace = { | ||
name, | ||
title, | ||
tagName: 'span', | ||
ellatrix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
className: 'nbsp', | ||
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. 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 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. Even if I changed the 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. Not if we're not going to use it 😄 |
||
edit( { value, onChange } ) { | ||
function addNonBreakingSpace() { | ||
onChange( insert( value, '\u00a0' ) ); | ||
} | ||
|
||
return ( | ||
<RichTextShortcut | ||
type="primaryShift" | ||
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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. As shown in this source, For example, in Chrome, it would appear as follows (this was also the case in FireFox and Edge):
If we override this shortcut, we will not be able to access the browser menu unless we remove focus from RichText. 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.
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, that is correct. From my research here, it appears that
Then, possible patterns and possibilities are as follows.
|
||
character=" " | ||
onUse={ addNonBreakingSpace } | ||
/> | ||
); | ||
}, | ||
}; |
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.
Do you mean to use
\u00a0
instead ofSPACE
? In that case, the shortcut modal will display as below.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.