diff --git a/packages/e2e-tests/specs/__snapshots__/writing-flow.test.js.snap b/packages/e2e-tests/specs/__snapshots__/writing-flow.test.js.snap
index 0d02a8e655bfa3..dca0ce4763cdbb 100644
--- a/packages/e2e-tests/specs/__snapshots__/writing-flow.test.js.snap
+++ b/packages/e2e-tests/specs/__snapshots__/writing-flow.test.js.snap
@@ -72,7 +72,7 @@ exports[`adding blocks should create valid paragraph blocks when rapidly pressin
exports[`adding blocks should insert line break at end 1`] = `
"
-
a
+a
"
`;
@@ -90,7 +90,7 @@ exports[`adding blocks should insert line break at start 1`] = `
exports[`adding blocks should insert line break in empty container 1`] = `
"
-
+
"
`;
diff --git a/packages/e2e-tests/specs/blocks/__snapshots__/list.test.js.snap b/packages/e2e-tests/specs/blocks/__snapshots__/list.test.js.snap
index 119fce765c5f43..b2e8ec4875aaca 100644
--- a/packages/e2e-tests/specs/blocks/__snapshots__/list.test.js.snap
+++ b/packages/e2e-tests/specs/blocks/__snapshots__/list.test.js.snap
@@ -146,13 +146,13 @@ exports[`List should indent and outdent level 2 3`] = `
exports[`List should insert a line break on shift+enter 1`] = `
"
-
+
"
`;
exports[`List should insert a line break on shift+enter in a non trailing list item 1`] = `
"
-
+
"
`;
diff --git a/packages/editor/src/components/rich-text/index.js b/packages/editor/src/components/rich-text/index.js
index 3ca992296e4fb2..e72a70b61e46c6 100644
--- a/packages/editor/src/components/rich-text/index.js
+++ b/packages/editor/src/components/rich-text/index.js
@@ -193,6 +193,7 @@ export class RichText extends Component {
multilineTag: this.multilineTag,
multilineWrapperTags: this.multilineWrapperTags,
prepareEditableTree: this.props.prepareEditableTree,
+ __unstableIsEditableTree: true,
} );
}
diff --git a/packages/rich-text/src/create.js b/packages/rich-text/src/create.js
index 90d54c82c45611..82348bbd4fa8aa 100644
--- a/packages/rich-text/src/create.js
+++ b/packages/rich-text/src/create.js
@@ -108,6 +108,7 @@ export function create( {
range,
multilineTag,
multilineWrapperTags,
+ __unstableIsEditableTree: isEditableTree,
} = {} ) {
if ( typeof text === 'string' && text.length > 0 ) {
return {
@@ -128,6 +129,7 @@ export function create( {
return createFromElement( {
element,
range,
+ isEditableTree,
} );
}
@@ -136,6 +138,7 @@ export function create( {
range,
multilineTag,
multilineWrapperTags,
+ isEditableTree,
} );
}
@@ -257,6 +260,7 @@ function createFromElement( {
multilineTag,
multilineWrapperTags,
currentWrapperTags = [],
+ isEditableTree,
} ) {
const accumulator = createEmptyValue();
@@ -291,7 +295,10 @@ function createFromElement( {
continue;
}
- if ( node.getAttribute( 'data-rich-text-padding' ) ) {
+ if (
+ node.getAttribute( 'data-rich-text-padding' ) ||
+ ( isEditableTree && type === 'br' && ! node.getAttribute( 'data-rich-text-line-break' ) )
+ ) {
accumulateSelection( accumulator, node, range, createEmptyValue() );
continue;
}
@@ -433,7 +440,7 @@ function createFromMultilineElement( {
continue;
}
- let value = createFromElement( {
+ const value = createFromElement( {
element: node,
range,
multilineTag,
@@ -441,23 +448,6 @@ function createFromMultilineElement( {
currentWrapperTags,
} );
- // If a line consists of one single line break (invisible), consider the
- // line empty, wether this is the browser's doing or not.
- if ( value.text === '\n' ) {
- const start = value.start;
- const end = value.end;
-
- value = createEmptyValue();
-
- if ( start !== undefined ) {
- value.start = 0;
- }
-
- if ( end !== undefined ) {
- value.end = 0;
- }
- }
-
// Multiline value text should be separated by a double line break.
if ( index !== 0 || currentWrapperTags.length > 0 ) {
const formats = currentWrapperTags.length > 0 ? [ currentWrapperTags ] : [ , ];
@@ -495,7 +485,7 @@ function getAttributes( { element } ) {
for ( let i = 0; i < length; i++ ) {
const { name, value } = element.attributes[ i ];
- if ( name === 'data-rich-text-format-boundary' ) {
+ if ( name.indexOf( 'data-rich-text-' ) === 0 ) {
continue;
}
diff --git a/packages/rich-text/src/insert-line-break.js b/packages/rich-text/src/insert-line-break.js
index 540214d614f3c6..08b0b70b864e63 100644
--- a/packages/rich-text/src/insert-line-break.js
+++ b/packages/rich-text/src/insert-line-break.js
@@ -3,32 +3,14 @@
*/
import { insert } from './insert';
-import { LINE_SEPARATOR } from './special-characters';
/**
- * Inserts a line break at the given or selected position. Inserts two line
- * breaks if at the end of a line.
+ * Inserts a line break at the given or selected position.
*
* @param {Object} value Value to modify.
*
- * @return {Object} The value with the line break(s) inserted.
+ * @return {Object} The value with the line break inserted.
*/
export function insertLineBreak( value ) {
- const { text, end } = value;
- const length = text.length;
-
- let toInsert = '\n';
-
- // If the caret is at the end of the text, and there is no
- // trailing line break or no text at all, we have to insert two
- // line breaks in order to create a new line visually and place
- // the caret there.
- if (
- ( end === length || text[ end ] === LINE_SEPARATOR ) &&
- ( text[ end - 1 ] !== '\n' || length === 0 )
- ) {
- toInsert = '\n\n';
- }
-
- return insert( value, toInsert );
+ return insert( value, '\n' );
}
diff --git a/packages/rich-text/src/test/__snapshots__/to-dom.js.snap b/packages/rich-text/src/test/__snapshots__/to-dom.js.snap
index 78378090137bd5..a68cdab1c911eb 100644
--- a/packages/rich-text/src/test/__snapshots__/to-dom.js.snap
+++ b/packages/rich-text/src/test/__snapshots__/to-dom.js.snap
@@ -132,8 +132,13 @@ exports[`recordToDom should filter format boundary attributes 1`] = `
exports[`recordToDom should handle br 1`] = `
-
+
+
`;
@@ -143,17 +148,24 @@ exports[`recordToDom should handle br with formatting 1`] = `
data-rich-text-format-boundary="true"
>
-
+
+
te
-
+
st
a
-
+
-
+
b