Skip to content

Commit 30d42bf

Browse files
committed
Write/Design tool: Persist as a user preference
1 parent 4f3da91 commit 30d42bf

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

packages/block-editor/src/store/actions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { __, _n, sprintf } from '@wordpress/i18n';
2121
import { store as noticesStore } from '@wordpress/notices';
2222
import { create, insert, remove, toHTMLString } from '@wordpress/rich-text';
2323
import deprecated from '@wordpress/deprecated';
24+
import { store as preferencesStore } from '@wordpress/preferences';
2425

2526
/**
2627
* Internal dependencies
@@ -1668,7 +1669,7 @@ export const setNavigationMode =
16681669
*/
16691670
export const __unstableSetEditorMode =
16701671
( mode ) =>
1671-
( { dispatch, select } ) => {
1672+
( { dispatch, select, registry } ) => {
16721673
// When switching to zoom-out mode, we need to select the parent section
16731674
if ( mode === 'zoom-out' ) {
16741675
const firstSelectedClientId = select.getBlockSelectionStart();
@@ -1708,7 +1709,7 @@ export const __unstableSetEditorMode =
17081709
}
17091710
}
17101711

1711-
dispatch( { type: 'SET_EDITOR_MODE', mode } );
1712+
registry.dispatch( preferencesStore ).set( 'core', 'editorTool', mode );
17121713

17131714
if ( mode === 'navigation' ) {
17141715
speak(

packages/block-editor/src/store/reducer.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,22 +1786,6 @@ export const blockListSettings = ( state = {}, action ) => {
17861786
return state;
17871787
};
17881788

1789-
/**
1790-
* Reducer returning which mode is enabled.
1791-
*
1792-
* @param {string} state Current state.
1793-
* @param {Object} action Dispatched action.
1794-
*
1795-
* @return {string} Updated state.
1796-
*/
1797-
export function editorMode( state = 'edit', action ) {
1798-
if ( action.type === 'SET_EDITOR_MODE' ) {
1799-
return action.mode;
1800-
}
1801-
1802-
return state;
1803-
}
1804-
18051789
/**
18061790
* Reducer return an updated state representing the most recent block attribute
18071791
* update. The state is structured as an object where the keys represent the
@@ -2117,7 +2101,6 @@ const combinedReducers = combineReducers( {
21172101
preferences,
21182102
lastBlockAttributesChange,
21192103
lastFocus,
2120-
editorMode,
21212104
expandedBlock,
21222105
highlightedBlock,
21232106
lastBlockInserted,

packages/block-editor/src/store/selectors.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { symbol } from '@wordpress/icons';
1616
import { create, remove, toHTMLString } from '@wordpress/rich-text';
1717
import deprecated from '@wordpress/deprecated';
1818
import { createSelector, createRegistrySelector } from '@wordpress/data';
19+
import { store as preferencesStore } from '@wordpress/preferences';
1920

2021
/**
2122
* Internal dependencies
@@ -2691,7 +2692,7 @@ export function __experimentalGetLastBlockAttributeChanges( state ) {
26912692
* @return {boolean} Is navigation mode enabled.
26922693
*/
26932694
export function isNavigationMode( state ) {
2694-
return state.editorMode === 'navigation';
2695+
return __unstableGetEditorMode( state ) === 'navigation';
26952696
}
26962697

26972698
/**
@@ -2701,9 +2702,11 @@ export function isNavigationMode( state ) {
27012702
*
27022703
* @return {string} the editor mode.
27032704
*/
2704-
export function __unstableGetEditorMode( state ) {
2705-
return state.editorMode;
2706-
}
2705+
export const __unstableGetEditorMode = createRegistrySelector(
2706+
( select ) => () => {
2707+
return select( preferencesStore ).get( 'core', 'editorTool' );
2708+
}
2709+
);
27072710

27082711
/**
27092712
* Returns whether block moving mode is enabled.

0 commit comments

Comments
 (0)