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

Revert "Honor the Disable Visual Editor setting (#12000)" #12151

Merged
merged 3 commits into from
Nov 21, 2018
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
7 changes: 0 additions & 7 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@ function gutenberg_pre_init() {
add_filter( 'replace_editor', 'gutenberg_init', 10, 2 );
}

/**
* Enable Gutenberg based on user_can_richedit setting.
* Set gutenberg_can_edit_post based on user setting for disable visual editor.
*/
add_filter( 'gutenberg_can_edit_post_type', 'user_can_richedit', 5 );
add_filter( 'gutenberg_can_edit_post', 'user_can_richedit', 5 );

/**
* Initialize Gutenberg.
*
Expand Down
8 changes: 8 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,13 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
'after'
);

// Ignore Classic Editor's `rich_editing` user option, aka "Disable visual
// editor". Forcing this to be true guarantees that TinyMCE and its plugins
// are available in Gutenberg. Fixes
// https://github.com/WordPress/gutenberg/issues/5667.
$user_can_richedit = user_can_richedit();
add_filter( 'user_can_richedit', '__return_true' );

wp_enqueue_script( 'wp-edit-post' );
wp_enqueue_script( 'wp-format-library' );
wp_enqueue_style( 'wp-format-library' );
Expand Down Expand Up @@ -1294,6 +1301,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
'allowedMimeTypes' => get_allowed_mime_types(),
'styles' => $styles,
'imageSizes' => gutenberg_get_available_image_sizes(),
'richEditingEnabled' => $user_can_richedit,

// Ideally, we'd remove this and rely on a REST API endpoint.
'postLock' => $lock_details,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
*/
import FullscreenModeClose from '../fullscreen-mode-close';

