MCPcopy Index your code
hub / github.com/midrender/revideo / drawToken

Method drawToken

packages/2d/src/lib/code/CodeCursor.ts:228–375  ·  view source on GitHub ↗
(
    fragment: CodeFragment,
    scope: CodeScope,
    offset: SerializedVector2,
    alpha: number,
  )

Source from the content-addressed store, hash-verified

226 }
227
228 private drawToken(
229 fragment: CodeFragment,
230 scope: CodeScope,
231 offset: SerializedVector2,
232 alpha: number,
233 ) {
234 const progress = unwrap(scope.progress);
235 const currentProgress = this.currentProgress();
236 if (progress > 0) {
237 this.globalProgress.push(progress);
238 }
239
240 const code = progress < 0.5 ? fragment.before : fragment.after;
241
242 let hasOffset = true;
243 let width = 0;
244 let stringLength = 0;
245 let y = 0;
246 for (let i = 0; i < code.content.length; i++) {
247 let color = this.fallbackFill.serialize();
248 let char = code.content.charAt(i);
249 const selection: {before: number | null; after: number | null} = {
250 before: null,
251 after: null,
252 };
253
254 if (char === '\n') {
255 y++;
256 hasOffset = false;
257 width = 0;
258 stringLength = 0;
259 selection.before = null;
260 selection.after = null;
261 continue;
262 }
263
264 const beforeHighlight =
265 this.caches &&
266 this.highlighter?.highlight(this.beforeIndex + i, this.caches.before);
267 const afterHighlight =
268 this.caches &&
269 this.highlighter?.highlight(this.afterIndex + i, this.caches.after);
270
271 const highlight = progress < 0.5 ? beforeHighlight : afterHighlight;
272 if (highlight) {
273 // Handle edge cases where the highlight style changes despite the
274 // content being the same. The code doesn't fade in and out so the color
275 // has to be interpolated to avoid jarring changes.
276 if (
277 fragment.before.content === fragment.after.content &&
278 beforeHighlight?.color !== afterHighlight?.color
279 ) {
280 highlight.color = Color.lerp(
281 beforeHighlight?.color ?? this.fallbackFill,
282 afterHighlight?.color ?? this.fallbackFill,
283 progress,
284 ).serialize();
285 }

Callers 1

drawScopeMethod · 0.95

Calls 7

currentProgressMethod · 0.95
processSelectionMethod · 0.95
unwrapFunction · 0.90
mapFunction · 0.90
serializeMethod · 0.65
highlightMethod · 0.65
lerpMethod · 0.65

Tested by

no test coverage detected