Skip to content
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

Fix the RTL editor styles and the theme styles option #27947

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,9 @@ function gutenberg_register_vendor_script( $scripts, $handle, $src, $deps = arra
* @return array Filtered editor settings.
*/
function gutenberg_extend_block_editor_styles( $settings ) {
$editor_styles_file = gutenberg_dir_path() . 'build/editor/editor-styles.css';
$editor_styles_file = is_rtl() ?
gutenberg_dir_path() . 'build/editor/editor-styles-rtl.css' :
gutenberg_dir_path() . 'build/editor/editor-styles.css';

/*
* If, for whatever reason, the built editor styles do not exist, avoid
Expand All @@ -601,7 +603,9 @@ function gutenberg_extend_block_editor_styles( $settings ) {
*/

$default_styles = file_get_contents(
ABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
is_rtl() ?
ABSPATH . WPINC . '/css/dist/editor/editor-styles-rtl.css' :
ABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
);

/*
Expand Down Expand Up @@ -640,7 +644,9 @@ function gutenberg_extend_block_editor_styles( $settings ) {
* @return array Filtered editor settings.
*/
function gutenberg_extend_block_editor_settings_with_default_editor_styles( $settings ) {
$editor_styles_file = gutenberg_dir_path() . 'build/editor/editor-styles.css';
$editor_styles_file = is_rtl() ?
gutenberg_dir_path() . 'build/editor/editor-styles-rtl.css' :
gutenberg_dir_path() . 'build/editor/editor-styles.css';
$settings['defaultEditorStyles'] = array(
array(
'css' => file_get_contents( $editor_styles_file ),
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const interfaceLabels = {
footer: __( 'Editor footer' ),
};

function Layout( { settings } ) {
function Layout( { styles } ) {
const isMobileViewport = useViewportMatch( 'medium', '<' );
const isHugeViewport = useViewportMatch( 'huge', '>=' );
const {
Expand Down Expand Up @@ -171,7 +171,7 @@ function Layout( { settings } ) {
const ref = useRef();

useDrop( ref );
useEditorStyles( ref, settings.styles );
useEditorStyles( ref, styles );
const [ inserterDialogRef, inserterDialogProps ] = useDialog( {
onClose: () => setIsInserterOpened( false ),
} );
Expand Down
14 changes: 6 additions & 8 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ function Editor( {

const editorSettings = useMemo( () => {
const result = {
...( hasThemeStyles
? settings
: omit( settings, [ 'defaultEditorStyles' ] ) ),
...omit( settings, [ 'defaultEditorStyles', 'styles' ] ),
__experimentalPreferredStyleVariations: {
value: preferredStyleVariations,
onChange: updatePreferredStyleVariations,
Expand All @@ -114,9 +112,6 @@ function Editor( {
// This is marked as experimental to give time for the quick inserter to mature.
__experimentalSetIsInserterOpened: setIsInserterOpened,
keepCaretInsideBlock,
styles: hasThemeStyles
? settings.styles
: settings.defaultEditorStyles,
};

// Omit hidden block types if exists and non-empty.
Expand All @@ -141,7 +136,6 @@ function Editor( {
hasFixedToolbar,
focusMode,
hasReducedUI,
hasThemeStyles,
hiddenBlockTypes,
blockTypes,
preferredStyleVariations,
Expand All @@ -151,6 +145,10 @@ function Editor( {
keepCaretInsideBlock,
] );

const styles = useMemo( () => {
return hasThemeStyles ? settings.styles : settings.defaultEditorStyles;
}, [ settings, hasThemeStyles ] );

if ( ! post ) {
return null;
}
Expand All @@ -172,7 +170,7 @@ function Editor( {
>
<ErrorBoundary onError={ onError }>
<EditorInitialization postId={ postId } />
<Layout settings={ settings } />
<Layout styles={ styles } />
<KeyboardShortcuts
shortcuts={ preventEventDiscovery }
/>
Expand Down