From 2b459da973f4c9463350549a9885b0af55a7ee82 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Thu, 11 Aug 2022 12:27:59 +0900 Subject: [PATCH 1/9] RichText: add non breaking space shortcut on Windows --- .../keyboard-shortcut-help-modal/config.js | 4 +++ .../keyboard-shortcut-help-modal/config.js | 4 +++ .../test/__snapshots__/index.js.snap | 7 ++++ .../keyboard-shortcut-help-modal/config.js | 4 +++ .../keyboard-shortcut-help-modal/config.js | 4 +++ packages/format-library/package.json | 1 + .../format-library/src/default-formats.js | 2 ++ .../src/non-breaking-space/index.js | 35 +++++++++++++++++++ 8 files changed, 61 insertions(+) create mode 100644 packages/format-library/src/non-breaking-space/index.js diff --git a/packages/customize-widgets/src/components/keyboard-shortcut-help-modal/config.js b/packages/customize-widgets/src/components/keyboard-shortcut-help-modal/config.js index 7e098a87be2cd9..7c18763d508ab9 100644 --- a/packages/customize-widgets/src/components/keyboard-shortcut-help-modal/config.js +++ b/packages/customize-widgets/src/components/keyboard-shortcut-help-modal/config.js @@ -36,4 +36,8 @@ export const textFormattingShortcuts = [ keyCombination: { modifier: 'access', character: 'x' }, description: __( 'Make the selected text inline code.' ), }, + { + keyCombination: { modifier: 'primaryShift', character: 'SPACE' }, + description: __( 'Add non breaking space.' ), + }, ]; diff --git a/packages/edit-post/src/components/keyboard-shortcut-help-modal/config.js b/packages/edit-post/src/components/keyboard-shortcut-help-modal/config.js index 7e098a87be2cd9..7c18763d508ab9 100644 --- a/packages/edit-post/src/components/keyboard-shortcut-help-modal/config.js +++ b/packages/edit-post/src/components/keyboard-shortcut-help-modal/config.js @@ -36,4 +36,8 @@ export const textFormattingShortcuts = [ keyCombination: { modifier: 'access', character: 'x' }, description: __( 'Make the selected text inline code.' ), }, + { + keyCombination: { modifier: 'primaryShift', character: 'SPACE' }, + description: __( 'Add non breaking space.' ), + }, ]; diff --git a/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap b/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap index 0353a76f1ec663..1fdfc1cc75f49d 100644 --- a/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +++ b/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap @@ -96,6 +96,13 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ "modifier": "access", }, }, + Object { + "description": "Make the selected text inline code.", + "keyCombination": Object { + "character": "space", + "modifier": "primaryShift", + }, + }, ] } title="Text formatting" diff --git a/packages/edit-site/src/components/keyboard-shortcut-help-modal/config.js b/packages/edit-site/src/components/keyboard-shortcut-help-modal/config.js index 7e098a87be2cd9..7c18763d508ab9 100644 --- a/packages/edit-site/src/components/keyboard-shortcut-help-modal/config.js +++ b/packages/edit-site/src/components/keyboard-shortcut-help-modal/config.js @@ -36,4 +36,8 @@ export const textFormattingShortcuts = [ keyCombination: { modifier: 'access', character: 'x' }, description: __( 'Make the selected text inline code.' ), }, + { + keyCombination: { modifier: 'primaryShift', character: 'SPACE' }, + description: __( 'Add non breaking space.' ), + }, ]; diff --git a/packages/edit-widgets/src/components/keyboard-shortcut-help-modal/config.js b/packages/edit-widgets/src/components/keyboard-shortcut-help-modal/config.js index 7e098a87be2cd9..7c18763d508ab9 100644 --- a/packages/edit-widgets/src/components/keyboard-shortcut-help-modal/config.js +++ b/packages/edit-widgets/src/components/keyboard-shortcut-help-modal/config.js @@ -36,4 +36,8 @@ export const textFormattingShortcuts = [ keyCombination: { modifier: 'access', character: 'x' }, description: __( 'Make the selected text inline code.' ), }, + { + keyCombination: { modifier: 'primaryShift', character: 'SPACE' }, + description: __( 'Add non breaking space.' ), + }, ]; diff --git a/packages/format-library/package.json b/packages/format-library/package.json index 3e7324a7826cf5..ac68c1eab6af24 100644 --- a/packages/format-library/package.json +++ b/packages/format-library/package.json @@ -35,6 +35,7 @@ "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", + "@wordpress/keycodes": "file:../keycodes", "@wordpress/rich-text": "file:../rich-text", "@wordpress/url": "file:../url", "lodash": "^4.17.21" diff --git a/packages/format-library/src/default-formats.js b/packages/format-library/src/default-formats.js index 412ae23f4b686d..bc6d097e62fce4 100644 --- a/packages/format-library/src/default-formats.js +++ b/packages/format-library/src/default-formats.js @@ -12,6 +12,7 @@ import { textColor } from './text-color'; import { subscript } from './subscript'; import { superscript } from './superscript'; import { keyboard } from './keyboard'; +import { nonBreakingSpace } from './non-breaking-space'; export default [ bold, @@ -25,4 +26,5 @@ export default [ subscript, superscript, keyboard, + nonBreakingSpace, ]; diff --git a/packages/format-library/src/non-breaking-space/index.js b/packages/format-library/src/non-breaking-space/index.js new file mode 100644 index 00000000000000..e7a8512103a7d1 --- /dev/null +++ b/packages/format-library/src/non-breaking-space/index.js @@ -0,0 +1,35 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { insert } from '@wordpress/rich-text'; +import { RichTextShortcut } from '@wordpress/block-editor'; +import { isAppleOS } from '@wordpress/keycodes'; + +const name = 'core/non-breaking-space'; +const title = __( 'Non breaking space' ); + +export const nonBreakingSpace = { + name, + title, + tagName: 'span', + className: 'nbsp', + edit( { value, onChange } ) { + function addSpace() { + onChange( insert( value, ' ' ) ); + } + + // Shift + Ctrl + Space shortcut is built in on the Mac. + if ( isAppleOS() ) { + return; + } + + return ( + + ); + }, +}; From 79e8afd6f0796291a6c09f177805a250a6e49148 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Fri, 12 Aug 2022 01:13:03 +0900 Subject: [PATCH 2/9] Update snapshot --- .../test/__snapshots__/index.js.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap b/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap index 1fdfc1cc75f49d..ad5f92022e1276 100644 --- a/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +++ b/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap @@ -97,9 +97,9 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ }, }, Object { - "description": "Make the selected text inline code.", + "description": "Add non breaking space.", "keyCombination": Object { - "character": "space", + "character": "SPACE", "modifier": "primaryShift", }, }, From 0d9d4ee7b033d6312c6617d42870ae2f803de8ce Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Fri, 12 Aug 2022 01:31:08 +0900 Subject: [PATCH 3/9] Fix local changes --- package-lock.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package-lock.json b/package-lock.json index 6d7947ac5abc54..a547812dd5b6a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", "@wordpress/rich-text": "file:packages/rich-text", "@wordpress/url": "file:packages/url", "lodash": "^4.17.21" From 2697e83065ba8a0ad5bf7e2564d055d5ca36bddd Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Fri, 12 Aug 2022 16:45:14 +0900 Subject: [PATCH 4/9] Change function name --- packages/format-library/src/non-breaking-space/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/format-library/src/non-breaking-space/index.js b/packages/format-library/src/non-breaking-space/index.js index e7a8512103a7d1..66a280133dcf63 100644 --- a/packages/format-library/src/non-breaking-space/index.js +++ b/packages/format-library/src/non-breaking-space/index.js @@ -15,7 +15,7 @@ export const nonBreakingSpace = { tagName: 'span', className: 'nbsp', edit( { value, onChange } ) { - function addSpace() { + function addNonBreakingSpace() { onChange( insert( value, ' ' ) ); } @@ -28,7 +28,7 @@ export const nonBreakingSpace = { ); }, From 824462a460a620b4be9dcb8bd5a00bcb4b8edb65 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Fri, 12 Aug 2022 16:49:59 +0900 Subject: [PATCH 5/9] Use unicode character --- packages/format-library/src/non-breaking-space/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/format-library/src/non-breaking-space/index.js b/packages/format-library/src/non-breaking-space/index.js index 66a280133dcf63..0c133251be2d7f 100644 --- a/packages/format-library/src/non-breaking-space/index.js +++ b/packages/format-library/src/non-breaking-space/index.js @@ -16,7 +16,7 @@ export const nonBreakingSpace = { className: 'nbsp', edit( { value, onChange } ) { function addNonBreakingSpace() { - onChange( insert( value, ' ' ) ); + onChange( insert( value, '\u00a0' ) ); } // Shift + Ctrl + Space shortcut is built in on the Mac. From a7c1a471ca3e20328ad9cd2a3e1a60a2b36789e1 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Fri, 12 Aug 2022 17:03:27 +0900 Subject: [PATCH 6/9] Override built-in shortcut on Mac OS --- packages/format-library/src/non-breaking-space/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/format-library/src/non-breaking-space/index.js b/packages/format-library/src/non-breaking-space/index.js index 0c133251be2d7f..b0de7ba5a97359 100644 --- a/packages/format-library/src/non-breaking-space/index.js +++ b/packages/format-library/src/non-breaking-space/index.js @@ -4,7 +4,6 @@ import { __ } from '@wordpress/i18n'; import { insert } from '@wordpress/rich-text'; import { RichTextShortcut } from '@wordpress/block-editor'; -import { isAppleOS } from '@wordpress/keycodes'; const name = 'core/non-breaking-space'; const title = __( 'Non breaking space' ); @@ -19,11 +18,6 @@ export const nonBreakingSpace = { onChange( insert( value, '\u00a0' ) ); } - // Shift + Ctrl + Space shortcut is built in on the Mac. - if ( isAppleOS() ) { - return; - } - return ( Date: Thu, 28 Dec 2023 18:41:50 +0900 Subject: [PATCH 7/9] Revert unintended changes --- package-lock.json | 73 +++------------------------- packages/format-library/package.json | 1 - 2 files changed, 6 insertions(+), 68 deletions(-) diff --git a/package-lock.json b/package-lock.json index db01c768647e56..960ae127ea85a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59964,73 +59964,12 @@ "integrity": "sha512-0N0yZof5hi44HAR2pPS+ikJ3nzKNoZdVu8FffRf3wy47I7Dm7etk/3KetMdRUqzVd16V4O2m2ISpNTbnIuqy1w==", "dev": true, "requires": { - "@babel/eslint-parser": "^7.16.0", - "@typescript-eslint/eslint-plugin": "^5.3.0", - "@typescript-eslint/parser": "^5.3.0", - "@wordpress/babel-preset-default": "file:packages/babel-preset-default", - "@wordpress/prettier-config": "file:packages/prettier-config", - "cosmiconfig": "^7.0.0", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-import": "^2.25.2", - "eslint-plugin-jest": "^25.2.3", - "eslint-plugin-jsdoc": "^37.0.3", - "eslint-plugin-jsx-a11y": "^6.5.1", - "eslint-plugin-prettier": "^3.3.0", - "eslint-plugin-react": "^7.27.0", - "eslint-plugin-react-hooks": "^4.3.0", - "globals": "^13.12.0", - "requireindex": "^1.2.0" - } - }, - "@wordpress/format-library": { - "version": "file:packages/format-library", - "requires": { - "@babel/runtime": "^7.16.0", - "@wordpress/a11y": "file:packages/a11y", - "@wordpress/block-editor": "file:packages/block-editor", - "@wordpress/components": "file:packages/components", - "@wordpress/compose": "file:packages/compose", - "@wordpress/data": "file:packages/data", - "@wordpress/element": "file:packages/element", - "@wordpress/html-entities": "file:packages/html-entities", - "@wordpress/i18n": "file:packages/i18n", - "@wordpress/icons": "file:packages/icons", - "@wordpress/keycodes": "file:packages/keycodes", - "@wordpress/rich-text": "file:packages/rich-text", - "@wordpress/url": "file:packages/url", - "lodash": "^4.17.21" - } - }, - "@wordpress/hooks": { - "version": "file:packages/hooks", - "requires": { - "@babel/runtime": "^7.16.0" - } - }, - "@wordpress/html-entities": { - "version": "file:packages/html-entities", - "requires": { - "@babel/runtime": "^7.16.0" - } - }, - "@wordpress/i18n": { - "version": "file:packages/i18n", - "requires": { - "@babel/runtime": "^7.16.0", - "@wordpress/hooks": "file:packages/hooks", - "gettext-parser": "^1.3.1", - "lodash": "^4.17.21", - "memize": "^1.1.0", - "sprintf-js": "^1.1.1", - "tannin": "^1.2.0" - } - }, - "@wordpress/icons": { - "version": "file:packages/icons", - "requires": { - "@babel/runtime": "^7.16.0", - "@wordpress/element": "file:packages/element", - "@wordpress/primitives": "file:packages/primitives" + "@jest/types": "^29.6.1", + "@types/node": "*", + "chalk": "^4.0.0", + "jest-message-util": "^29.6.2", + "jest-util": "^29.6.2", + "slash": "^3.0.0" } }, "@jest/core": { diff --git a/packages/format-library/package.json b/packages/format-library/package.json index 9a1650ca2564e5..d2ea9062cf79e3 100644 --- a/packages/format-library/package.json +++ b/packages/format-library/package.json @@ -35,7 +35,6 @@ "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", - "@wordpress/keycodes": "file:../keycodes", "@wordpress/rich-text": "file:../rich-text", "@wordpress/url": "file:../url" }, From bab769da54a859b208e623eef1803229fe10debd Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Thu, 28 Dec 2023 18:55:45 +0900 Subject: [PATCH 8/9] Revert unintended changes --- .../test/__snapshots__/index.js.snap | 113 ------------------ 1 file changed, 113 deletions(-) delete mode 100644 packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap diff --git a/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap b/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap deleted file mode 100644 index ad5f92022e1276..00000000000000 --- a/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +++ /dev/null @@ -1,113 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`KeyboardShortcutHelpModal should match snapshot when the modal is active 1`] = ` - - - - - - - -`; - -exports[`KeyboardShortcutHelpModal should match snapshot when the modal is not active 1`] = `""`; From 758ceb64883135a71df92a912b32ee0bd9057e23 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sat, 2 Mar 2024 10:51:39 +0900 Subject: [PATCH 9/9] use nbsp as tagName --- .../src/components/keyboard-shortcut-help-modal/config.js | 2 +- packages/format-library/src/non-breaking-space/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/edit-post/src/components/keyboard-shortcut-help-modal/config.js b/packages/edit-post/src/components/keyboard-shortcut-help-modal/config.js index 4edf46204c75ae..a206fa6c71d779 100644 --- a/packages/edit-post/src/components/keyboard-shortcut-help-modal/config.js +++ b/packages/edit-post/src/components/keyboard-shortcut-help-modal/config.js @@ -47,7 +47,7 @@ export const textFormattingShortcuts = [ ), }, { - keyCombination: { modifier: 'primaryShift', character: 'SPACE' }, + keyCombination: { modifier: 'primaryShift', character: '\u00a0' }, description: __( 'Add non breaking space.' ), }, ]; diff --git a/packages/format-library/src/non-breaking-space/index.js b/packages/format-library/src/non-breaking-space/index.js index b0de7ba5a97359..829b0960f28a92 100644 --- a/packages/format-library/src/non-breaking-space/index.js +++ b/packages/format-library/src/non-breaking-space/index.js @@ -11,8 +11,8 @@ const title = __( 'Non breaking space' ); export const nonBreakingSpace = { name, title, - tagName: 'span', - className: 'nbsp', + tagName: 'nbsp', + className: null, edit( { value, onChange } ) { function addNonBreakingSpace() { onChange( insert( value, '\u00a0' ) );