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

Editor: Unify context text cursor preference #57479

Merged
merged 1 commit into from
Jan 3, 2024
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
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
Loading