0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-31 11:54:03 -05:00

Add scrollPointIntoView event for integrations.

This commit is contained in:
Neil Jenkins 2015-12-09 17:29:47 +11:00
parent 9ccf765ba8
commit 8b183c6ef6
3 changed files with 28 additions and 12 deletions

View file

@ -2424,22 +2424,30 @@ proto._createRange =
}; };
proto.scrollRangeIntoView = function ( range ) { proto.scrollRangeIntoView = function ( range ) {
var win = this._win; // Get the bounding rect
var top = range.getBoundingClientRect().top; var rect = range.getBoundingClientRect();
var height = win.innerHeight;
var node, parent; var node, parent;
if ( !top ) { if ( !rect.top ) {
node = this._doc.createElement( 'SPAN' ); node = this._doc.createElement( 'SPAN' );
range = range.cloneRange(); range = range.cloneRange();
insertNodeInRange( range, node ); insertNodeInRange( range, node );
top = node.getBoundingClientRect().top; rect = node.getBoundingClientRect();
parent = node.parentNode; parent = node.parentNode;
parent.removeChild( node ); parent.removeChild( node );
parent.normalize(); parent.normalize();
} }
// Then check and scroll
var win = this._win;
var height = win.innerHeight;
var top = rect.top;
if ( top > height ) { if ( top > height ) {
win.scrollBy( 0, top - height + 20 ); win.scrollBy( 0, top - height + 20 );
} }
// And fire event for integrations to use
this.fireEvent( 'scrollPointIntoView', {
x: rect.left,
y: top
});
}; };
proto._moveCursorTo = function ( toStart ) { proto._moveCursorTo = function ( toStart ) {

File diff suppressed because one or more lines are too long

View file

@ -302,22 +302,30 @@ proto._createRange =
}; };
proto.scrollRangeIntoView = function ( range ) { proto.scrollRangeIntoView = function ( range ) {
var win = this._win; // Get the bounding rect
var top = range.getBoundingClientRect().top; var rect = range.getBoundingClientRect();
var height = win.innerHeight;
var node, parent; var node, parent;
if ( !top ) { if ( !rect.top ) {
node = this._doc.createElement( 'SPAN' ); node = this._doc.createElement( 'SPAN' );
range = range.cloneRange(); range = range.cloneRange();
insertNodeInRange( range, node ); insertNodeInRange( range, node );
top = node.getBoundingClientRect().top; rect = node.getBoundingClientRect();
parent = node.parentNode; parent = node.parentNode;
parent.removeChild( node ); parent.removeChild( node );
parent.normalize(); parent.normalize();
} }
// Then check and scroll
var win = this._win;
var height = win.innerHeight;
var top = rect.top;
if ( top > height ) { if ( top > height ) {
win.scrollBy( 0, top - height + 20 ); win.scrollBy( 0, top - height + 20 );
} }
// And fire event for integrations to use
this.fireEvent( 'scrollPointIntoView', {
x: rect.left,
y: top
});
}; };
proto._moveCursorTo = function ( toStart ) { proto._moveCursorTo = function ( toStart ) {