|
@@ -122,9 +122,8 @@ export default function deleteContent( model, selection, options = {} ) {
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Returns the live positions for the range adjusted to span only blocks selected from the user perspective.
|
|
|
|
|
|
|
+// Returns the live positions for the range adjusted to span only blocks selected from the user perspective. Example:
|
|
|
//
|
|
//
|
|
|
-// Examples:
|
|
|
|
|
// <heading1>[foo</heading1>
|
|
// <heading1>[foo</heading1>
|
|
|
// <paragraph>bar</paragraph>
|
|
// <paragraph>bar</paragraph>
|
|
|
// <heading1>]abc</heading1> <-- this block is not considered as selected
|
|
// <heading1>]abc</heading1> <-- this block is not considered as selected
|
|
@@ -233,6 +232,7 @@ function mergeBranches( writer, startPosition, endPosition ) {
|
|
|
// <blockBlock> -> |
|
|
// <blockBlock> -> |
|
|
|
// <paragraph>]bar</paragraph> -> ---
|
|
// <paragraph>]bar</paragraph> -> ---
|
|
|
// </blockBlock> ->
|
|
// </blockBlock> ->
|
|
|
|
|
+//
|
|
|
function mergeBranchesLeft( writer, startPosition, endPosition, commonAncestor ) {
|
|
function mergeBranchesLeft( writer, startPosition, endPosition, commonAncestor ) {
|
|
|
const startElement = startPosition.parent;
|
|
const startElement = startPosition.parent;
|
|
|
const endElement = endPosition.parent;
|
|
const endElement = endPosition.parent;
|
|
@@ -248,16 +248,19 @@ function mergeBranchesLeft( writer, startPosition, endPosition, commonAncestor )
|
|
|
|
|
|
|
|
// Move endElement just after startElement if they aren't siblings.
|
|
// Move endElement just after startElement if they aren't siblings.
|
|
|
if ( !endPosition.isEqual( startPosition ) ) {
|
|
if ( !endPosition.isEqual( startPosition ) ) {
|
|
|
|
|
+ //
|
|
|
// <blockQuote> -> <blockQuote>
|
|
// <blockQuote> -> <blockQuote>
|
|
|
// <heading1>foo[</heading1> -> <heading1>foo</heading1>[<paragraph>bar</paragraph>
|
|
// <heading1>foo[</heading1> -> <heading1>foo</heading1>[<paragraph>bar</paragraph>
|
|
|
// </blockQuote> -> </blockQuote> ^
|
|
// </blockQuote> -> </blockQuote> ^
|
|
|
// <blockBlock> -> <blockBlock> |
|
|
// <blockBlock> -> <blockBlock> |
|
|
|
// <paragraph>]bar</paragraph> -> ] ---
|
|
// <paragraph>]bar</paragraph> -> ] ---
|
|
|
// </blockBlock> -> </blockBlock>
|
|
// </blockBlock> -> </blockBlock>
|
|
|
|
|
+ //
|
|
|
writer.insert( endElement, startPosition );
|
|
writer.insert( endElement, startPosition );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Merge two siblings (nodes on sides of startPosition):
|
|
// Merge two siblings (nodes on sides of startPosition):
|
|
|
|
|
+ //
|
|
|
// <blockQuote> -> <blockQuote>
|
|
// <blockQuote> -> <blockQuote>
|
|
|
// <heading1>foo</heading1>[<paragraph>bar</paragraph> -> <heading1>foo[bar</heading1>
|
|
// <heading1>foo</heading1>[<paragraph>bar</paragraph> -> <heading1>foo[bar</heading1>
|
|
|
// </blockQuote> -> </blockQuote>
|
|
// </blockQuote> -> </blockQuote>
|
|
@@ -271,12 +274,14 @@ function mergeBranchesLeft( writer, startPosition, endPosition, commonAncestor )
|
|
|
writer.merge( startPosition );
|
|
writer.merge( startPosition );
|
|
|
|
|
|
|
|
// Remove empty end ancestors:
|
|
// Remove empty end ancestors:
|
|
|
|
|
+ //
|
|
|
// <blockQuote> -> <blockQuote>
|
|
// <blockQuote> -> <blockQuote>
|
|
|
// <heading1>foo[bar</heading1> -> <heading1>foo[bar</heading1>
|
|
// <heading1>foo[bar</heading1> -> <heading1>foo[bar</heading1>
|
|
|
// </blockQuote> -> </blockQuote>
|
|
// </blockQuote> -> </blockQuote>
|
|
|
// <blockBlock> ->
|
|
// <blockBlock> ->
|
|
|
// ] -> ]
|
|
// ] -> ]
|
|
|
// </blockBlock> ->
|
|
// </blockBlock> ->
|
|
|
|
|
+ //
|
|
|
while ( endPosition.parent.isEmpty ) {
|
|
while ( endPosition.parent.isEmpty ) {
|
|
|
const parentToRemove = endPosition.parent;
|
|
const parentToRemove = endPosition.parent;
|
|
|
|
|
|
|
@@ -306,6 +311,7 @@ function mergeBranchesLeft( writer, startPosition, endPosition, commonAncestor )
|
|
|
// <blockBlock> -> [<blockBlock> v
|
|
// <blockBlock> -> [<blockBlock> v
|
|
|
// <paragraph>]bar</paragraph> -> <paragraph>foo]bar</paragraph>
|
|
// <paragraph>]bar</paragraph> -> <paragraph>foo]bar</paragraph>
|
|
|
// </blockBlock> -> </blockBlock>
|
|
// </blockBlock> -> </blockBlock>
|
|
|
|
|
+//
|
|
|
function mergeBranchesRight( writer, startPosition, endPosition, commonAncestor ) {
|
|
function mergeBranchesRight( writer, startPosition, endPosition, commonAncestor ) {
|
|
|
const startElement = startPosition.parent;
|
|
const startElement = startPosition.parent;
|
|
|
const endElement = endPosition.parent;
|
|
const endElement = endPosition.parent;
|
|
@@ -321,22 +327,26 @@ function mergeBranchesRight( writer, startPosition, endPosition, commonAncestor
|
|
|
|
|
|
|
|
// Move startElement just before endElement if they aren't siblings.
|
|
// Move startElement just before endElement if they aren't siblings.
|
|
|
if ( !endPosition.isEqual( startPosition ) ) {
|
|
if ( !endPosition.isEqual( startPosition ) ) {
|
|
|
|
|
+ //
|
|
|
// <blockQuote> -> <blockQuote>
|
|
// <blockQuote> -> <blockQuote>
|
|
|
// <heading1>foo[</heading1> -> [ ---
|
|
// <heading1>foo[</heading1> -> [ ---
|
|
|
// </blockQuote> -> </blockQuote> |
|
|
// </blockQuote> -> </blockQuote> |
|
|
|
// <blockBlock> -> <blockBlock> v
|
|
// <blockBlock> -> <blockBlock> v
|
|
|
// <paragraph>]bar</paragraph> -> <heading1>foo</heading1>]<paragraph>bar</paragraph>
|
|
// <paragraph>]bar</paragraph> -> <heading1>foo</heading1>]<paragraph>bar</paragraph>
|
|
|
// </blockBlock> -> </blockBlock>
|
|
// </blockBlock> -> </blockBlock>
|
|
|
|
|
+ //
|
|
|
writer.insert( startElement, endPosition );
|
|
writer.insert( startElement, endPosition );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Remove empty end ancestors:
|
|
// Remove empty end ancestors:
|
|
|
|
|
+ //
|
|
|
// <blockQuote> ->
|
|
// <blockQuote> ->
|
|
|
// [ -> [
|
|
// [ -> [
|
|
|
// </blockQuote> ->
|
|
// </blockQuote> ->
|
|
|
// <blockBlock> -> <blockBlock>
|
|
// <blockBlock> -> <blockBlock>
|
|
|
// <heading1>foo</heading1>]<paragraph>bar</paragraph> -> <heading1>foo</heading1>]<paragraph>bar</paragraph>
|
|
// <heading1>foo</heading1>]<paragraph>bar</paragraph> -> <heading1>foo</heading1>]<paragraph>bar</paragraph>
|
|
|
// </blockBlock> -> </blockBlock>
|
|
// </blockBlock> -> </blockBlock>
|
|
|
|
|
+ //
|
|
|
while ( startPosition.parent.isEmpty ) {
|
|
while ( startPosition.parent.isEmpty ) {
|
|
|
const parentToRemove = startPosition.parent;
|
|
const parentToRemove = startPosition.parent;
|
|
|
|
|
|