MCPcopy Create free account
hub / github.com/TextGeneratorio/text-generator.io / highlightLine

Function highlightLine

static/libs/codemirror.js:1534–1577  ·  view source on GitHub ↗
(cm, line, context, forceToEnd)

Source from the content-addressed store, hash-verified

1532// style strings), which is used to highlight the tokens on the
1533// line.
1534function highlightLine(cm, line, context, forceToEnd) {
1535 // A styles array always starts with a number identifying the
1536 // mode/overlays that it is based on (for easy invalidation).
1537 var st = [cm.state.modeGen], lineClasses = {};
1538 // Compute the base array of styles
1539 runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); },
1540 lineClasses, forceToEnd);
1541 var state = context.state;
1542
1543 // Run overlays, adjust style array.
1544 var loop = function ( o ) {
1545 context.baseTokens = st;
1546 var overlay = cm.state.overlays[o], i = 1, at = 0;
1547 context.state = true;
1548 runMode(cm, line.text, overlay.mode, context, function (end, style) {
1549 var start = i;
1550 // Ensure there's a token end at the current position, and that i points at it
1551 while (at < end) {
1552 var i_end = st[i];
1553 if (i_end > end)
1554 { st.splice(i, 1, end, st[i+1], i_end); }
1555 i += 2;
1556 at = Math.min(end, i_end);
1557 }
1558 if (!style) { return }
1559 if (overlay.opaque) {
1560 st.splice(start, i - start, end, "overlay " + style);
1561 i = start + 2;
1562 } else {
1563 for (; start < i; start += 2) {
1564 var cur = st[start+1];
1565 st[start+1] = (cur ? cur + " " : "") + "overlay " + style;
1566 }
1567 }
1568 }, lineClasses);
1569 context.state = state;
1570 context.baseTokens = null;
1571 context.baseTokenPos = 1;
1572 };
1573
1574 for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
1575
1576 return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
1577}
1578
1579function getLineStyles(cm, line, updateFrontier) {
1580 if (!line.styles || line.styles[0] != cm.state.modeGen) {

Callers 2

getLineStylesFunction · 0.85
highlightWorkerFunction · 0.85

Calls 2

runModeFunction · 0.85
loopFunction · 0.85

Tested by

no test coverage detected