From 17f89e9bd352f866a60e32dadbd7d60085310adf Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Thu, 2 Jul 2015 20:30:43 +0800 Subject: Optimized syncscroll.js buildMap, make it faster --- public/js/syncscroll.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js index 2ed3ff03..a9eafe48 100644 --- a/public/js/syncscroll.js +++ b/public/js/syncscroll.js @@ -199,6 +199,8 @@ function buildMapInner(syncBack) { acc = 0; var lines = editor.getValue().split('\n'); + var lineHeight = parseFloat(sourceLikeDiv.css('line-height')); + var div = sourceLikeDiv[0]; for (i = 0; i < lines.length; i++) { var str = lines[i]; var h, lh; @@ -211,9 +213,8 @@ function buildMapInner(syncBack) { } sourceLikeDiv.text(str); - h = parseFloat(sourceLikeDiv.css('height')); - lh = parseFloat(sourceLikeDiv.css('line-height')); - acc += Math.round(h / lh); + h = parseFloat(div.clientHeight); + acc += Math.round(h / lineHeight); } sourceLikeDiv.remove(); _lineHeightMap.push(acc); @@ -260,7 +261,7 @@ function buildMapInner(syncBack) { scrollMap = _scrollMap; lineHeightMap = _lineHeightMap; - if(loaded && syncBack) + if (loaded && syncBack) syncScrollToView(); } -- cgit v1.2.3