pi-odd-worktree 3.7.1 → 3.7.2
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.
- package/lib/diff-design.js +183 -8
- package/package.json +1 -1
- package/tools/diff-design.test.js +149 -0
package/lib/diff-design.js
CHANGED
|
@@ -434,6 +434,10 @@ const LEADING_CHROME = new Set([' ', '│', '▎', '|', '┃', '║']);
|
|
|
434
434
|
// The closing run is dropped only while it CLEARS a state, because a frame cell's own paint starts
|
|
435
435
|
// there too (`\u001b[32m│`) and is the host's to keep.
|
|
436
436
|
const TRAILING_SGR = /(?:\u001b\[[0-9;]*m)+$/u;
|
|
437
|
+
// A row whose first cell is the host's frame rule, and the skip marker the host draws between hunks:
|
|
438
|
+
// neither is the rest of a wrapped diff line.
|
|
439
|
+
const WRAP_BREAK_CELLS = new Set(['╭', '╰', '╮', '╯', '─']);
|
|
440
|
+
const SKIP_MARKER = /^\.\.\./u;
|
|
437
441
|
const SGR_CLEARS = new Set(['0', '22', '23', '24', '25', '27', '28', '29', '39', '49', '55', '59']);
|
|
438
442
|
|
|
439
443
|
/** Whether one SGR escape CLEARS a state rather than opening one. */
|
|
@@ -547,11 +551,14 @@ function recolourDiffRow(row, spec) {
|
|
|
547
551
|
const paintedCode = code === '' ? '' : highlightRow(code, 'muted', spec.language, spec.seam, spec.theme);
|
|
548
552
|
return `${before}${paint(spec.theme, 'muted', token)}${paintedCode}${after}`;
|
|
549
553
|
}
|
|
550
|
-
|
|
554
|
+
// The number's trailing space is the row's padding when the row states no code of its own (the host
|
|
555
|
+
// flushed it before a word wider than the row), so the row is read with that space restored.
|
|
556
|
+
const probe = `${rest} `;
|
|
557
|
+
const match = ADDED.exec(probe) ?? REMOVED.exec(probe) ?? CONTEXT.exec(probe);
|
|
551
558
|
if (match === null) return row;
|
|
552
559
|
// `undefined` marks a context row, whose marker is a space and already part of the row's chrome.
|
|
553
|
-
const added = ADDED.test(
|
|
554
|
-
const role = added ? 'toolDiffAdded' : REMOVED.test(
|
|
560
|
+
const added = ADDED.test(probe);
|
|
561
|
+
const role = added ? 'toolDiffAdded' : REMOVED.test(probe) ? 'toolDiffRemoved' : undefined;
|
|
555
562
|
const gutter = role === undefined ? match[1] : `${rest[0]}${match[1]}`;
|
|
556
563
|
const head = `${gutter}${DIVIDER_RUN}`;
|
|
557
564
|
const headColumns = textColumns(head);
|
|
@@ -564,8 +571,14 @@ function recolourDiffRow(row, spec) {
|
|
|
564
571
|
// A row this design already divided wears the rule right after its number: read it back, so the
|
|
565
572
|
// second pass rebuilds the same row instead of adding a second divider (S14).
|
|
566
573
|
const code = tailText.startsWith(DIVIDER_TAIL) ? tailText.slice(DIVIDER_TAIL.length) : tailText;
|
|
567
|
-
|
|
568
|
-
|
|
574
|
+
// S15: a line the host wrapped states the rest of it on rows this design drops. The row is drawn
|
|
575
|
+
// from the WHOLE line, so it fills its width like the write pane's and ends in the ellipsis that
|
|
576
|
+
// pane writes for a line that did not fit.
|
|
577
|
+
const whole = joinWrapped(code, rest, spec.rest ?? [], room);
|
|
578
|
+
const base = whole;
|
|
579
|
+
const overflow = headColumns + textColumns(base) > room;
|
|
580
|
+
const clipped = overflow;
|
|
581
|
+
const shown = overflow ? clipPlain(base, room - headColumns) : base;
|
|
569
582
|
let body;
|
|
570
583
|
if (role !== undefined) {
|
|
571
584
|
body = paint(spec.theme, role, `${head}${shown}`);
|
|
@@ -593,17 +606,179 @@ function highlightRow(code, fallback, language, seam, theme) {
|
|
|
593
606
|
return paint(theme, fallback === 'muted' ? 'text' : fallback, code);
|
|
594
607
|
}
|
|
595
608
|
|
|
609
|
+
/** Whether a row states a numbered diff line (a hunk header and a skip marker state none). */
|
|
610
|
+
function statesLine(row) {
|
|
611
|
+
const chars = visibleChars(row);
|
|
612
|
+
const start = diffStart(chars);
|
|
613
|
+
if (start < 0) return false;
|
|
614
|
+
const rest = chars.slice(start).map((entry) => entry.char).join('');
|
|
615
|
+
return !HUNK.test(rest) && (ADDED.test(rest) || REMOVED.test(rest) || CONTEXT.test(rest));
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Whether a row is the REST of a diff line the host wrapped: text with no number, at the row's own
|
|
620
|
+
* left column. A blank band row, a frame rule, a skip marker and the host's expand hint are the
|
|
621
|
+
* host's own rows and never the rest of a line.
|
|
622
|
+
*/
|
|
623
|
+
function wrappedRest(row) {
|
|
624
|
+
if (typeof row !== 'string' || statesLine(row)) return undefined;
|
|
625
|
+
const chars = visibleChars(row);
|
|
626
|
+
const first = chars.findIndex((entry) => !LEADING_CHROME.has(entry.char));
|
|
627
|
+
const last = contentLast(chars);
|
|
628
|
+
if (first < 0 || last < first) return undefined;
|
|
629
|
+
if (WRAP_BREAK_CELLS.has(chars[first].char)) return undefined;
|
|
630
|
+
const text = chars.slice(first, last + 1).map((entry) => entry.char).join('');
|
|
631
|
+
return HUNK.test(text) || SKIP_MARKER.test(text) || EXPAND_HINT.test(plainOf(row)) ? undefined : text;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* The code of a wrapped diff line put back together: the numbered row's code and the rows the host
|
|
636
|
+
* wrapped it onto. The host broke each row at a space it then ate, or — for a word longer than the
|
|
637
|
+
* width — through the word, which leaves the row FULL and with no space to break at. `room` is the
|
|
638
|
+
* width the host wrapped at.
|
|
639
|
+
*/
|
|
640
|
+
function joinWrapped(code, rowText, rest, room) {
|
|
641
|
+
let whole = code;
|
|
642
|
+
let previous = rowText;
|
|
643
|
+
let previousCode = code;
|
|
644
|
+
for (const piece of rest) {
|
|
645
|
+
const hardBreak = textColumns(previous) >= room && !previousCode.trim().includes(' ');
|
|
646
|
+
// A numbered row with no code of its own (the host flushed it before a word wider than the row)
|
|
647
|
+
// has nothing to separate the rest from.
|
|
648
|
+
whole += `${hardBreak || whole === '' ? '' : ' '}${piece}`;
|
|
649
|
+
previous = piece;
|
|
650
|
+
previousCode = piece;
|
|
651
|
+
}
|
|
652
|
+
return whole;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// ---- the edit heading: what the call changed ----
|
|
656
|
+
|
|
657
|
+
// The heading the host draws for an `edit`: its frame cells, an optional icon, the tool and the path.
|
|
658
|
+
const EDIT_HEADING = /^[╭─\s▎│]*(?:✎\s*)?edit\s+\S+/u;
|
|
659
|
+
// The most cells the line comparison may fill; a bigger block is counted without one.
|
|
660
|
+
const MAX_DIFF_CELLS = 4_000_000;
|
|
661
|
+
|
|
662
|
+
function textLines(text) {
|
|
663
|
+
return text === '' ? [] : text.split('\n');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/** How many lines of `before` a change to `after` deletes and adds, by the longest common subsequence. */
|
|
667
|
+
function lineDelta(before, after) {
|
|
668
|
+
const a = textLines(before);
|
|
669
|
+
const b = textLines(after);
|
|
670
|
+
let head = 0;
|
|
671
|
+
while (head < a.length && head < b.length && a[head] === b[head]) head += 1;
|
|
672
|
+
let tail = 0;
|
|
673
|
+
while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail] === b[b.length - 1 - tail]) tail += 1;
|
|
674
|
+
const left = a.slice(head, a.length - tail);
|
|
675
|
+
const right = b.slice(head, b.length - tail);
|
|
676
|
+
if (left.length === 0 || right.length === 0 || left.length * right.length > MAX_DIFF_CELLS) {
|
|
677
|
+
return { added: right.length, removed: left.length };
|
|
678
|
+
}
|
|
679
|
+
let previous = new Array(right.length + 1).fill(0);
|
|
680
|
+
for (let i = 1; i <= left.length; i += 1) {
|
|
681
|
+
const current = new Array(right.length + 1).fill(0);
|
|
682
|
+
for (let j = 1; j <= right.length; j += 1) {
|
|
683
|
+
current[j] = left[i - 1] === right[j - 1] ? previous[j - 1] + 1 : Math.max(previous[j], current[j - 1]);
|
|
684
|
+
}
|
|
685
|
+
previous = current;
|
|
686
|
+
}
|
|
687
|
+
const common = previous[right.length];
|
|
688
|
+
return { added: right.length - common, removed: left.length - common };
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** The `(+added · -removed)` an edit call states, or `undefined` when it changes no line. A zero is not written. */
|
|
692
|
+
function changeCount(args) {
|
|
693
|
+
if (args === null || typeof args !== 'object') return undefined;
|
|
694
|
+
const edits = Array.isArray(args.edits) ? [...args.edits] : [];
|
|
695
|
+
if (typeof args.oldText === 'string' && typeof args.newText === 'string') edits.push(args);
|
|
696
|
+
let added = 0;
|
|
697
|
+
let removed = 0;
|
|
698
|
+
for (const entry of edits) {
|
|
699
|
+
if (entry === null || typeof entry !== 'object') continue;
|
|
700
|
+
if (typeof entry.oldText !== 'string' || typeof entry.newText !== 'string') continue;
|
|
701
|
+
const delta = lineDelta(entry.oldText, entry.newText);
|
|
702
|
+
added += delta.added;
|
|
703
|
+
removed += delta.removed;
|
|
704
|
+
}
|
|
705
|
+
const parts = [added > 0 ? `+${added}` : '', removed > 0 ? `-${removed}` : ''].filter((part) => part !== '');
|
|
706
|
+
return parts.length === 0 ? undefined : `(${parts.join(' · ')})`;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/** The SGR escapes in force at the end of `text`: every one since the last full reset. */
|
|
710
|
+
function sgrInForce(text) {
|
|
711
|
+
let state = [];
|
|
712
|
+
for (const escape of text.matchAll(/\u001b\[([0-9;]*)m/gu)) {
|
|
713
|
+
if (escape[1] === '' || escape[1] === '0') state = [];
|
|
714
|
+
else state.push(escape[0]);
|
|
715
|
+
}
|
|
716
|
+
return state.join('');
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* The host's heading row with `count` written after the path, in the `muted` role. The columns come
|
|
721
|
+
* out of the rule (or the padding) that follows the path, so the row keeps its width and the frame
|
|
722
|
+
* does not move; a heading with no room for it, or whose filler carries a paint of its own, is the
|
|
723
|
+
* host's. A heading that already wears a count has no filler right after its path, so it is a no-op.
|
|
724
|
+
*/
|
|
725
|
+
function headingWithCount(row, count, theme) {
|
|
726
|
+
const chars = visibleChars(row);
|
|
727
|
+
const matched = EDIT_HEADING.exec(chars.map((entry) => entry.char).join(''));
|
|
728
|
+
if (matched === null) return row;
|
|
729
|
+
const end = Array.from(matched[0]).length;
|
|
730
|
+
let filler = 0;
|
|
731
|
+
while (end + filler < chars.length && (chars[end + filler].char === ' ' || chars[end + filler].char === '─')) filler += 1;
|
|
732
|
+
const need = textColumns(count) + 1;
|
|
733
|
+
if (chars[end]?.char !== ' ' || filler < need + 3) return row;
|
|
734
|
+
const from = chars[end + 1].raw;
|
|
735
|
+
const to = chars[end + 1 + need].raw;
|
|
736
|
+
if (row.slice(from, to).includes('\u001b')) return row;
|
|
737
|
+
const at = chars[end].raw;
|
|
738
|
+
const before = row.slice(0, at);
|
|
739
|
+
return `${before} ${paint(theme, 'muted', count)}${sgrInForce(before)}${row.slice(at, from)}${row.slice(to)}`;
|
|
740
|
+
}
|
|
741
|
+
|
|
596
742
|
/**
|
|
597
743
|
* Every row of an `edit` card, recoloured and divided. Idempotent (S8b/S14): each row is read as its
|
|
598
744
|
* PLAIN text and rebuilt from it, divider included, so a row already wearing this drawing states the
|
|
599
745
|
* same visible characters and comes back byte for byte — never with a second copy of an escape, a
|
|
600
746
|
* reset or the divider.
|
|
747
|
+
*
|
|
748
|
+
* S15: the host wraps a long diff line onto rows that carry no number and no gutter, which would
|
|
749
|
+
* draw at the frame's left column with no divider. This design draws ONE row per line, like the
|
|
750
|
+
* write pane: the rows after a numbered one that are the rest of its line are dropped, and that row
|
|
751
|
+
* ends in `…`. A row that fit is never marked.
|
|
601
752
|
*/
|
|
602
753
|
function editRows(lines, render, ctx, seam) {
|
|
603
754
|
const language = languageOf(callPath(render?.args), seam);
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
755
|
+
const count = render?.isError === true ? undefined : changeCount(render?.args);
|
|
756
|
+
let headed = count === undefined;
|
|
757
|
+
const out = [];
|
|
758
|
+
let index = 0;
|
|
759
|
+
while (index < lines.length) {
|
|
760
|
+
const row = lines[index];
|
|
761
|
+
index += 1;
|
|
762
|
+
if (typeof row !== 'string') {
|
|
763
|
+
out.push(String(row));
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
if (!headed && statesLine(row)) headed = true;
|
|
767
|
+
if (!headed && EDIT_HEADING.test(plainOf(row))) {
|
|
768
|
+
headed = true;
|
|
769
|
+
out.push(headingWithCount(row, count, ctx.theme));
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
const rest = [];
|
|
773
|
+
if (render?.isError !== true && statesLine(row)) {
|
|
774
|
+
while (index < lines.length && wrappedRest(lines[index]) !== undefined) {
|
|
775
|
+
rest.push(wrappedRest(lines[index]));
|
|
776
|
+
index += 1;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
out.push(recolourDiffRow(row, { theme: ctx.theme, language, seam, rest }));
|
|
780
|
+
}
|
|
781
|
+
return out;
|
|
607
782
|
}
|
|
608
783
|
|
|
609
784
|
// ---- the design's entry point ----
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.2",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -756,3 +756,152 @@ describe('the shape of the contract (S5)', () => {
|
|
|
756
756
|
assert.doesNotThrow(() => diffColorDesign(seamFor().seam).apply(rows, callCtx({ render: { args } })));
|
|
757
757
|
});
|
|
758
758
|
});
|
|
759
|
+
|
|
760
|
+
describe('a diff line the host wrapped is ONE row ending in an ellipsis, as the write pane draws it (S15)', () => {
|
|
761
|
+
const ctx = () => ({ tool: 'edit', part: 'call', width: WIDTH, theme, render: { args: { path: 'lib/app.js' } } });
|
|
762
|
+
// The host's `Text` breaks a long diff line at the width: the first row states the number, every
|
|
763
|
+
// other row is the rest of the SAME line, at the row's own left column with no number.
|
|
764
|
+
const INNER = WIDTH - 4;
|
|
765
|
+
const hostWrap = (marker, number, code) => {
|
|
766
|
+
// Word wrap; a word longer than the row is broken through, which fills the row.
|
|
767
|
+
const rows = [];
|
|
768
|
+
let current = '';
|
|
769
|
+
for (let word of `${marker}${number} ${code}`.split(' ')) {
|
|
770
|
+
if (current !== '' && textLength(`${current} ${word}`) > INNER) {
|
|
771
|
+
rows.push(current);
|
|
772
|
+
current = '';
|
|
773
|
+
}
|
|
774
|
+
while (textLength(word) > INNER) {
|
|
775
|
+
if (current !== '') rows.push(current);
|
|
776
|
+
rows.push(word.slice(0, INNER));
|
|
777
|
+
current = '';
|
|
778
|
+
word = word.slice(INNER);
|
|
779
|
+
}
|
|
780
|
+
current = current === '' ? word : `${current} ${word}`;
|
|
781
|
+
}
|
|
782
|
+
rows.push(current);
|
|
783
|
+
return rows.map((row) => `│ ${row.padEnd(INNER)} │`);
|
|
784
|
+
};
|
|
785
|
+
const textLength = (text) => Array.from(text).length;
|
|
786
|
+
const LONG = 'const mentions = source.split(newline).filter((line) => !/oddModules/.test(line) && /codegraph/i.test(line))';
|
|
787
|
+
|
|
788
|
+
test('an added line: the rest rows are dropped and the one row keeps its width, divider and role', () => {
|
|
789
|
+
const wrapped = hostWrap('+', '233', LONG);
|
|
790
|
+
assert.ok(wrapped.length >= 2, 'the host did wrap this line');
|
|
791
|
+
const rows = diffColorDesign(seamFor().seam).apply(wrapped, ctx());
|
|
792
|
+
assert.equal(rows.length, 1, `the wrapped remainder is not drawn as stray rows: ${rows.map(unpaint).join('\n')}`);
|
|
793
|
+
assert.equal(cols(rows[0]), WIDTH, 'the row keeps the width the host gave it');
|
|
794
|
+
const plain = unpaint(rows[0]);
|
|
795
|
+
assert.match(plain, /^│ \+233 │ const mentions = .*…\s*│$/u, plain);
|
|
796
|
+
assert.match(rows[0], /<toolDiffAdded>\+233 │ .*…<\/toolDiffAdded>/u, 'the whole row still wears the role');
|
|
797
|
+
assert.equal((plain.match(/│/gu) ?? []).length, 3, `two frame cells and ONE divider: ${plain}`);
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
test('a removed and a context line behave the same, and the rows around them are untouched', () => {
|
|
801
|
+
const rows = diffColorDesign(seamFor().seam).apply([
|
|
802
|
+
`│ ${'@@ -230,3 +230,3 @@'.padEnd(INNER)} │`,
|
|
803
|
+
...hostWrap('-', '232', LONG),
|
|
804
|
+
...hostWrap(' ', '234', LONG),
|
|
805
|
+
`│ ${'+235 const next = 1;'.padEnd(INNER)} │`,
|
|
806
|
+
], ctx());
|
|
807
|
+
const plain = rows.map(unpaint);
|
|
808
|
+
assert.equal(plain.length, 4, plain.join('\n'));
|
|
809
|
+
assert.match(plain[1], /^│ -232 │ const mentions = .*…\s*│$/u);
|
|
810
|
+
assert.match(plain[2], /^│ +234 │ const mentions = .*…\s*│$/u);
|
|
811
|
+
assert.match(plain[3], /^│ \+235 │ const next = 1;\s*│$/u, 'a line that fit is not marked');
|
|
812
|
+
for (const row of rows) assert.equal(cols(row), WIDTH);
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
test('a word longer than the width is cut the same way, and nothing wraps past the frame', () => {
|
|
816
|
+
const rows = diffColorDesign(seamFor().seam).apply(hostWrap('+', '9', 'x'.repeat(130)), ctx());
|
|
817
|
+
assert.equal(rows.length, 1);
|
|
818
|
+
assert.equal(cols(rows[0]), WIDTH);
|
|
819
|
+
assert.match(unpaint(rows[0]), /^│ \+9 │ x+…\s*│$/u);
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
test('painted twice is the same rows', () => {
|
|
823
|
+
const design = diffColorDesign(seamFor().seam);
|
|
824
|
+
const once = design.apply(hostWrap('+', '233', LONG), ctx());
|
|
825
|
+
assert.deepEqual(design.apply(once, ctx()), once);
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
test('only the rest of a line is dropped: a skip marker, the closing rule and a hint stay', () => {
|
|
829
|
+
const rows = [
|
|
830
|
+
...hostWrap('+', '233', LONG),
|
|
831
|
+
'│ ... │',
|
|
832
|
+
'╰──────────────────────────────────────────────────────────╯',
|
|
833
|
+
'ctrl+o to expand',
|
|
834
|
+
];
|
|
835
|
+
const plain = diffColorDesign(seamFor().seam).apply(rows, ctx()).map(unpaint);
|
|
836
|
+
assert.equal(plain.length, 4, plain.join('\n'));
|
|
837
|
+
assert.equal(plain[1], rows[hostWrap('+', '233', LONG).length]);
|
|
838
|
+
assert.equal(plain[2], rows.at(-2));
|
|
839
|
+
assert.equal(plain[3], 'ctrl+o to expand');
|
|
840
|
+
});
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
describe('the edit heading states what the call changed, as the write heading states its lines (S16)', () => {
|
|
844
|
+
const heading = '╭─ ✎ edit lib/app.js ─────────────────────────────────────╮';
|
|
845
|
+
const withHint = '╭─ ✎ edit lib/app.js ──────────────── ctrl+o to collapse ─╮';
|
|
846
|
+
const run = (rows, edits, extra = {}) => diffColorDesign(seamFor().seam).apply(rows, {
|
|
847
|
+
tool: 'edit',
|
|
848
|
+
part: 'call',
|
|
849
|
+
width: WIDTH,
|
|
850
|
+
theme,
|
|
851
|
+
render: { args: { path: 'lib/app.js', edits }, ...extra },
|
|
852
|
+
});
|
|
853
|
+
const edit = (oldText, newText) => ({ oldText, newText });
|
|
854
|
+
|
|
855
|
+
test('added and removed lines follow the path, muted, and the row keeps its width', () => {
|
|
856
|
+
const [row] = run([withHint], [edit('a\nb', 'a\nc\nd')]);
|
|
857
|
+
assert.equal(cols(row), cols(withHint), 'the rule gave the columns, the frame did not move');
|
|
858
|
+
assert.match(row, /edit lib\/app\.js <muted>\(\+2 · -1\)<\/muted> ─+ ctrl\+o to collapse ─╮$/u, row);
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
test('a count of zero is not written, and nothing changed writes nothing', () => {
|
|
862
|
+
assert.match(run([heading], [edit('a', 'a\nb\nc')])[0], /<muted>\(\+2\)<\/muted>/u);
|
|
863
|
+
assert.match(run([heading], [edit('a\nb', 'a')])[0], /<muted>\(-1\)<\/muted>/u);
|
|
864
|
+
assert.equal(run([heading], [edit('same', 'same')])[0], heading);
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
test('every edit of the call counts, and the legacy single oldText/newText call too', () => {
|
|
868
|
+
assert.match(run([heading], [edit('a', 'b'), edit('x\ny', 'x')])[0], /\(\+1 · -2\)/u);
|
|
869
|
+
const legacy = diffColorDesign(seamFor().seam).apply([heading], {
|
|
870
|
+
tool: 'edit', part: 'call', width: WIDTH, theme, render: { args: { path: 'lib/app.js', oldText: 'a', newText: 'b\nc' } },
|
|
871
|
+
});
|
|
872
|
+
assert.match(legacy[0], /\(\+2 · -1\)/u);
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
test('a line only counts when the call really changes it', () => {
|
|
876
|
+
const [row] = run([heading], [edit('keep\nold\nkeep too', 'keep\nnew\nkeep too')]);
|
|
877
|
+
assert.match(row, /\(\+1 · -1\)/u, row);
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
test('float and unframed headings carry the count too', () => {
|
|
881
|
+
const float = ' ▎ ✎ edit lib/app.js ctrl+o to expand ';
|
|
882
|
+
assert.match(run([float], [edit('a', 'b')])[0], /edit lib\/app\.js <muted>\(\+1 · -1\)<\/muted> +ctrl\+o to expand/u);
|
|
883
|
+
assert.equal(cols(run([float], [edit('a', 'b')])[0]), cols(float));
|
|
884
|
+
const bare = `edit lib/app.js${' '.repeat(40)}`;
|
|
885
|
+
assert.match(run([bare], [edit('a', 'b')])[0], /^edit lib\/app\.js <muted>\(\+1 · -1\)<\/muted> +$/u);
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
test('no room, no args, a failed call or the body rows: the host\'s rows come back', () => {
|
|
889
|
+
const tight = '╭─ ✎ edit lib/app.js ─╮';
|
|
890
|
+
assert.deepEqual(run([tight], [edit('a', 'b')]), [tight]);
|
|
891
|
+
assert.deepEqual(run([heading], undefined), [heading]);
|
|
892
|
+
assert.deepEqual(run([heading], [edit('a', 'b')], { isError: true }), [heading]);
|
|
893
|
+
const body = ['│ -1 edit lib/app.js ────────────────────────────────────── │'];
|
|
894
|
+
assert.equal(unpaint(run(body, [edit('a', 'b')])[0]).includes('(+1 · -1)'), false);
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
test('painted twice is the same row', () => {
|
|
898
|
+
const once = run([withHint], [edit('a', 'b')]);
|
|
899
|
+
assert.deepEqual(run(once, [edit('a', 'b')]), once);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
test('the colour the heading was drawn in is picked up again after the count', () => {
|
|
903
|
+
const painted = `\u001b[34m${withHint}\u001b[39m`;
|
|
904
|
+
const [row] = run([painted], [edit('a', 'b')]);
|
|
905
|
+
assert.ok(row.includes('</muted>\u001b[34m'), row);
|
|
906
|
+
});
|
|
907
|
+
});
|