pi-polish 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,7 @@ export default function (pi: ExtensionAPI) {
45
45
  if (!(child instanceof Markdown) || (child as any).defaultTextStyle !== undefined || (child as any)[patched]) continue;
46
46
  const render = child.render.bind(child);
47
47
  child.render = (width: number) => {
48
- const lines: string[] = render(width);
48
+ const lines = [...render(width)];
49
49
  const first = lines.findIndex((l) => l.replace(/\x1b\[[0-9;]*m/g, "").trim());
50
50
  if (first >= 0) lines[first] = markFirstLine(lines[first], REPLY);
51
51
  return lines;
@@ -361,6 +361,7 @@ function withBackground(line: string, spans: Span[], on: string, off: string): s
361
361
  class DiffView implements Component {
362
362
  private highlighted: string[];
363
363
  private palette: Palette;
364
+ private cachedRender?: { width: number; lines: string[] };
364
365
 
365
366
  constructor(
366
367
  private lines: string[],
@@ -403,6 +404,8 @@ class DiffView implements Component {
403
404
  }
404
405
 
405
406
  render(width: number): string[] {
407
+ if (this.cachedRender?.width === width) return this.cachedRender.lines;
408
+
406
409
  const { addedBg, removedBg, addedGutter, removedGutter } = this.palette;
407
410
  const out = this.lines.map((line, i) => {
408
411
  const sign = line[0];
@@ -419,10 +422,13 @@ class DiffView implements Component {
419
422
  return `${bg}${text.replace(/\x1b\[0?m/g, (m) => m + bg)}${pad}${BG_RESET}`;
420
423
  });
421
424
  if (this.footer) out.push(truncateToWidth(this.footer, width));
425
+ this.cachedRender = { width, lines: out };
422
426
  return out;
423
427
  }
424
428
 
425
- invalidate(): void {}
429
+ invalidate(): void {
430
+ this.cachedRender = undefined;
431
+ }
426
432
  }
427
433
 
428
434
  function lineCount(n: number): string {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-polish",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "license": "MIT",
5
5
  "author": "Thomas van Dongen",
6
6
  "type": "module",