Optimized syncscroll.js buildMap, make it faster

This commit is contained in:
Wu Cheng-Han 2015-07-02 20:30:43 +08:00
parent f8ef5341c7
commit 17f89e9bd3
1 changed files with 5 additions and 4 deletions

View File

@ -199,6 +199,8 @@ function buildMapInner(syncBack) {
acc = 0; acc = 0;
var lines = editor.getValue().split('\n'); var lines = editor.getValue().split('\n');
var lineHeight = parseFloat(sourceLikeDiv.css('line-height'));
var div = sourceLikeDiv[0];
for (i = 0; i < lines.length; i++) { for (i = 0; i < lines.length; i++) {
var str = lines[i]; var str = lines[i];
var h, lh; var h, lh;
@ -211,9 +213,8 @@ function buildMapInner(syncBack) {
} }
sourceLikeDiv.text(str); sourceLikeDiv.text(str);
h = parseFloat(sourceLikeDiv.css('height')); h = parseFloat(div.clientHeight);
lh = parseFloat(sourceLikeDiv.css('line-height')); acc += Math.round(h / lineHeight);
acc += Math.round(h / lh);
} }
sourceLikeDiv.remove(); sourceLikeDiv.remove();
_lineHeightMap.push(acc); _lineHeightMap.push(acc);