function HeaderToolbar( { hasFixedToolbar, isLargeViewport, mode } ) {
function HeaderToolbar( { hasFixedToolbar, isLargeViewport, showInserter } ) {
const toolbarAriaLabel = hasFixedToolbar ?
/* translators: accessibility text for the editor toolbar when Top Toolbar is on */
__( 'Document and block tools' ) :
Expand All @@ -35,7 +35,7 @@ function HeaderToolbar( { hasFixedToolbar, isLargeViewport, mode } ) {
>
<FullscreenModeClose />
<div>
<Inserter disabled={ mode !== 'visual' } position="bottom right" />
<Inserter disabled={ ! showInserter } position="bottom right" />
<DotTip tipId="core/editor.inserter">
{ __( 'Welcome to the wonderful world of blocks! Click the “+” (“Add block”) button to add a new block. There are blocks available for all kinds of content: you can insert text, headings, images, lists, and lots more!' ) }
</DotTip>
Expand All @@ -56,7 +56,7 @@ function HeaderToolbar( { hasFixedToolbar, isLargeViewport, mode } ) {
export default compose( [
withSelect( ( select ) => ( {
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ),
mode: select( 'core/edit-post' ).getEditorMode(),
showInserter: select( 'core/edit-post' ).getEditorMode() === 'visual' && select( 'core/editor' ).getEditorSettings().richEditingEnabled,
} ) ),
withViewportMatch( { isLargeViewport: 'medium' } ),
] )( HeaderToolbar );
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { MenuItemsChoice, MenuGroup } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { compose, ifCondition } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';

/**
Expand Down Expand Up @@ -49,8 +49,10 @@ function ModeSwitcher( { onSwitch, mode } ) {

export default compose( [
withSelect( ( select ) => ( {
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings().richEditingEnabled,
mode: select( 'core/edit-post' ).getEditorMode(),
} ) ),
ifCondition( ( { isRichEditingEnabled } ) => isRichEditingEnabled ),
withDispatch( ( dispatch, ownProps ) => ( {
onSwitch( mode ) {
dispatch( 'core/edit-post' ).switchEditorMode( mode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class EditorModeKeyboardShortcuts extends Component {
}

toggleMode() {
const { mode, switchMode } = this.props;
const { mode, switchMode, isRichEditingEnabled } = this.props;
if ( ! isRichEditingEnabled ) {
return;
}
switchMode( mode === 'visual' ? 'text' : 'visual' );
}

Expand Down Expand Up @@ -52,6 +55,7 @@ class EditorModeKeyboardShortcuts extends Component {

export default compose( [
withSelect( ( select ) => ( {
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings().richEditingEnabled,
mode: select( 'core/edit-post' ).getEditorMode(),
isEditorSidebarOpen: select( 'core/edit-post' ).isEditorSidebarOpened(),
hasBlockSelection: !! select( 'core/editor' ).getBlockSelectionStart(),
Expand Down
6 changes: 4 additions & 2 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function Layout( {
hasActiveMetaboxes,
isSaving,
isMobileViewport,
isRichEditingEnabled,
} ) {
const sidebarIsOpened = editorSidebarOpened || pluginSidebarOpened || publishSidebarOpened;

Expand Down Expand Up @@ -84,8 +85,8 @@ function Layout( {
<EditorModeKeyboardShortcuts />
<KeyboardShortcutHelpModal />
<OptionsModal />
{ mode === 'text' && <TextEditor /> }
{ mode === 'visual' && <VisualEditor /> }
{ ( mode === 'text' || ! isRichEditingEnabled ) && <TextEditor /> }
{ isRichEditingEnabled && mode === 'visual' && <VisualEditor /> }
<div className="edit-post-layout__metaboxes">
<MetaBoxes location="normal" />
</div>
Expand Down Expand Up @@ -137,6 +138,7 @@ export default compose(
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ),
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings().richEditingEnabled,
} ) ),
withDispatch( ( dispatch ) => {
const { closePublishSidebar, togglePublishSidebar } = dispatch( 'core/edit-post' );
Expand Down
46 changes: 27 additions & 19 deletions packages/edit-post/src/components/text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
*/
import { PostTextEditor, PostTitle } from '@wordpress/editor';
import { IconButton } from '@wordpress/components';
import { withDispatch } from '@wordpress/data';
import { withDispatch, withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { displayShortcut } from '@wordpress/keycodes';
import { compose } from '@wordpress/compose';

function TextEditor( { onExit } ) {
function TextEditor( { onExit, isRichEditingEnabled } ) {
return (
<div className="edit-post-text-editor">
<div className="edit-post-text-editor__toolbar">
<h2>{ __( 'Editing Code' ) }</h2>
<IconButton
onClick={ onExit }
icon="no-alt"
shortcut={ displayShortcut.secondary( 'm' ) }
>
{ __( 'Exit Code Editor' ) }
</IconButton>
</div>
{ isRichEditingEnabled && (
<div className="edit-post-text-editor__toolbar">
<h2>{ __( 'Editing Code' ) }</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowriad Should this headline maybe still be displayed (without the button)? See #12182 for a related report.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure no strong opinion.

<IconButton
onClick={ onExit }
icon="no-alt"
shortcut={ displayShortcut.secondary( 'm' ) }
>
{ __( 'Exit Code Editor' ) }
</IconButton>
</div>
) }
<div className="edit-post-text-editor__body">
<PostTitle />
<PostTextEditor />
Expand All @@ -28,10 +31,15 @@ function TextEditor( { onExit } ) {
);
}

export default withDispatch( ( dispatch ) => {
return {
onExit() {
dispatch( 'core/edit-post' ).switchEditorMode( 'visual' );
},
};
} )( TextEditor );
export default compose(
withSelect( ( select ) => ( {
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings().richEditingEnabled,
} ) ),
withDispatch( ( dispatch ) => {
return {
onExit() {
dispatch( 'core/edit-post' ).switchEditorMode( 'visual' );
},
};
} )
)( TextEditor );
20 changes: 12 additions & 8 deletions packages/editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export const PREFERENCES_DEFAULTS = {
/**
* The default editor settings
*
* alignWide boolean Enable/Disable Wide/Full Alignments
* colors Array Palette colors
* fontSizes Array Available font sizes
* imageSizes Array Available image sizes
* maxWidth number Max width to constraint resizing
* blockTypes boolean|Array Allowed block types
* hasFixedToolbar boolean Whether or not the editor toolbar is fixed
* focusMode boolean Whether the focus mode is enabled or not
* alignWide boolean Enable/Disable Wide/Full Alignments
* colors Array Palette colors
* fontSizes Array Available font sizes
* imageSizes Array Available image sizes
* maxWidth number Max width to constraint resizing
* blockTypes boolean|Array Allowed block types
* hasFixedToolbar boolean Whether or not the editor toolbar is fixed
* focusMode boolean Whether the focus mode is enabled or not
* richEditingEnabled boolean Whether rich editing is enabled or not
*/
export const EDITOR_SETTINGS_DEFAULTS = {
alignWide: false,
Expand Down Expand Up @@ -126,6 +127,9 @@ export const EDITOR_SETTINGS_DEFAULTS = {

// List of allowed mime types and file extensions.
allowedMimeTypes: null,

// Whether richs editing is enabled or not.
richEditingEnabled: true,
};

/**
Expand Down