Fixed weird behavior in scroll link extension

This commit is contained in:
benweet 2014-03-19 23:06:17 +00:00
parent d445ccfec8
commit 3f8d96eb48

View File

@ -17,7 +17,7 @@ define([
scrollLink.onSectionsCreated = function(sectionListParam) { scrollLink.onSectionsCreated = function(sectionListParam) {
sectionList = sectionListParam; sectionList = sectionListParam;
}; };
var offsetBegin = 0; var offsetBegin = 0;
scrollLink.onMarkdownTrim = function(offsetBeginParam) { scrollLink.onMarkdownTrim = function(offsetBeginParam) {
offsetBegin = offsetBeginParam; offsetBegin = offsetBeginParam;
@ -70,7 +70,7 @@ define([
} }
addTextareaSection(sectionText); addTextareaSection(sectionText);
}); });
// Apply a coef to manage divergence in some browsers // Apply a coef to manage divergence in some browsers
var theoricalHeight = _.last(mdSectionList).endOffset; var theoricalHeight = _.last(mdSectionList).endOffset;
var realHeight = $textareaElt[0].scrollHeight; var realHeight = $textareaElt[0].scrollHeight;
@ -183,8 +183,8 @@ define([
lastPreviewScrollTop = previewScrollTop; lastPreviewScrollTop = previewScrollTop;
return; return;
} }
$previewElt.stop('scrollLinkFx', true).animate({ scrollingHelper.stop('scrollLinkFx', true).css('value', 0).animate({
scrollTop: destScrollTop value: destScrollTop - previewScrollTop
}, { }, {
easing: 'easeOutSine', easing: 'easeOutSine',
duration: 200, duration: 200,
@ -192,11 +192,12 @@ define([
step: function(now) { step: function(now) {
isPreviewMoving = true; isPreviewMoving = true;
lastPreviewScrollTop = previewScrollTop + now; lastPreviewScrollTop = previewScrollTop + now;
$previewElt.scrollTop(lastPreviewScrollTop);
}, },
done: function() { done: function() {
setTimeout(function() { _.defer(function() {
isPreviewMoving = false; isPreviewMoving = false;
}, 100); });
}, },
}).dequeue('scrollLinkFx'); }).dequeue('scrollLinkFx');
} }
@ -227,43 +228,24 @@ define([
lastEditorScrollTop = editorScrollTop; lastEditorScrollTop = editorScrollTop;
return; return;
} }
if(window.lightMode) { scrollingHelper.stop('scrollLinkFx', true).css('value', 0).animate({
$textareaElt.stop('scrollLinkFx', true).animate({ value: destScrollTop - editorScrollTop
scrollTop: destScrollTop }, {
}, { easing: 'easeOutSine',
easing: 'easeOutSine', duration: 200,
duration: 200, queue: 'scrollLinkFx',
queue: 'scrollLinkFx', step: function(now) {
step: function(now) { isEditorMoving = true;
isEditorMoving = true; lastEditorScrollTop = editorScrollTop + now;
lastEditorScrollTop = editorScrollTop + now; window.lightMode || aceEditor.session.setScrollTop(lastEditorScrollTop);
}, window.lightMode && $textareaElt.scrollTop(lastEditorScrollTop);
done: function() { },
setTimeout(function() { done: function() {
isEditorMoving = false; _.defer(function() {
}, 100); isEditorMoving = false;
}, });
}).dequeue('scrollLinkFx'); },
} }).dequeue('scrollLinkFx');
else {
scrollingHelper.stop('scrollLinkFx', true).css('value', 0).animate({
value: destScrollTop - editorScrollTop
}, {
easing: 'easeOutSine',
duration: 200,
queue: 'scrollLinkFx',
step: function(now) {
isEditorMoving = true;
lastEditorScrollTop = editorScrollTop + now;
aceEditor.session.setScrollTop(lastEditorScrollTop);
},
done: function() {
_.defer(function() {
isEditorMoving = false;
});
},
}).dequeue('scrollLinkFx');
}
} }
}, 100); }, 100);
@ -331,4 +313,4 @@ define([
}; };
return scrollLink; return scrollLink;
}); });