Skip to content

Commit

Permalink
Rich text: remove store change on focus (#48342)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 23, 2023
1 parent 1a93475 commit 09df1a4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function findSelection( blocks ) {
blocks[ i ].attributes[ attributeKey ] = blocks[ i ].attributes[
attributeKey
].replace( START_OF_SELECTED_AREA, '' );
return blocks[ i ].clientId;
return [ blocks[ i ].clientId, attributeKey, 0, 0 ];
}

const nestedSelection = findSelection( blocks[ i ].innerBlocks );
Expand All @@ -38,6 +38,8 @@ function findSelection( blocks ) {
return nestedSelection;
}
}

return [];
}

export function useInputRules( props ) {
Expand Down Expand Up @@ -86,9 +88,11 @@ export function useInputRules( props ) {
} );
const block = transformation.transform( content );

selectionChange( findSelection( [ block ] ) );
selectionChange( ...findSelection( [ block ] ) );
onReplace( [ block ] );
__unstableMarkAutomaticChange();

return true;
}

function onInput( event ) {
Expand All @@ -106,7 +110,7 @@ export function useInputRules( props ) {
}

if ( __unstableAllowPrefixTransformations && inputRule ) {
inputRule();
if ( inputRule() ) return;
}

const value = getValue();
Expand Down
2 changes: 1 addition & 1 deletion packages/dom/src/dom/get-rectangle-from-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function getRectangleFromRange( range ) {
// by adding a temporary text node with zero-width space to the range.
//
// See: https://stackoverflow.com/a/6847328/995445
if ( ! rect ) {
if ( ! rect || rect.height === 0 ) {
assertIsDefined( ownerDocument, 'ownerDocument' );
const padNode = ownerDocument.createTextNode( '\u200b' );
// Do not modify the live range.
Expand Down
26 changes: 14 additions & 12 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getHoverEventDurations,
getSelectionEventDurations,
getLoadingDurations,
sum,
} from './utils';

jest.setTimeout( 1000000 );
Expand Down Expand Up @@ -235,22 +236,26 @@ describe( 'Post Editor Performance', () => {
it( 'Selecting blocks', async () => {
await load1000Paragraphs();
const paragraphs = await canvas().$$( '.wp-block' );
await page.tracing.start( {
path: traceFile,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
await paragraphs[ 0 ].click();
for ( let j = 1; j <= 10; j++ ) {
// Wait for the browser to be idle before starting the monitoring.
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( 1000 );
await page.tracing.start( {
path: traceFile,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
await paragraphs[ j ].click();
await page.tracing.stop();
traceResults = JSON.parse( readFile( traceFile ) );
const allDurations = getSelectionEventDurations( traceResults );
results.focus.push(
allDurations.reduce( ( acc, eventDurations ) => {
return acc + sum( eventDurations );
}, 0 )
);
}
await page.tracing.stop();
traceResults = JSON.parse( readFile( traceFile ) );
const [ focusEvents ] = getSelectionEventDurations( traceResults );
results.focus = focusEvents;
} );

it( 'Opening persistent list view', async () => {
Expand Down Expand Up @@ -292,9 +297,6 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Searching the inserter', async () => {
function sum( arr ) {
return arr.reduce( ( a, b ) => a + b, 0 );
}
await load1000Paragraphs();
await openGlobalBlockInserter();
for ( let j = 0; j < 10; j++ ) {
Expand Down
13 changes: 12 additions & 1 deletion packages/e2e-tests/specs/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function isFocusEvent( item ) {
return isEvent( item ) && item.args.data.type === 'focus';
}

function isFocusInEvent( item ) {
return isEvent( item ) && item.args.data.type === 'focusin';
}

function isClickEvent( item ) {
return isEvent( item ) && item.args.data.type === 'click';
}
Expand Down Expand Up @@ -68,7 +72,10 @@ export function getTypingEventDurations( trace ) {
}

export function getSelectionEventDurations( trace ) {
return [ getEventDurationsForType( trace, isFocusEvent ) ];
return [
getEventDurationsForType( trace, isFocusEvent ),
getEventDurationsForType( trace, isFocusInEvent ),
];
}

export function getClickEventDurations( trace ) {
Expand Down Expand Up @@ -113,3 +120,7 @@ export async function getLoadingDurations() {
};
} );
}

export function sum( arr ) {
return arr.reduce( ( a, b ) => a + b, 0 );
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ export function useInputAndSelection( props ) {
end: index,
activeFormats: EMPTY_ACTIVE_FORMATS,
};
onSelectionChange( index, index );
} else {
applyRecord( record.current );
onSelectionChange( record.current.start, record.current.end );
Expand Down

1 comment on commit 09df1a4

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 09df1a4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4255070605
📝 Reported issues:

Please sign in to comment.