MCPcopy Create free account
hub / github.com/breck7/scroll / highlightLine

Function highlightLine

external/.scrollLibs.js:2478–2543  ·  view source on GitHub ↗
(cm, line, context, forceToEnd)

Source from the content-addressed store, hash-verified

2476 // style strings), which is used to highlight the tokens on the
2477 // line.
2478 function highlightLine(cm, line, context, forceToEnd) {
2479 // A styles array always starts with a number identifying the
2480 // mode/overlays that it is based on (for easy invalidation).
2481 var st = [cm.state.modeGen],
2482 lineClasses = {}
2483 // Compute the base array of styles
2484 runMode(
2485 cm,
2486 line.text,
2487 cm.doc.mode,
2488 context,
2489 function (end, style) {
2490 return st.push(end, style)
2491 },
2492 lineClasses,
2493 forceToEnd
2494 )
2495 var state = context.state
2496
2497 // Run overlays, adjust style array.
2498 var loop = function (o) {
2499 context.baseTokens = st
2500 var overlay = cm.state.overlays[o],
2501 i = 1,
2502 at = 0
2503 context.state = true
2504 runMode(
2505 cm,
2506 line.text,
2507 overlay.mode,
2508 context,
2509 function (end, style) {
2510 var start = i
2511 // Ensure there's a token end at the current position, and that i points at it
2512 while (at < end) {
2513 var i_end = st[i]
2514 if (i_end > end) {
2515 st.splice(i, 1, end, st[i + 1], i_end)
2516 }
2517 i += 2
2518 at = Math.min(end, i_end)
2519 }
2520 if (!style) {
2521 return
2522 }
2523 if (overlay.opaque) {
2524 st.splice(start, i - start, end, "overlay " + style)
2525 i = start + 2
2526 } else {
2527 for (; start < i; start += 2) {
2528 var cur = st[start + 1]
2529 st[start + 1] = (cur ? cur + " " : "") + "overlay " + style
2530 }
2531 }
2532 },
2533 lineClasses
2534 )
2535 context.state = state

Callers 2

getLineStylesFunction · 0.85
highlightWorkerFunction · 0.85

Calls 2

runModeFunction · 0.85
loopFunction · 0.85

Tested by

no test coverage detected