Skip to content

Commit

Permalink
Editor: Unify context text cursor preference
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jan 3, 2024
1 parent 0ef7bc4 commit 70550fb
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export default function EditPostPreferencesModal() {
) }
>
<EnableFeature
scope="core"
featureName="keepCaretInsideBlock"
help={ __(
'Keeps the text cursor within the block boundaries, aiding users with screen readers by preventing unintentional cursor movement outside the block.'
Expand Down
4 changes: 0 additions & 4 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function Editor( {
preferredStyleVariations,
hiddenBlockTypes,
blockTypes,
keepCaretInsideBlock,
template,
} = useSelect(
( select ) => {
Expand Down Expand Up @@ -101,7 +100,6 @@ function Editor( {
),
hiddenBlockTypes: getHiddenBlockTypes(),
blockTypes: getBlockTypes(),
keepCaretInsideBlock: isFeatureActive( 'keepCaretInsideBlock' ),
template:
supportsTemplateMode && isViewable && canEditTemplate
? getEditedPostTemplate()
Expand All @@ -128,7 +126,6 @@ function Editor( {
isDistractionFree,
hasInlineToolbar,

keepCaretInsideBlock,
// Keep a reference of the `allowedBlockTypes` from the server to handle use cases
// where we need to differentiate if a block is disabled by the user or some plugin.
defaultAllowedBlockTypes: settings.allowedBlockTypes,
Expand Down Expand Up @@ -156,7 +153,6 @@ function Editor( {
hasInlineToolbar,
focusMode,
isDistractionFree,
keepCaretInsideBlock,
hiddenBlockTypes,
blockTypes,
preferredStyleVariations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export function useSpecificEditorSettings() {
focusMode,
isDistractionFree,
hasFixedToolbar,
keepCaretInsideBlock,
canvasMode,
settings,
postWithTemplate,
Expand Down Expand Up @@ -130,10 +129,6 @@ export function useSpecificEditorSettings() {
hasFixedToolbar:
!! getPreference( 'core/edit-site', 'fixedToolbar' ) ||
! isLargeViewport,
keepCaretInsideBlock: !! getPreference(
'core/edit-site',
'keepCaretInsideBlock'
),
canvasMode: getCanvasMode(),
settings: getSettings(),
postWithTemplate: _context?.postId,
Expand All @@ -152,7 +147,6 @@ export function useSpecificEditorSettings() {
focusMode: canvasMode === 'view' && focusMode ? false : focusMode,
isDistractionFree,
hasFixedToolbar,
keepCaretInsideBlock,
defaultRenderingMode,
getPostLinkProps,
// I wonder if they should be set in the post editor too
Expand All @@ -165,7 +159,6 @@ export function useSpecificEditorSettings() {
focusMode,
isDistractionFree,
hasFixedToolbar,
keepCaretInsideBlock,
defaultRenderingMode,
getPostLinkProps,
archiveLabels.archiveTypeLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default function EditSitePreferencesModal() {
) }
>
<EnableFeature
namespace="core"
featureName="keepCaretInsideBlock"
help={ __(
'Keeps the text cursor within the block boundaries, aiding users with screen readers by preventing unintentional cursor movement outside the block.'
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ export function initializeEditor( id, settings ) {
fixedToolbar: false,
focusMode: false,
distractionFree: false,
keepCaretInsideBlock: false,
welcomeGuide: true,
welcomeGuideStyles: true,
welcomeGuidePage: true,
welcomeGuideTemplate: true,
showListViewByDefault: false,
showBlockBreadcrumbs: true,
} );

dispatch( preferencesStore ).setDefaults( 'core', {
allowRightClickOverrides: true,
keepCaretInsideBlock: false,
} );

dispatch( interfaceStore ).setDefaultComplementaryArea(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const BLOCK_EDITOR_SETTINGS = [
'imageEditing',
'imageSizes',
'isRTL',
'keepCaretInsideBlock',
'locale',
'maxWidth',
'onUpdateDefaultBlockStyles',
Expand Down Expand Up @@ -91,6 +90,7 @@ const BLOCK_EDITOR_SETTINGS = [
function useBlockEditorSettings( settings, postType, postId ) {
const {
allowRightClickOverrides,
keepCaretInsideBlock,
reusableBlocks,
hasUploadPermissions,
canUseUnfilteredHTML,
Expand All @@ -115,13 +115,14 @@ function useBlockEditorSettings( settings, postType, postId ) {
} = select( coreStore );
const { getPostLinkProps: postLinkProps } =
select( editorStore ).getEditorSettings();
const { get } = select( preferencesStore );

const siteSettings = canUser( 'read', 'settings' )
? getEntityRecord( 'root', 'site' )
: undefined;

return {
allowRightClickOverrides: select( preferencesStore ).get(
allowRightClickOverrides: get(
'core',
'allowRightClickOverrides'
),
Expand All @@ -130,6 +131,7 @@ function useBlockEditorSettings( settings, postType, postId ) {
postType,
postId
)?._links?.hasOwnProperty( 'wp:action-unfiltered-html' ),
keepCaretInsideBlock: get( 'core', 'keepCaretInsideBlock' ),
reusableBlocks: isWeb
? getEntityRecords( 'postType', 'wp_block', {
per_page: -1,
Expand Down Expand Up @@ -220,6 +222,7 @@ function useBlockEditorSettings( settings, postType, postId ) {
)
),
allowRightClickOverrides,
keepCaretInsideBlock,
mediaUpload: hasUploadPermissions ? mediaUpload : undefined,
__experimentalReusableBlocks: reusableBlocks,
__experimentalBlockPatterns: blockPatterns,
Expand Down Expand Up @@ -254,6 +257,7 @@ function useBlockEditorSettings( settings, postType, postId ) {
} ),
[
allowRightClickOverrides,
keepCaretInsideBlock,
settings,
hasUploadPermissions,
reusableBlocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

export default function convertEditorSettings( data ) {
let newData = data;
const settingsToMoveToCore = [ 'allowRightClickOverrides' ];
const settingsToMoveToCore = [
'allowRightClickOverrides',
'keepCaretInsideBlock',
];

settingsToMoveToCore.forEach( ( setting ) => {
if ( data?.[ 'core/edit-post' ]?.[ setting ] !== undefined ) {
Expand Down

0 comments on commit 70550fb

Please sign in to comment.