MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / updateDisplayInner

Function updateDisplayInner

static/js/codemirror/codemirror.js:413–523  ·  view source on GitHub ↗
(cm, changes, viewPort)

Source from the content-addressed store, hash-verified

411 // determine which DOM updates have to be made, and makes the
412 // updates.
413 function updateDisplayInner(cm, changes, viewPort) {
414 var display = cm.display, doc = cm.doc;
415 if (!display.wrapper.clientWidth) {
416 display.showingFrom = display.showingTo = doc.first;
417 display.viewOffset = 0;
418 return;
419 }
420
421 // Compute the new visible window
422 // If scrollTop is specified, use that to determine which lines
423 // to render instead of the current scrollbar position.
424 var visible = visibleLines(display, doc, viewPort);
425 // Bail out if the visible area is already rendered and nothing changed.
426 if (changes.length == 0 &&
427 visible.from > display.showingFrom && visible.to < display.showingTo)
428 return;
429
430 if (maybeUpdateLineNumberWidth(cm))
431 changes = [{from: doc.first, to: doc.first + doc.size}];
432 var gutterW = display.sizer.style.marginLeft = display.gutters.offsetWidth + "px";
433 display.scrollbarH.style.left = cm.options.fixedGutter ? gutterW : "0";
434
435 // Used to determine which lines need their line numbers updated
436 var positionsChangedFrom = Infinity;
437 if (cm.options.lineNumbers)
438 for (var i = 0; i < changes.length; ++i)
439 if (changes[i].diff) { positionsChangedFrom = changes[i].from; break; }
440
441 var end = doc.first + doc.size;
442 var from = Math.max(visible.from - cm.options.viewportMargin, doc.first);
443 var to = Math.min(end, visible.to + cm.options.viewportMargin);
444 if (display.showingFrom < from && from - display.showingFrom < 20) from = Math.max(doc.first, display.showingFrom);
445 if (display.showingTo > to && display.showingTo - to < 20) to = Math.min(end, display.showingTo);
446 if (sawCollapsedSpans) {
447 from = lineNo(visualLine(doc, getLine(doc, from)));
448 while (to < end && lineIsHidden(doc, getLine(doc, to))) ++to;
449 }
450
451 // Create a range of theoretically intact lines, and punch holes
452 // in that using the change info.
453 var intact = [{from: Math.max(display.showingFrom, doc.first),
454 to: Math.min(display.showingTo, end)}];
455 if (intact[0].from >= intact[0].to) intact = [];
456 else intact = computeIntact(intact, changes);
457 // When merged lines are present, we might have to reduce the
458 // intact ranges because changes in continued fragments of the
459 // intact lines do require the lines to be redrawn.
460 if (sawCollapsedSpans)
461 for (var i = 0; i < intact.length; ++i) {
462 var range = intact[i], merged;
463 while (merged = collapsedSpanAtEnd(getLine(doc, range.to - 1))) {
464 var newTo = merged.find().from.line;
465 if (newTo > range.from) range.to = newTo;
466 else { intact.splice(i--, 1); break; }
467 }
468 }
469
470 // Clip off the parts that won't be visible

Callers 1

updateDisplayFunction · 0.85

Calls 15

visibleLinesFunction · 0.85
lineNoFunction · 0.85
visualLineFunction · 0.85
getLineFunction · 0.85
lineIsHiddenFunction · 0.85
computeIntactFunction · 0.85
collapsedSpanAtEndFunction · 0.85
updateViewOffsetFunction · 0.85
patchDisplayFunction · 0.85
startWorkerFunction · 0.85
getRectFunction · 0.85

Tested by

no test coverage detected