|
| 1 | +(function() { |
| 2 | + "use strict"; |
| 3 | + |
| 4 | + namespace = "widget_"; |
| 5 | + |
| 6 | + function makeLineWidget(cm, line, height, options) { |
| 7 | + var widgetEl = document.createElement('div'); |
| 8 | + widgetEl.style.height = height + 'px'; |
| 9 | + widgetEl.textContent = 'dummy text'; |
| 10 | + |
| 11 | + return { |
| 12 | + el : widgetEl, |
| 13 | + widget : cm.addLineWidget(line, widgetEl, options || {}) |
| 14 | + }; |
| 15 | + } |
| 16 | + |
| 17 | + function testWidgetsAffectDocumentHeight(tagline, docLines, widgetLine, viewportLine) { |
| 18 | + var initialHeight = 100; |
| 19 | + var changedHeight = 150; |
| 20 | + |
| 21 | + testCM('lineWidgetDocHeight_' + tagline, function(cm) { |
| 22 | + var startingDocHeight = cm.getScrollInfo().height; |
| 23 | + |
| 24 | + if (viewportLine != null) { |
| 25 | + cm.scrollIntoView({ line : viewportLine, ch: 0 }); |
| 26 | + } |
| 27 | + |
| 28 | + var widgetInfo = makeLineWidget(cm, widgetLine, initialHeight); |
| 29 | + eq(startingDocHeight + initialHeight, cm.getScrollInfo().height, 'addLineWidget(): widget height should be added to document height.'); |
| 30 | + |
| 31 | + widgetInfo.el.style.height = changedHeight + 'px'; |
| 32 | + widgetInfo.widget.changed(); |
| 33 | + eq(startingDocHeight + changedHeight, cm.getScrollInfo().height, 'widget.changed(): widget height should be updated in document height.'); |
| 34 | + |
| 35 | + widgetInfo.widget.clear(); |
| 36 | + eq(startingDocHeight, cm.getScrollInfo().height, 'widget.clear(): widget height should be removed from document height.'); |
| 37 | + }, { |
| 38 | + value : new Array(docLines + 1).join('blah\n') |
| 39 | + }) |
| 40 | + } |
| 41 | + |
| 42 | + testWidgetsAffectDocumentHeight('shortFile_WidgetAtTop', 50, 0); |
| 43 | + testWidgetsAffectDocumentHeight('shortFile_WidgetAtBottom', 50, 49); |
| 44 | + |
| 45 | + testWidgetsAffectDocumentHeight('longFile_WidgetAtTop', 1000, 1); |
| 46 | + testWidgetsAffectDocumentHeight('longFile_WidgetAtMiddle', 1000, 500); |
| 47 | + testWidgetsAffectDocumentHeight('longFile_WidgetAtBottom', 1000, 1000); |
| 48 | + |
| 49 | + testWidgetsAffectDocumentHeight('longFile_WidgetAtTop_viewportBottom', 1000, 0, 999); |
| 50 | + testWidgetsAffectDocumentHeight('longFile_WidgetAtMiddle_viewportBottom', 1000, 499, 999); |
| 51 | + testWidgetsAffectDocumentHeight('longFile_WidgetAtBottom_viewportBottom', 1000, 999, 999); |
| 52 | + |
| 53 | +})(); |
0 commit comments