mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 23:40:35 -05:00
Use helper fn to get start block in paste handler.
Neater and deals with the edge cases.
This commit is contained in:
parent
597024eecb
commit
c0e33843fb
3 changed files with 7 additions and 15 deletions
|
@ -2646,18 +2646,14 @@ proto._onPaste = function ( event ) {
|
||||||
startOffset = range.startOffset,
|
startOffset = range.startOffset,
|
||||||
endContainer = range.endContainer,
|
endContainer = range.endContainer,
|
||||||
endOffset = range.endOffset,
|
endOffset = range.endOffset,
|
||||||
startBlock = startContainer.nodeType === TEXT_NODE ?
|
startBlock = getStartBlockOfRange( range );
|
||||||
startContainer : startContainer.childNodes[ startOffset ];
|
|
||||||
|
|
||||||
// We need to position the pasteArea in the visible portion of the screen
|
// We need to position the pasteArea in the visible portion of the screen
|
||||||
// to stop the browser auto-scrolling.
|
// to stop the browser auto-scrolling.
|
||||||
while ( isInline( startBlock ) ) {
|
|
||||||
startBlock = startBlock.parentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pasteArea = this.createElement( 'DIV', {
|
var pasteArea = this.createElement( 'DIV', {
|
||||||
style: 'position: absolute; overflow: hidden; top:' +
|
style: 'position: absolute; overflow: hidden; top:' +
|
||||||
( body.scrollTop + startBlock.getBoundingClientRect().top ) +
|
( body.scrollTop +
|
||||||
|
( startBlock ? startBlock.getBoundingClientRect().top : 0 ) ) +
|
||||||
'px; left: 0; width: 1px; height: 1px;'
|
'px; left: 0; width: 1px; height: 1px;'
|
||||||
});
|
});
|
||||||
body.appendChild( pasteArea );
|
body.appendChild( pasteArea );
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1529,18 +1529,14 @@ proto._onPaste = function ( event ) {
|
||||||
startOffset = range.startOffset,
|
startOffset = range.startOffset,
|
||||||
endContainer = range.endContainer,
|
endContainer = range.endContainer,
|
||||||
endOffset = range.endOffset,
|
endOffset = range.endOffset,
|
||||||
startBlock = startContainer.nodeType === TEXT_NODE ?
|
startBlock = getStartBlockOfRange( range );
|
||||||
startContainer : startContainer.childNodes[ startOffset ];
|
|
||||||
|
|
||||||
// We need to position the pasteArea in the visible portion of the screen
|
// We need to position the pasteArea in the visible portion of the screen
|
||||||
// to stop the browser auto-scrolling.
|
// to stop the browser auto-scrolling.
|
||||||
while ( isInline( startBlock ) ) {
|
|
||||||
startBlock = startBlock.parentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pasteArea = this.createElement( 'DIV', {
|
var pasteArea = this.createElement( 'DIV', {
|
||||||
style: 'position: absolute; overflow: hidden; top:' +
|
style: 'position: absolute; overflow: hidden; top:' +
|
||||||
( body.scrollTop + startBlock.getBoundingClientRect().top ) +
|
( body.scrollTop +
|
||||||
|
( startBlock ? startBlock.getBoundingClientRect().top : 0 ) ) +
|
||||||
'px; left: 0; width: 1px; height: 1px;'
|
'px; left: 0; width: 1px; height: 1px;'
|
||||||
});
|
});
|
||||||
body.appendChild( pasteArea );
|
body.appendChild( pasteArea );
|
||||||
|
|
Loading…
Reference in a new issue