mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -05:00
Fix copying inline styles when selection not on boundary.
Resolves #219 properly this time.
This commit is contained in:
parent
9aacad6e3c
commit
26b71dee8e
3 changed files with 27 additions and 33 deletions
|
@ -2118,7 +2118,7 @@ var onCopy = function ( event ) {
|
||||||
var range = this.getSelection();
|
var range = this.getSelection();
|
||||||
var node = this.createElement( 'div' );
|
var node = this.createElement( 'div' );
|
||||||
var root = this._root;
|
var root = this._root;
|
||||||
var startBlock, contents, parent, newContents;
|
var startBlock, endBlock, copyRoot, contents, parent, newContents;
|
||||||
|
|
||||||
// Edge only seems to support setting plain text as of 2016-03-11.
|
// Edge only seems to support setting plain text as of 2016-03-11.
|
||||||
// Mobile Safari flat out doesn't work:
|
// Mobile Safari flat out doesn't work:
|
||||||
|
@ -2126,23 +2126,20 @@ var onCopy = function ( event ) {
|
||||||
if ( !isEdge && !isIOS && clipboardData ) {
|
if ( !isEdge && !isIOS && clipboardData ) {
|
||||||
range = range.cloneRange();
|
range = range.cloneRange();
|
||||||
startBlock = getStartBlockOfRange( range, root );
|
startBlock = getStartBlockOfRange( range, root );
|
||||||
if ( startBlock === getEndBlockOfRange( range, root ) ) {
|
endBlock = getEndBlockOfRange( range, root );
|
||||||
// Copy all inline formatting, but that's it.
|
copyRoot = ( startBlock === endBlock ) ? startBlock : root;
|
||||||
moveRangeBoundariesDownTree( range );
|
moveRangeBoundariesDownTree( range );
|
||||||
moveRangeBoundariesUpTree( range, startBlock );
|
moveRangeBoundariesUpTree( range, copyRoot );
|
||||||
contents = range.cloneContents();
|
contents = range.cloneContents();
|
||||||
} else {
|
parent = range.commonAncestorContainer;
|
||||||
moveRangeBoundariesUpTree( range, root );
|
while ( parent && parent !== copyRoot ) {
|
||||||
contents = range.cloneContents();
|
newContents = parent.cloneNode( false );
|
||||||
parent = range.commonAncestorContainer;
|
newContents.appendChild( contents );
|
||||||
while ( parent && parent !== root ) {
|
contents = newContents;
|
||||||
newContents = parent.cloneNode( false );
|
parent = parent.parentNode;
|
||||||
newContents.appendChild( contents );
|
|
||||||
contents = newContents;
|
|
||||||
parent = parent.parentNode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
node.appendChild( contents );
|
node.appendChild( contents );
|
||||||
|
|
||||||
clipboardData.setData( 'text/html', node.innerHTML );
|
clipboardData.setData( 'text/html', node.innerHTML );
|
||||||
clipboardData.setData( 'text/plain',
|
clipboardData.setData( 'text/plain',
|
||||||
node.innerText || node.textContent );
|
node.innerText || node.textContent );
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -39,7 +39,7 @@ var onCopy = function ( event ) {
|
||||||
var range = this.getSelection();
|
var range = this.getSelection();
|
||||||
var node = this.createElement( 'div' );
|
var node = this.createElement( 'div' );
|
||||||
var root = this._root;
|
var root = this._root;
|
||||||
var startBlock, contents, parent, newContents;
|
var startBlock, endBlock, copyRoot, contents, parent, newContents;
|
||||||
|
|
||||||
// Edge only seems to support setting plain text as of 2016-03-11.
|
// Edge only seems to support setting plain text as of 2016-03-11.
|
||||||
// Mobile Safari flat out doesn't work:
|
// Mobile Safari flat out doesn't work:
|
||||||
|
@ -47,23 +47,20 @@ var onCopy = function ( event ) {
|
||||||
if ( !isEdge && !isIOS && clipboardData ) {
|
if ( !isEdge && !isIOS && clipboardData ) {
|
||||||
range = range.cloneRange();
|
range = range.cloneRange();
|
||||||
startBlock = getStartBlockOfRange( range, root );
|
startBlock = getStartBlockOfRange( range, root );
|
||||||
if ( startBlock === getEndBlockOfRange( range, root ) ) {
|
endBlock = getEndBlockOfRange( range, root );
|
||||||
// Copy all inline formatting, but that's it.
|
copyRoot = ( startBlock === endBlock ) ? startBlock : root;
|
||||||
moveRangeBoundariesDownTree( range );
|
moveRangeBoundariesDownTree( range );
|
||||||
moveRangeBoundariesUpTree( range, startBlock );
|
moveRangeBoundariesUpTree( range, copyRoot );
|
||||||
contents = range.cloneContents();
|
contents = range.cloneContents();
|
||||||
} else {
|
parent = range.commonAncestorContainer;
|
||||||
moveRangeBoundariesUpTree( range, root );
|
while ( parent && parent !== copyRoot ) {
|
||||||
contents = range.cloneContents();
|
newContents = parent.cloneNode( false );
|
||||||
parent = range.commonAncestorContainer;
|
newContents.appendChild( contents );
|
||||||
while ( parent && parent !== root ) {
|
contents = newContents;
|
||||||
newContents = parent.cloneNode( false );
|
parent = parent.parentNode;
|
||||||
newContents.appendChild( contents );
|
|
||||||
contents = newContents;
|
|
||||||
parent = parent.parentNode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
node.appendChild( contents );
|
node.appendChild( contents );
|
||||||
|
|
||||||
clipboardData.setData( 'text/html', node.innerHTML );
|
clipboardData.setData( 'text/html', node.innerHTML );
|
||||||
clipboardData.setData( 'text/plain',
|
clipboardData.setData( 'text/plain',
|
||||||
node.innerText || node.textContent );
|
node.innerText || node.textContent );
|
||||||
|
|
Loading…
Reference in a new issue