diff options
author | Wu Cheng-Han | 2015-07-02 20:30:43 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2015-07-02 20:30:43 +0800 |
commit | 17f89e9bd352f866a60e32dadbd7d60085310adf (patch) | |
tree | c4e1d2684a4c0794469600ed147bf376b812d069 /public/js | |
parent | f8ef5341c70a2aee6b22751eebc500ed24c7825f (diff) |
Optimized syncscroll.js buildMap, make it faster
Diffstat (limited to '')
-rw-r--r-- | public/js/syncscroll.js | 9 |
1 files 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(); } |