(changes, suppressCallback)
| 927 | // determine which DOM updates have to be made, and makes the |
| 928 | // updates. |
| 929 | function updateDisplay(changes, suppressCallback) { |
| 930 | if (!scroller.clientWidth) { |
| 931 | showingFrom = showingTo = displayOffset = 0; |
| 932 | return; |
| 933 | } |
| 934 | // Compute the new visible window |
| 935 | var visible = visibleLines(); |
| 936 | // Bail out if the visible area is already rendered and nothing changed. |
| 937 | if (changes !== true && changes.length == 0 && visible.from > showingFrom && visible.to < showingTo) return; |
| 938 | var from = Math.max(visible.from - 100, 0), to = Math.min(doc.size, visible.to + 100); |
| 939 | if (showingFrom < from && from - showingFrom < 20) from = showingFrom; |
| 940 | if (showingTo > to && showingTo - to < 20) to = Math.min(doc.size, showingTo); |
| 941 | |
| 942 | // Create a range of theoretically intact lines, and punch holes |
| 943 | // in that using the change info. |
| 944 | var intact = changes === true ? [] : |
| 945 | computeIntact([{from: showingFrom, to: showingTo, domStart: 0}], changes); |
| 946 | // Clip off the parts that won't be visible |
| 947 | var intactLines = 0; |
| 948 | for (var i = 0; i < intact.length; ++i) { |
| 949 | var range = intact[i]; |
| 950 | if (range.from < from) {range.domStart += (from - range.from); range.from = from;} |
| 951 | if (range.to > to) range.to = to; |
| 952 | if (range.from >= range.to) intact.splice(i--, 1); |
| 953 | else intactLines += range.to - range.from; |
| 954 | } |
| 955 | if (intactLines == to - from && from == showingFrom && to == showingTo) return; |
| 956 | intact.sort(function(a, b) {return a.domStart - b.domStart;}); |
| 957 | |
| 958 | var th = textHeight(), gutterDisplay = gutter.style.display; |
| 959 | lineDiv.style.display = "none"; |
| 960 | patchDisplay(from, to, intact); |
| 961 | lineDiv.style.display = gutter.style.display = ""; |
| 962 | |
| 963 | // Position the mover div to align with the lines it's supposed |
| 964 | // to be showing (which will cover the visible display) |
| 965 | var different = from != showingFrom || to != showingTo || lastSizeC != scroller.clientHeight + th; |
| 966 | // This is just a bogus formula that detects when the editor is |
| 967 | // resized or the font size changes. |
| 968 | if (different) lastSizeC = scroller.clientHeight + th; |
| 969 | showingFrom = from; showingTo = to; |
| 970 | displayOffset = heightAtLine(doc, from); |
| 971 | mover.style.top = (displayOffset * th) + "px"; |
| 972 | if (scroller.clientHeight) |
| 973 | code.style.height = (doc.height * th + 2 * paddingTop()) + "px"; |
| 974 | |
| 975 | // Since this is all rather error prone, it is honoured with the |
| 976 | // only assertion in the whole file. |
| 977 | if (lineDiv.childNodes.length != showingTo - showingFrom) |
| 978 | throw new Error("BAD PATCH! " + JSON.stringify(intact) + " size=" + (showingTo - showingFrom) + |
| 979 | " nodes=" + lineDiv.childNodes.length); |
| 980 | |
| 981 | function checkHeights() { |
| 982 | maxWidth = scroller.clientWidth; |
| 983 | var curNode = lineDiv.firstChild, heightChanged = false; |
| 984 | doc.iter(showingFrom, showingTo, function(line) { |
| 985 | if (!line.hidden) { |
| 986 | var height = Math.round(curNode.offsetHeight / th) || 1; |
no test coverage detected