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

Writing Flow: fix empty horizontal arrow nav #16846

Merged
merged 3 commits into from
Aug 9, 2019
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
11 changes: 9 additions & 2 deletions packages/dom/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ function isEdge( container, isReverse, onlyVertical ) {
const side = isReverseDir ? 'left' : 'right';
const testRect = getRectangleFromRange( testRange );

return Math.round( testRect[ side ] ) === Math.round( rangeRect[ side ] );
// Allow the position to be 1px off.
return Math.abs( testRect[ side ] - rangeRect[ side ] ) <= 1;
}

/**
Expand Down Expand Up @@ -352,11 +353,17 @@ function caretRangeFromPoint( doc, x, y ) {
* @return {?Range} The best range for the given point.
*/
function hiddenCaretRangeFromPoint( doc, x, y, container ) {
const originalZIndex = container.style.zIndex;
const originalPosition = container.style.position;

// A z-index only works if the element position is not static.
container.style.zIndex = '10000';
container.style.position = 'relative';

const range = caretRangeFromPoint( doc, x, y );

container.style.zIndex = null;
container.style.zIndex = originalZIndex;
container.style.position = originalPosition;

return range;
}
Expand Down
14 changes: 14 additions & 0 deletions packages/e2e-tests/specs/__snapshots__/writing-flow.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ exports[`Writing Flow should navigate empty paragraph 1`] = `
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should navigate empty paragraphs 1`] = `
"<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>3</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should not create extra line breaks in multiline value 1`] = `
"<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
Expand Down
14 changes: 14 additions & 0 deletions packages/e2e-tests/specs/writing-flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,18 @@ describe( 'Writing Flow', () => {

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should navigate empty paragraphs', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( '3' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
4 changes: 4 additions & 0 deletions packages/rich-text/src/to-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ export function toTree( {
type: 'span',
attributes: {
'data-rich-text-placeholder': placeholder,
// Necessary to prevent the placeholder from catching
// selection. The placeholder is also not editable after
// all.
contenteditable: 'false',
},
} );
}
Expand Down