0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Prevent scroll move to top when focus method invoked

In webkit, if contenteditable element focus method have been invoked when another input element has focus,
contenteditable scroll to top automatically so we need scroll it back
This commit is contained in:
Sungho Kim 2016-08-24 17:46:44 +09:00
parent 25ff83455e
commit cbc959067a

View file

@ -624,8 +624,16 @@ proto._updatePathOnEvent = function () {
// --- Focus --- // --- Focus ---
proto.focus = function () { proto.focus = function () {
var scrollTop = this.scrollTop();
this._root.focus(); this._root.focus();
// In webkit, if contenteditable element focus method have been invoked when another input element has focus,
// contenteditable scroll to top automatically so we need scroll it back
if (scrollTop !== this.scrollTop()) {
this.scrollTop(scrollTop);
}
if ( isIE ) { if ( isIE ) {
this.fireEvent( 'focus' ); this.fireEvent( 'focus' );
} }
@ -643,6 +651,16 @@ proto.blur = function () {
return this; return this;
}; };
// --- scrollTop ---
proto.scrollTop = function(value) {
if (value) {
this._root.scrollTop = value;
}
return this._root.scrollTop;
}
// --- Bookmarking --- // --- Bookmarking ---
var startSelectionId = 'squire-selection-start'; var startSelectionId = 'squire-selection-start';