Fossil

Changes On Branch diff-word-wrap
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch diff-word-wrap Excluding Merge-Ins

This is equivalent to a diff from 9b263d87c1 to e4556126da

2026-01-11
17:04
Modify the accordion panel style to hide only vertical overflow and keep the box shadows of selected and current timeline entries visible in the context section of /info pages. Set the CSS property to `clip' instead of `hidden' to disallow any vertical scrolling (for example, by tabbing through hyperlinks), although this is probably not relevant for accordion panels. check-in: b0188ce122 user: florian tags: trunk
2026-01-10
14:17
Sync with trunk. Leaf check-in: ceee00be59 user: florian tags: standard-cli-colors
14:10
Sync with trunk. Leaf check-in: e4556126da user: florian tags: diff-word-wrap
14:05
Sync with trunk. Leaf check-in: facfbbd552 user: florian tags: diff-keyboard-navigation
14:02
Sync with trunk. check-in: c50c8ed9d7 user: florian tags: timeline-keyboard-navigation
11:52
Do not try to use "notepad" as a text editor on non-windows systems. check-in: 9b263d87c1 user: drh tags: trunk
2026-01-09
16:44
Update the built-in SQLite to the latest trunk check-in for testing. check-in: 2b2530dd07 user: drh tags: trunk
2025-09-26
12:57
Sync with trunk. check-in: 779fe3e1b2 user: florian tags: diff-word-wrap

Changes to src/default.css.
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588








589
590
591


592
593
594


595
596
597



598
599
600

601
602
603



604
605
606



607
608
609
610
611
612
613
614
615
616
617
618
562
563
564
565
566
567
568








569
570
571

572








573
574
575
576
577
578
579
580
581


582
583



584
585
586


587
588
589



590
591


592
593
594
595


596
597
598





599
600
601
602
603
604
605







-
-
-
-
-
-
-
-



-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
+
+
-
-
-
+
+

-
-
+
+
+
-
-
-
+

-
-
+
+
+

-
-
+
+
+
-
-
-
-
-







/* Rules governing diff layout and colors */
table.diff {
  width: 100%;
  border-spacing: 0;
  border-radius: 5px;
  border: 1px solid black;
  overflow: hidden; /* Prevent background from overlapping rounded borders. */
  font-size: 80%;
}
table.diff td.diffln{
  padding: 0;
}
table.diff td.diffln > pre{
  padding: 0 0.25em 0 0.5em;
  margin: 0;
}
table.diff td {
  vertical-align: top;
  padding: 0;
  text-align: left;
  overflow: hidden /*work around inner PRE slight overflow/overlap*/;
}
table.diff pre {
  margin: 0 0 0 0;
  padding: 0 0.5em;
  line-height: 1.275/*for mobile: forum post e6f4ee7de98b55c0*/;
  text-size-adjust: none
  /* ^^^ attempt to keep mobile from inflating some text */;
  margin: 0;
  padding: 0;
  border: 0;
  font-family: monospace;
  line-height: 1.275;
  text-size-adjust: none;
  white-space: pre-wrap;
  word-wrap: break-word;
}
table.diff pre > ins,
table.diff pre > del {
table.diff td del,
table.diff td ins {
  /* Fill platform-dependent color gaps caused by
     inflated line-height */
  padding: 0.062em 0 0.062em 0;
  padding: calc((1em*1.275 - 1em)/2) 0;
  text-decoration: none;
}
table.diff pre > ins > *,
table.diff pre > del > *{
table.diff td.diffln {
  width: 0%;
  text-align: right;
  /* Avoid odd-looking color swatches in conjunction with
     (table.diff pre > ins/del) padding */
  padding: inherit;
  padding: 0 0.16em 0 0.32em;
}
table.diff td.diffln > pre {
  padding: 0 0.35em 0 0.5em;
table.diff td.difflne {
  text-align: left;
  padding: 0 0.32em;
}
table.diff td > pre {
  box-sizing: border-box;
table.diff td.diffsep {
  width: 0%;
  padding: 0 0.32em 0 0.16em;
  /* Workaround for "slight wiggle" when using mouse-wheel in some FF
     versions, apparently caused by the increased line-height forcing
     these elements to be a *tick* larger than they should be but not
     large enough to force a scroll bar to show up. */
  overflow-y: hidden;
}
tr.diffskip.jchunk {
  /* jchunk gets added from JS to diffskip rows when they are
     plugged into the /jchunk route. */
  background-color: aliceblue;
  padding: 0;
}
628
629
630
631
632
633
634
635

636
637
638
639
640
641
642
615
616
617
618
619
620
621

622
623
624
625
626
627
628
629







-
+







  text-align: left;
}
tr.diffskip > td.chunkctrl > div {
  display: flex;
  align-items: center;
}
tr.diffskip > td.chunkctrl > div > span.error {
  padding: 0.25em 0.5em;
  padding: 2px;
  border-radius: 0.5em;
}
tr.diffskip > td.chunkctrl .jcbutton
/* class name .button breaks w/ some skins! */ {
  min-width: 3.5ex;
  max-width: 3.5ex;
  text-align: center;
673
674
675
676
677
678
679
680
681
682
683




684
685
686


687
688
689
690
691
692
693
694
695
696

697
698
699


700
701
702
703
704




705
706

707
708
709

710
711
712


713
714

715
716
717
718

719
720
721
722
723


724
725
726

727
728
729
730
731

732
733
734
735
736
737


738
739
740
741


742
743
744
745

746
747




748
749
750
751
752
753
754
755
660
661
662
663
664
665
666




667
668
669
670
671


672
673

674








675



676
677


678


679
680
681
682
683

684



685



686
687
688

689




690





691
692

693

694
695


696

697
698


699


700
701

702


703
704


705

706


707
708
709
710

711
712
713
714
715
716
717







-
-
-
-
+
+
+
+

-
-
+
+
-

-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-

-
-
+
+
+
+

-
+
-
-
-
+
-
-
-
+
+

-
+
-
-
-
-
+
-
-
-
-
-
+
+
-

-
+

-
-

-
+

-
-

-
-
+
+
-

-
-
+
+
-
-

-
+
-
-
+
+
+
+
-







  content: '⇡⇣';
}
tr.diffskip > td.chunkctrl .jcbutton:hover {
  cursor: pointer;
  opacity: 1;
  filter: contrast(1);
}
tr.diffchunk {
  display: grid;
  gap: 0px 0px;
  grid-template-rows: 1fr;
td.difftxt {
  max-width: 0;
  overflow-x: hidden;
  overflow-y: hidden;
}
table.splitdiff tr.diffchunk {
  grid-template-columns: auto 1fr auto auto 1fr;
td.difftxtu {
  width: 100%;
  grid-template-areas: "difflnl difftxtl diffsep difflnr difftxtr";
}
table.udiff tr.diffchunk {
  grid-template-columns: auto auto auto 1fr;
  grid-template-areas: "difflnl difflnr diffsep difftxtu";
}
td.difflnl { grid-area: difflnl; }
td.difflnr { grid-area: difflnr; }
td.difftxtu { grid-area: difftxtu; }
td.difftxtl  { grid-area: difftxtl; }
td.difftxtl,
td.difftxtr  { grid-area: difftxtr; }
td.diffln {
  width: fit-content;
td.difftxtr {
  width: 50%;
  text-align: right;
  padding: 0 1em 0 0;
}
td.difflne {
  padding-bottom: 0.4em;
td.diffln.nul,
td.diffsep.nul,
td.difftxt.nul {
  background-color: #f9f9f9;
}
td.diffsep {
td.diffln.del,
  width: fit-content;
  padding: 0 0.3em 0 0.5em;
  grid-area: diffsep;
td.diffsep.del,
}
td.difftxt pre {
  overflow-x: auto;
td.difftxt.del {
  background-color: #ffe8e8;
}
td.diffln ins {
td.diffln.ins,
  background-color: #a0e4b2;
  text-decoration: none;
}
td.diffln del {
td.diffsep.ins,
  background-color: #ffc0c0;
  text-decoration: none;
}
td.difftxt del {
  background-color: #ffe8e8;
td.difftxt.ins {
  background-color: #dafbe1;
  text-decoration: none;
}
td.difftxt del > del {
td.difftxt.del del {
  background-color: #ffc0c0;
  text-decoration: none;
  font-weight: bold;
}
td.difftxt del > del.edit {
td.difftxt.del del.edit {
  background-color: #c0c0ff;
  text-decoration: none;
  font-weight: bold;
}
td.difftxt ins {
  background-color: #dafbe1;
td.difftxt.ins ins {
  background-color: #a0e4b2;
  text-decoration: none;
}
td.difftxt ins > ins {
  background-color: #a0e4b2;
td.difftxt.ins ins.edit {
  background-color: #c0c0ff;
  text-decoration: none;
  font-weight: bold;
}
td.difftxt ins > ins.edit {
table.diff td.diffln,
  background-color: #c0c0ff;
  text-decoration: none;
table.diff td.diffsep,
table.splitdiff.select_right td.difftxtl,
table.splitdiff.select_left td.difftxtr {
  user-select: none;
  font-weight: bold;
}
body.tkt div.content li > table.udiff {
  margin-left: 1.5em;
  margin-top: 0.5em;
}
body.tkt div.content ol.tkt-changes > li:target > p > span {
  border-bottom: 3px solid gold;
Changes to src/diff.c.
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

1043
1044
1045
1046
1047
1048
1049
1031
1032
1033
1034
1035
1036
1037

1038
1039
1040

1041
1042
1043
1044
1045
1046
1047
1048







-



-
+







  void (*xInsert)(DiffBuilder*,const DLine*);
  void (*xDelete)(DiffBuilder*,const DLine*);
  void (*xReplace)(DiffBuilder*,const DLine*,const DLine*);
  void (*xEdit)(DiffBuilder*,const DLine*,const DLine*);
  void (*xEnd)(DiffBuilder*);
  unsigned int lnLeft;              /* Lines seen on the left (delete) side */
  unsigned int lnRight;             /* Lines seen on the right (insert) side */
  unsigned int nPending;            /* Number of pending lines */
  int eState;                       /* State of the output */
  int width;                        /* Display width */
  Blob *pOut;                       /* Output blob */
  Blob aCol[5];                     /* Holding blobs */
  Blob bBuf2;                       /* Storage to hold retained lines */
  DiffConfig *pCfg;                 /* Configuration information */
};

/************************* DiffBuilderDebug ********************************/
/* This version of DiffBuilder is used for debugging the diff and diff
** diff formatter logic.  It is accessed using the (undocumented) --debug
** option to the diff command.  The output is human-readable text that
1323
1324
1325
1326
1327
1328
1329
1330
1331


1332
1333
1334


1335
1336
1337


1338
1339
1340

1341
1342
1343
1344
1345
1346
1347

1348
1349

1350
1351

1352
1353
1354
1355
1356
1357
1358
1359
1360
1361

1362
1363
1364
1365
1366
1367
1368
1369

1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405

1406
1407
1408
1409
1410
1411


1412
1413
1414
1415
1416
1417
1418
1419
1420

1421
1422
1423
1424
1425







1426
1427
1428
1429



1430
1431
1432
1433
1434






1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451







1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466

1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489

1490
1491
1492
1493
1494





1495
1496
1497
1498

1499
1500
1501


1502
1503

1504
1505
1506
1507
1508
1509
1510










1511
1512
1513
1514

1515
1516
1517


1518
1519

1520
1521
1522
1523
1524



1525
1526
1527
1528


1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546

1547
1548

1549
1550

1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564



1565
1566
1567



1568

1569
1570


1571
1572
1573
1574

1575
1576
1577
1578
1579
1580

1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632

1633
1634
1635
1636
1637
1638

1639
1640
1641


1642
1643
1644
1645
1646
1647
1648
1649

1650
1651
1652
1653
1654
1655
1656











1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668










1669
1670
1671
1672
1673

1674
1675
1676
1677
1678
1679
1680









1681
1682
1683
1684
1685
1686
1687
1688
1689
1690

1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706

1707
1708




1709
1710
1711
1712

1713
1714
1715

1716
1717

1718
1719

1720
1721

1722
1723
1724
1725
1726
1727
1728





1729
1730

1731
1732
1733
1734

1735
1736
1737

1738
1739

1740
1741

1742
1743

1744
1745
1746
1747



1748
1749
1750
1751

1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771

1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1322
1323
1324
1325
1326
1327
1328


1329
1330
1331


1332
1333



1334
1335



1336
1337
1338
1339




1340


1341
1342

1343
1344
1345
1346


1347
1348
1349


1350
1351







1352











1353
1354
1355
1356








1357
1358



1359
1360
1361
1362
1363
1364
1365

1366

1367
1368
1369


1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381





1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395





1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407


1408
1409
1410
1411






1412
1413
1414
1415
1416
1417
1418
1419
1420













1421








1422
1423
1424
1425
1426
1427
1428
1429
1430


1431
1432
1433
1434
1435





1436
1437
1438
1439
1440
1441
1442
1443

1444
1445


1446
1447
1448

1449
1450
1451





1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464

1465
1466


1467
1468
1469

1470
1471
1472



1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493

1494
1495
1496

1497
1498

1499
1500

1501




1502
1503
1504
1505
1506
1507

1508
1509


1510
1511
1512



1513
1514
1515
1516
1517


1518
1519
1520
1521
1522

1523




1524

1525




1526








































1527

1528
1529
1530
1531

1532

1533
1534
1535
1536

1537



1538
1539
1540
1541
1542
1543


1544
1545
1546







1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559


1560







1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572


1573
1574







1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585








1586






1587
1588
1589
1590
1591
1592


1593
1594
1595


1596
1597
1598
1599
1600
1601
1602

1603
1604
1605

1606
1607

1608
1609

1610
1611

1612
1613
1614





1615
1616
1617
1618
1619


1620
1621
1622
1623

1624
1625
1626

1627
1628

1629
1630

1631
1632

1633
1634
1635


1636
1637
1638
1639
1640


1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660

1661
1662





1663
1664
1665
1666
1667
1668
1669







-
-
+
+

-
-
+
+
-
-
-
+
+
-
-
-
+



-
-
-
-
+
-
-
+

-
+



-
-



-
-
+

-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
-
-
-
-


-
-
-







-
+
-



-
-
+
+









+
-
-
-
-
-
+
+
+
+
+
+
+




+
+
+
-
-
-
-
-
+
+
+
+
+
+






-
-



+
-
-
-
-
-
-
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-









-
-




+
-
-
-
-
-
+
+
+
+
+



-
+

-
-
+
+

-
+


-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
+

-
-
+
+

-
+


-
-
-
+
+
+



-
+
+













-



-
+

-
+

-
+
-
-
-
-






-
+

-
-
+
+
+
-
-
-
+
+
+

+
-
-
+
+



-
+
-
-
-
-

-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-




-
+
-




-
+
-
-
-
+
+




-
-


+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
-

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
-

+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
+
-
-
-
-
-
-






-
-


+
-
-
+
+
+
+



-
+


-
+

-
+

-
+

-
+


-
-
-
-
-
+
+
+
+
+
-
-
+



-
+


-
+

-
+

-
+

-
+


-
-
+
+
+


-
-
+



















-
+

-
-
-
-
-







/************************* DiffBuilderUnified********************************/
/* This formatter generates a unified diff for HTML.
**
** The result is a <table> with four columns.  The four columns hold:
**
**     1.   The line numbers for the first file.
**     2.   The line numbers for the second file.
**     3.   The "diff mark":  "+" or "-" or just a space
**     4.   Text of the line
**     3.   The "diff mark": "+", "-" or blank.
**     4.   Text of the line.
**
** Inserted lines are marked with <ins> and deleted lines are marked
** with <del>.  The whole line is marked this way, not just the part that
** The table cells holding the inserted and deleted lines are assigned to CSS
** classes .nul, .ins or .del to color them accordingly. The changed parts of
** changed.  The part that change has an additional nested <ins> or <del>.
** The CSS needs to be set up such that a single <ins> or <del> gives a
** light background and a nested <ins> or <del> gives a darker background.
** each line have additional <ins> or <del> elements. The CSS needs to be set
** up such that the <ins> or <del> intensify the background color of the .ins
** Additional attributes (like bold font) might also be added to nested
** <ins> and <del> since those are the characters that have actually
** changed.
** and .del CSS classes.
**
** Accumulator strategy:
**
**    *   Delete line numbers are output directly to p->pOut
**    *   Insert line numbers accumulate in p->aCol[0].
**    *   Separator marks accumulate in p->aCol[1].
**    *   Change text accumulates in p->aCol[2].
**    *   Retained insert text goes to p->bBuf2
**    *   Pending insert line numbers go into p->aCol[3].
**    *   Pending insert text goes into p->aCol[4].
**    *   Anything else goes directly to p->pOut
**
** eState is 1 if text has an open <del>
** eState is 1 if the last line was a deletion.
*/
static void dfunifiedFinishDelete(DiffBuilder *p){
  if( p->eState==0 ) return;
  blob_append(p->pOut, "</del>", 6);
  blob_append(&p->aCol[2], "</del>", 6);
  p->eState = 0;
}
static void dfunifiedFinishInsert(DiffBuilder *p){
  unsigned int i;
  if( p->nPending==0 ) return;
  if( blob_size(&p->bBuf2)==0 ) return;
  dfunifiedFinishDelete(p);

  /* Blank lines for delete line numbers for each inserted line */
  for(i=0; i<p->nPending; i++) blob_append_char(p->pOut, '\n');

  /* Insert line numbers */
  blob_append(&p->aCol[0], "<ins>", 5);
  blob_append_xfer(&p->aCol[0], &p->aCol[3]);
  blob_append_xfer(p->pOut,&p->bBuf2);
  blob_append(&p->aCol[0], "</ins>", 6);

  /* "+" marks for the separator on inserted lines */
  for(i=0; i<p->nPending; i++) blob_append(&p->aCol[1], "+\n", 2);

  /* Text of the inserted lines */
  blob_append(&p->aCol[2], "<ins>", 5);
  blob_append_xfer(&p->aCol[2], &p->aCol[4]);
  blob_append(&p->aCol[2], "</ins>", 6);

  p->nPending = 0;
}
static void dfunifiedFinishRow(DiffBuilder *p){
  dfunifiedFinishDelete(p);
  dfunifiedFinishInsert(p);
  if( blob_size(&p->aCol[0])==0 ) return;
  blob_append(p->pOut, "</pre></td><td class=\"diffln difflnr\"><pre>\n", -1);
  blob_append_xfer(p->pOut, &p->aCol[0]);
  blob_append(p->pOut, "</pre></td><td class=\"diffsep\"><pre>\n", -1);
  blob_append_xfer(p->pOut, &p->aCol[1]);
  blob_append(p->pOut, "</pre></td><td class=\"difftxt difftxtu\"><pre>\n",-1);
  blob_append_xfer(p->pOut, &p->aCol[2]);
  blob_append(p->pOut, "</pre></td></tr>\n", -1);
}
static void dfunifiedStartRow(DiffBuilder *p){
  if( blob_size(&p->aCol[0])>0 ) return;
  blob_appendf(p->pOut,"<tr id=\"chunk%d\" class=\"diffchunk\">"
                       "<td class=\"diffln difflnl\"><pre>\n", ++nChunk);
}
static void dfunifiedSkip(DiffBuilder *p, unsigned int n, int isFinal){
  dfunifiedFinishRow(p);
  if( p->pCfg && p->pCfg->zLeftHash ){
    blob_appendf(p->pOut,
       "<tr class=\"diffskip\" data-startln=\"%d\" data-endln=\"%d\""
       " id=\"skip%xh%xi%x\">\n",
       p->lnLeft+1, p->lnLeft+n,
       p->lnLeft+1, p->lnLeft+n, nChunk, p->lnLeft, n);
       nChunk, p->lnLeft, n);
  }else{
    blob_append(p->pOut, "<tr>", 4);
  }
  blob_append(p->pOut, "<td class=\"diffln difflne\">"
                       "&#xfe19;</td><td></td><td></td></tr>\n", -1);
  blob_append(p->pOut, "<td class=\"diffln difflne\" colspan=\"4\">"
                       "&#xfe19;</td></tr>\n", -1);
  p->lnLeft += n;
  p->lnRight += n;
}
static void dfunifiedCommon(DiffBuilder *p, const DLine *pLine){
  dfunifiedStartRow(p);
  dfunifiedFinishDelete(p);
  dfunifiedFinishInsert(p);
  p->lnLeft++;
  p->lnRight++;
  blob_append (p->pOut, "<tr class=\"diffline\">", 21);
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_appendf(&p->aCol[0],"%d\n",p->lnRight);
  blob_append_char(&p->aCol[1], '\n');
  htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
  blob_append_char(&p->aCol[2], '\n');
  blob_appendf(p->pOut, "<td class=\"diffln difflnl\">%d</td>", p->lnLeft);
  blob_appendf(p->pOut, "<td class=\"diffln difflnr\">%d</td>", p->lnRight);
  blob_append (p->pOut, "<td class=\"diffsep\"></td>", 25);
  blob_append (p->pOut, "<td class=\"difftxt difftxtu\">", 29);
  htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
  blob_append (p->pOut, "</td>", 5);
  blob_append (p->pOut, "</tr>\n", 6);
}
static void dfunifiedInsert(DiffBuilder *p, const DLine *pLine){
  dfunifiedStartRow(p);
  p->lnRight++;
  blob_append (&p->bBuf2, "<tr class=\"diffline\">", 21);
  blob_append (&p->bBuf2, "<td class=\"diffln difflnl ins\"></td>", 36);
  blob_appendf(&p->bBuf2, "<td class=\"diffln difflnr ins\">%d</td>",
  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
  blob_append(&p->aCol[4], "<ins>", 5);
  htmlize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n);
  blob_append(&p->aCol[4], "</ins>\n", 7);
  p->nPending++;
               p->lnRight);
  blob_append (&p->bBuf2, "<td class=\"diffsep ins\">+</td>", 30);
  blob_append (&p->bBuf2, "<td class=\"difftxt difftxtu ins\"><ins>", 38);
  htmlize_to_blob(&p->bBuf2, pLine->z, (int)pLine->n);
  blob_append (&p->bBuf2, "</ins></td>", 11);
  blob_append (&p->bBuf2, "</tr>\n", 6);
}
static void dfunifiedDelete(DiffBuilder *p, const DLine *pLine){
  dfunifiedStartRow(p);
  dfunifiedFinishInsert(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  blob_append (p->pOut, "<tr class=\"diffline\">", 21);
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0],'\n');
  blob_append(&p->aCol[1],"-\n",2);
  blob_append(&p->aCol[2], "<del>", 5);
  htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
  blob_append(&p->aCol[2], "</del>\n", 7);
  blob_appendf(p->pOut, "<td class=\"diffln difflnl del\">%d</td>", p->lnLeft);
  blob_append (p->pOut, "<td class=\"diffln difflnr del\"></td>", 36);
  blob_append (p->pOut, "<td class=\"diffsep del\">-</td>", 30);
  blob_append (p->pOut, "<td class=\"difftxt difftxtu del\"><del>", 38);
  htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
  blob_append (p->pOut, "</del></td>", 11);
  blob_append (p->pOut, "</tr>\n", 6);
}
static void dfunifiedReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
  dfunifiedStartRow(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "-\n", 2);

  fossil_fatal("The seemingly unused function dfunifiedReplace() was called!");
  htmlize_to_blob(&p->aCol[2], pX->z,  pX->n);
  blob_append_char(&p->aCol[2], '\n');

  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);

  htmlize_to_blob(&p->aCol[4], pY->z,  pY->n);
  blob_append_char(&p->aCol[4], '\n');
  p->nPending++;
}
static void dfunifiedEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i;
  int x;
  LineChange chng;
  oneLineChange(pX, pY, &chng);
  dfunifiedStartRow(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  p->lnRight++;
  blob_append (p->pOut, "<tr class=\"diffline\">", 21);
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "-\n", 2);

  for(i=x=0; i<chng.n; i++){
  blob_appendf(p->pOut, "<td class=\"diffln difflnl del\">%d</td>", p->lnLeft);
  blob_append (p->pOut, "<td class=\"diffln difflnr del\"></td>", 36);
  blob_append (p->pOut, "<td class=\"diffsep del\">-</td>", 30);
  blob_append (p->pOut, "<td class=\"difftxt difftxtu del\">", 33);
  for( i=x=0; i<chng.n; i++ ){
    int ofst = chng.a[i].iStart1;
    int len = chng.a[i].iLen1;
    if( len ){
      htmlize_to_blob(&p->aCol[2], pX->z+x, ofst - x);
      htmlize_to_blob(p->pOut, pX->z+x, ofst - x);
      x = ofst;
      blob_append(&p->aCol[2], "<del>", 5);
      htmlize_to_blob(&p->aCol[2], pX->z+x, len);
      blob_append(p->pOut, "<del>", 5);
      htmlize_to_blob(p->pOut, pX->z+x, len);
      x += len;
      blob_append(&p->aCol[2], "</del>", 6);
      blob_append(p->pOut, "</del>", 6);
    }
  }
  htmlize_to_blob(&p->aCol[2], pX->z+x,  pX->n - x);
  blob_append_char(&p->aCol[2], '\n');

  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
  for(i=x=0; i<chng.n; i++){
  htmlize_to_blob(p->pOut, pX->z+x, pX->n - x);
  blob_append (p->pOut, "</td>", 5);
  blob_append (p->pOut, "</tr>\n", 6);
  blob_append (&p->bBuf2, "<tr class=\"diffline\">", 21);
  blob_append (&p->bBuf2, "<td class=\"diffln difflnl ins\"></td>", 36);
  blob_appendf(&p->bBuf2, "<td class=\"diffln difflnr ins\">%d</td>",
               p->lnRight);
  blob_append (&p->bBuf2, "<td class=\"diffsep ins\">+</td>", 30);
  blob_append (&p->bBuf2, "<td class=\"difftxt difftxtu ins\">", 33);
  for( i=x=0; i<chng.n; i++ ){
    int ofst = chng.a[i].iStart2;
    int len = chng.a[i].iLen2;
    if( len ){
      htmlize_to_blob(&p->aCol[4], pY->z+x, ofst - x);
      htmlize_to_blob(&p->bBuf2, pY->z+x, ofst - x);
      x = ofst;
      blob_append(&p->aCol[4], "<ins>", 5);
      htmlize_to_blob(&p->aCol[4], pY->z+x, len);
      blob_append(&p->bBuf2, "<ins>", 5);
      htmlize_to_blob(&p->bBuf2, pY->z+x, len);
      x += len;
      blob_append(&p->aCol[4], "</ins>", 6);
      blob_append(&p->bBuf2, "</ins>", 6);
    }
  }
  htmlize_to_blob(&p->aCol[4], pY->z+x,  pY->n - x);
  blob_append_char(&p->aCol[4], '\n');
  p->nPending++;
  htmlize_to_blob(&p->bBuf2, pY->z+x, pY->n - x);
  blob_append (&p->bBuf2, "</td>", 5);
  blob_append (&p->bBuf2, "</tr>\n", 6);
}
static void dfunifiedEnd(DiffBuilder *p){
  dfunifiedFinishRow(p);
  blob_append(p->pOut, "</table>\n",-1);
  blob_append(p->pOut, "</table>\n", 9);
  blob_reset(&p->bBuf2);
  fossil_free(p);
}
static DiffBuilder *dfunifiedNew(Blob *pOut, DiffConfig *pCfg){
  DiffBuilder *p = fossil_malloc(sizeof(*p));
  p->xSkip = dfunifiedSkip;
  p->xCommon = dfunifiedCommon;
  p->xInsert = dfunifiedInsert;
  p->xDelete = dfunifiedDelete;
  p->xReplace = dfunifiedReplace;
  p->xEdit = dfunifiedEdit;
  p->xEnd = dfunifiedEnd;
  p->lnLeft = p->lnRight = 0;
  p->eState = 0;
  p->nPending = 0;
  p->pOut = pOut;
  if( pCfg->zLeftHash ){
    blob_appendf(pOut, "<table class=\"diff udiff\" data-lefthash=\"%s\">\n",
                pCfg->zLeftHash);
                 pCfg->zLeftHash);
  }else{
    blob_append(pOut, "<table class=\"diff udiff\">\n", -1);
    blob_append(pOut, "<table class=\"diff udiff\">\n", 27);
  }
  blob_init(&p->aCol[0], 0, 0);
  blob_init(&p->bBuf2, 0, 0);
  blob_init(&p->aCol[1], 0, 0);
  blob_init(&p->aCol[2], 0, 0);
  blob_init(&p->aCol[3], 0, 0);
  blob_init(&p->aCol[4], 0, 0);
  p->pCfg = pCfg;
  return p;
}

/************************* DiffBuilderSplit  ******************************/
/* This formatter creates a side-by-side diff in HTML.  The output is a
** <table> with 5 columns:
** <table> with 6 columns:
**
**    1.  Line numbers for the first file.
**    2.  Text for the first file.
**     1.   Line numbers for the first file.
**     2.   First difference mark: "+", "-" or blank.
**     3.   Text for the first file.
**    3.  The difference mark.  "<", ">", "|" or blank
**    4.  Line numbers for the second file.
**    5.  Text for the second file.
**     4.   Line numbers for the second file.
**     5.   Second difference mark: "+", "-" or blank.
**     6.   Text for the second file.
**
** The styling approach with .nul, .ins and .del CSS classes and <ins> and
** The <ins> and <del> strategy is the same as for unified diff above.
** In fact, the same CSS can be used for both.
** <del> elements is the same as for the unified diffs above. In fact, the
** same CSS can be used for both.
**
** Accumulator strategy:
**
**    *   Left line numbers are output directly to p->pOut
**    *   All output goes directly to p->pOut
**    *   Left text accumulates in p->aCol[0].
**    *   Edit marks accumulates in p->aCol[1].
**    *   Right line numbers accumulate in p->aCol[2].
**    *   Right text accumulates in p->aCol[3].
**
** eState:
** eState is not unused.
**    0   In common block
**    1   Have <del> on the left
**    2   Have <ins> on the right
**    3   Have <del> on left and <ins> on the right
*/
static void dfsplitChangeState(DiffBuilder *p, int newState){
  if( p->eState == newState ) return;
  if( (p->eState&1)==0 && (newState & 1)!=0 ){
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[0], "<del>", 5);
    p->eState |= 1;
  }else if( (p->eState&1)!=0 && (newState & 1)==0 ){
    blob_append(p->pOut, "</del>", 6);
    blob_append(&p->aCol[0], "</del>", 6);
    p->eState &= ~1;
  }
  if( (p->eState&2)==0 && (newState & 2)!=0 ){
    blob_append(&p->aCol[2], "<ins>", 5);
    blob_append(&p->aCol[3], "<ins>", 5);
    p->eState |= 2;
  }else if( (p->eState&2)!=0 && (newState & 2)==0 ){
    blob_append(&p->aCol[2], "</ins>", 6);
    blob_append(&p->aCol[3], "</ins>", 6);
    p->eState &= ~2;
  }
}
static void dfsplitFinishRow(DiffBuilder *p){
  if( blob_size(&p->aCol[0])==0 ) return;
  dfsplitChangeState(p, 0);
  blob_append(p->pOut, "</pre></td><td class=\"difftxt difftxtl\"><pre>\n",-1);
  blob_append_xfer(p->pOut, &p->aCol[0]);
  blob_append(p->pOut, "</pre></td><td class=\"diffsep\"><pre>\n", -1);
  blob_append_xfer(p->pOut, &p->aCol[1]);
  blob_append(p->pOut, "</pre></td><td class=\"diffln difflnr\"><pre>\n",-1);
  blob_append_xfer(p->pOut, &p->aCol[2]);
  blob_append(p->pOut, "</pre></td><td class=\"difftxt difftxtr\"><pre>\n",-1);
  blob_append_xfer(p->pOut, &p->aCol[3]);
  blob_append(p->pOut, "</pre></td></tr>\n", -1);
}
static void dfsplitStartRow(DiffBuilder *p){
  if( blob_size(&p->aCol[0])>0 ) return;
  blob_appendf(p->pOut,"<tr id=\"chunk%d\" class=\"diffchunk\">"
                       "<td class=\"diffln difflnl\"><pre>\n", ++nChunk);
  p->eState = 0;
}
static void dfsplitSkip(DiffBuilder *p, unsigned int n, int isFinal){
  dfsplitFinishRow(p);
  if( p->pCfg && p->pCfg->zLeftHash ){
    blob_appendf(p->pOut,
       "<tr class=\"diffskip\" data-startln=\"%d\" data-endln=\"%d\""
       " id=\"skip%xh%xi%x\">\n",
       p->lnLeft+1, p->lnLeft+n,
       p->lnLeft+1, p->lnLeft+n, nChunk, p->lnLeft, n);
       nChunk,p->lnLeft,n);
  }else{
    blob_append(p->pOut, "<tr>", 4);
  }
  blob_append(p->pOut,
       "<td class=\"diffln difflnl difflne\">&#xfe19;</td>"
       "<td class=\"diffln difflnl difflne\" colspan=\"3\">&#xfe19;</td>"
       "<td></td><td></td>"
       "<td class=\"diffln difflnr difflne\">&#xfe19;</td>"
       "<td/td></tr>\n", -1);
       "<td class=\"diffln difflnr difflne\" colspan=\"3\">&#xfe19;</td>"
       "</tr>\n", -1);
  p->lnLeft += n;
  p->lnRight += n;
}
static void dfsplitCommon(DiffBuilder *p, const DLine *pLine){
  dfsplitStartRow(p);
  dfsplitChangeState(p, 0);
  p->lnLeft++;
  p->lnRight++;
  blob_append (p->pOut, "<tr class=\"diffline\">", 21);
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  htmlize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n);
  blob_append_char(&p->aCol[0], '\n');
  blob_append_char(&p->aCol[1], '\n');
  blob_appendf(&p->aCol[2],"%d\n",p->lnRight);
  htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
  blob_append_char(&p->aCol[3], '\n');
  blob_appendf(p->pOut, "<td class=\"diffln difflnl\">%d</td>", p->lnLeft);
  blob_append (p->pOut, "<td class=\"diffsep\"></td>", 25);
  blob_append (p->pOut, "<td class=\"difftxt difftxtl\">", 29);
  htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
  blob_append (p->pOut, "</td>", 5);
  blob_appendf(p->pOut, "<td class=\"diffln difflnr\">%d</td>", p->lnRight);
  blob_append (p->pOut, "<td class=\"diffsep\"></td>", 25);
  blob_append (p->pOut, "<td class=\"difftxt difftxtr\">", 29);
  htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
  blob_append (p->pOut, "</td>", 5);
  blob_append (p->pOut, "</tr>\n", 6);
}
static void dfsplitInsert(DiffBuilder *p, const DLine *pLine){
  dfsplitStartRow(p);
  dfsplitChangeState(p, 2);
  p->lnRight++;
  blob_append_char(p->pOut, '\n');
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "&gt;\n", -1);
  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
  blob_append(&p->aCol[3], "<ins>", 5);
  htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
  blob_append(&p->aCol[3], "</ins>\n", 7);
  blob_append (p->pOut, "<tr class=\"diffline\">", 21);
  blob_append (p->pOut, "<td class=\"diffln difflnl nul\"></td>", 36);
  blob_append (p->pOut, "<td class=\"diffsep nul\"></td>", 29);
  blob_append (p->pOut, "<td class=\"difftxt difftxtl nul\"></td>", 38);
  blob_appendf(p->pOut, "<td class=\"diffln difflnr ins\">%d</td>", p->lnRight);
  blob_append (p->pOut, "<td class=\"diffsep ins\">+</td>", 30);
  blob_append (p->pOut, "<td class=\"difftxt difftxtr ins\"><ins>", 38);
  htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
  blob_append (p->pOut, "</ins></td>", 11);
  blob_append (p->pOut, "</tr>\n", 6);
}
static void dfsplitDelete(DiffBuilder *p, const DLine *pLine){
  dfsplitStartRow(p);
  dfsplitChangeState(p, 1);
  p->lnLeft++;
  blob_append (p->pOut, "<tr class=\"diffline\">", 21);
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append(&p->aCol[0], "<del>", 5);
  htmlize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n);
  blob_append(&p->aCol[0], "</del>\n", 7);
  blob_append(&p->aCol[1], "&lt;\n", -1);
  blob_append_char(&p->aCol[2],'\n');
  blob_append_char(&p->aCol[3],'\n');
  blob_appendf(p->pOut, "<td class=\"diffln difflnl del\">%d</td>", p->lnLeft);
  blob_append (p->pOut, "<td class=\"diffsep del\">-</td>", 30);
  blob_append (p->pOut, "<td class=\"difftxt difftxtl del\"><del>", 38);
  htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
  blob_append (p->pOut, "</del></td>", 11);
  blob_append (p->pOut, "<td class=\"diffln difflnr nul\"></td>", 36);
  blob_append (p->pOut, "<td class=\"diffsep nul\"></td>", 29);
  blob_append (p->pOut, "<td class=\"difftxt difftxtr nul\"></td>", 38);
  blob_append (p->pOut, "</tr>\n", 6);
}
static void dfsplitReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
  dfsplitStartRow(p);
  dfsplitChangeState(p, 3);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  htmlize_to_blob(&p->aCol[0], pX->z,  pX->n);
  blob_append_char(&p->aCol[0], '\n');

  fossil_fatal("The seemingly unused function dfsplitReplace() was called!");
  blob_append(&p->aCol[1], "|\n", 2);

  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);

  htmlize_to_blob(&p->aCol[3], pY->z,  pY->n);
  blob_append_char(&p->aCol[3], '\n');
}
static void dfsplitEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i;
  int x;
  LineChange chng;
  oneLineChange(pX, pY, &chng);
  dfsplitStartRow(p);
  dfsplitChangeState(p, 3);
  p->lnLeft++;
  p->lnRight++;
  blob_append (p->pOut, "<tr class=\"diffline\">", 21);
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  for(i=x=0; i<chng.n; i++){
  blob_appendf(p->pOut, "<td class=\"diffln difflnl del\">%d</td>", p->lnLeft);
  blob_append (p->pOut, "<td class=\"diffsep del\">-</td>", 30);
  blob_append (p->pOut, "<td class=\"difftxt difftxtl del\">", 33);
  for( i=x=0; i<chng.n; i++ ){
    int ofst = chng.a[i].iStart1;
    int len = chng.a[i].iLen1;
    if( len ){
      htmlize_to_blob(&p->aCol[0], pX->z+x, ofst - x);
      htmlize_to_blob(p->pOut, pX->z+x, ofst - x);
      x = ofst;
      if( chng.a[i].iLen2 ){
        blob_append(&p->aCol[0], "<del class='edit'>", -1);
        blob_append(p->pOut, "<del class=\"edit\">", 18);
      }else{
        blob_append(&p->aCol[0], "<del>", 5);
        blob_append(p->pOut, "<del>", 5);
      }
      htmlize_to_blob(&p->aCol[0], pX->z+x, len);
      htmlize_to_blob(p->pOut, pX->z+x, len);
      x += len;
      blob_append(&p->aCol[0], "</del>", 6);
      blob_append(p->pOut, "</del>", 6);
    }
  }
  htmlize_to_blob(&p->aCol[0], pX->z+x,  pX->n - x);
  blob_append_char(&p->aCol[0], '\n');

  blob_append(&p->aCol[1], "|\n", 2);

  htmlize_to_blob(p->pOut, pX->z+x, pX->n - x);
  blob_append (p->pOut, "</td>", 5);
  blob_appendf(p->pOut, "<td class=\"diffln difflnr ins\">%d</td>", p->lnRight);
  blob_append (p->pOut, "<td class=\"diffsep ins\">+</td>", 30);
  blob_append (p->pOut, "<td class=\"difftxt difftxtr ins\">", 33);
  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
  for(i=x=0; i<chng.n; i++){
  for( i=x=0; i<chng.n; i++ ){
    int ofst = chng.a[i].iStart2;
    int len = chng.a[i].iLen2;
    if( len ){
      htmlize_to_blob(&p->aCol[3], pY->z+x, ofst - x);
      htmlize_to_blob(p->pOut, pY->z+x, ofst - x);
      x = ofst;
      if( chng.a[i].iLen1 ){
        blob_append(&p->aCol[3], "<ins class='edit'>", -1);
        blob_append(p->pOut, "<ins class=\"edit\">", 18);
      }else{
        blob_append(&p->aCol[3], "<ins>", 5);
        blob_append(p->pOut, "<ins>", 5);
      }
      htmlize_to_blob(&p->aCol[3], pY->z+x, len);
      htmlize_to_blob(p->pOut, pY->z+x, len);
      x += len;
      blob_append(&p->aCol[3], "</ins>", 6);
      blob_append(p->pOut, "</ins>", 6);
    }
  }
  htmlize_to_blob(&p->aCol[3], pY->z+x,  pY->n - x);
  blob_append_char(&p->aCol[3], '\n');
  htmlize_to_blob(p->pOut, pY->z+x,  pY->n - x);
  blob_append (p->pOut, "</td>", 5);
  blob_append (p->pOut, "</tr>\n", 6);
}
static void dfsplitEnd(DiffBuilder *p){
  dfsplitFinishRow(p);
  blob_append(p->pOut, "</table>\n",-1);
  blob_append(p->pOut, "</table>\n", 9);
  fossil_free(p);
}
static DiffBuilder *dfsplitNew(Blob *pOut, DiffConfig *pCfg){
  DiffBuilder *p = fossil_malloc(sizeof(*p));
  p->xSkip = dfsplitSkip;
  p->xCommon = dfsplitCommon;
  p->xInsert = dfsplitInsert;
  p->xDelete = dfsplitDelete;
  p->xReplace = dfsplitReplace;
  p->xEdit = dfsplitEdit;
  p->xEnd = dfsplitEnd;
  p->lnLeft = p->lnRight = 0;
  p->eState = 0;
  p->pOut = pOut;
  if( pCfg->zLeftHash ){
    blob_appendf(pOut,
      "<table class=\"diff splitdiff\" data-lefthash=\"%s\">\n",
      pCfg->zLeftHash);
  }else{
    blob_append(pOut, "<table class=\"diff splitdiff\">\n", -1);
    blob_append(pOut, "<table class=\"diff splitdiff\">\n", 31);
  }
  blob_init(&p->aCol[0], 0, 0);
  blob_init(&p->aCol[1], 0, 0);
  blob_init(&p->aCol[2], 0, 0);
  blob_init(&p->aCol[3], 0, 0);
  blob_init(&p->aCol[4], 0, 0);
  p->pCfg = pCfg;
  return p;
}

/************************* DiffBuilderSbs  ******************************/
/* This formatter creates a side-by-side diff in text.
*/
Changes to src/diff.js.
1
2


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73


1
2







































































-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/* Refinements to the display of unified and side-by-side diffs.
**
/* TODO: Run tools/makemake.tcl to regenerate the makefiles and to remove this
** file from the built-in files if it remains unused. */
** In all cases, the table columns tagged with "difftxt" are expanded,
** where possible, to fill the width of the screen.
**
** For a side-by-side diff, if either column is two wide to fit on the
** display, scrollbars are added.  The scrollbars are linked, so that
** both sides scroll together.  Left and right arrows also scroll.
*/
window.addEventListener('load',function(){
  var SCROLL_LEN = 25;
  function initDiff(diff){
    var txtCols = diff.querySelectorAll('td.difftxt');
    var txtPres = diff.querySelectorAll('td.difftxt pre');
    var width = 0;
    if(txtPres.length>=2){
      width = Math.max(txtPres[0].scrollWidth, txtPres[1].scrollWidth);
    }
    var i;
    for(i=0; i<txtCols.length; i++){
      txtCols[i].style.width = width + 'px';
      txtPres[i].style.maxWidth = width + 'px';
      txtPres[i].style.width = width + 'px';
      txtPres[i].onscroll = function(e){
        for(var j=0; j<txtPres.length; j++) txtPres[j].scrollLeft = this.scrollLeft;
      };
    }
    diff.tabIndex = 0;
    diff.onkeydown = function(e){
      e = e || event;
      var len = {37: -SCROLL_LEN, 39: SCROLL_LEN}[e.keyCode];
      if( !len ) return;
      txtPres[0].scrollLeft += len;
      return false;
    };
  }
  var i, diffs = document.querySelectorAll('table.splitdiff')
  for(i=0; i<diffs.length; i++){
    initDiff(diffs[i]);
  }
  const checkWidth = function f(){
    if(undefined === f.lastWidth){
      f.lastWidth = 0;
    }
    if( document.body.clientWidth===f.lastWidth ) return;
    f.lastWidth = document.body.clientWidth;
    var w = f.lastWidth*0.5 - 100;
    if(!f.colsL){
      f.colsL = document.querySelectorAll('td.difftxtl pre');
    }
    for(let i=0; i<f.colsL.length; i++){
      f.colsL[i].style.width = w + "px";
      f.colsL[i].style.maxWidth = w + "px";
    }
    if(!f.colsR){
      f.colsR = document.querySelectorAll('td.difftxtr pre');
    }
    for(let i=0; i<f.colsR.length; i++){
      f.colsR[i].style.width = w + "px";
      f.colsR[i].style.maxWidth = w + "px";
    }
    if(!f.allDiffs){
      f.allDiffs = document.querySelectorAll('table.diff');
    }
    w = f.lastWidth;
    for(let i=0; i<f.allDiffs.length; i++){
      f.allDiffs[i].style.width = '100%'; // setting to w causes unsightly horiz. scrollbar
      f.allDiffs[i].style.maxWidth = w + "px";
    }
  };
  checkWidth();
  window.addEventListener('resize', checkWidth);
}, false);
Changes to src/diffcmd.c.
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246





247
248




249
250
251
252
253




254
255
256


257
258

259
260
261



262
263
264
265



266
267
268
269
270
271




272
273
274


275
276

277
278

279
280

281
282
283




284
285
286
287


288

289
290
291
292
293


294
295


296
297
298
299
300


301
302
303
304
305


306
307
308
309
310

311
312
313
314
315

316
317
318
319
320
321

322
323
324
325
326




327
328
329
330
331





332
333
334
335




336
337
338

339
340
341
342


343
344
345

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370

371
372
373
374
375
376





377
378




379
380
381
382
383




384
385
386


387
388

389
390
391



392
393
394
395



396
397
398
399
400
401




402
403
404


405
406
407
408



409
410
411
412
413
414




415
416
417
418
419


420


421
422
423
424
425
426


427

428
429

430
431

432
433
434



435
436
437
438
439


440
441
442
443
444
445

446
447
448
449
450

451
452
453
454
455
456
457
458
459
460
461
462
230
231
232
233
234
235
236

237
238
239
240
241


242
243
244
245
246
247
248
249


250
251
252
253
254




255
256
257
258
259


260
261
262

263
264


265
266
267
268



269
270
271


272



273
274
275
276
277


278
279
280

281


282


283
284


285
286
287
288



289
290
291

292
293



294
295
296


297
298


299


300
301


302


303
304



305

306
307


308

309
310


311
312
313
314
315

316


317
318
319
320

321



322
323
324
325
326
327



328
329
330
331



332

333


334
335

336

337
338
339
340

341
342
343
344
345
346
347
348
349
350
351
352
353

354
355
356
357

358
359
360
361
362


363
364
365
366
367
368
369
370


371
372
373
374
375




376
377
378
379
380


381
382
383

384
385


386
387
388
389



390
391
392


393



394
395
396
397
398


399
400
401



402
403
404



405


406
407
408
409




410
411
412

413
414
415




416
417
418

419


420


421
422


423
424
425


426


427
428




429

430
431


432

433
434


435

436
437
438
439
440
441
442







-



+

-
-



+
+
+
+
+
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
+

-
-
+
+
+

-
-
-
+
+
+
-
-

-
-
-
+
+
+
+

-
-
+
+

-
+
-
-
+
-
-
+

-
-
+
+
+
+
-
-
-

+
+
-
+

-
-
-

+
+
-
-
+
+
-
-

-
-
+
+
-
-

-
-
+
+
-
-
-

-
+

-
-

-
+

-
-



+

-

-
-
+
+
+
+
-

-
-
-
+
+
+
+
+

-
-
-
+
+
+
+
-
-
-
+
-

-
-
+
+
-

-
+



-











+

-




-



+

-
-



+
+
+
+
+
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
+

-
-
+
+
+

-
-
-
+
+
+
-
-

-
-
-
+
+
+
+

-
-
+
+

-
-
-
+
+
+
-
-
-

-
-
+
+
+
+
-
-
-
-

+
+
-
+
+

-
-
-
-

+
+
-
+
-
-
+
-
-
+

-
-
+
+
+
-
-

-
-
+
+
-
-
-
-

-
+

-
-

-
+

-
-

-







@ <style>
@ body {
@    background-color: white;
@ }
@ h1 {
@   font-size: 150%;
@ }
@
@ table.diff {
@   width: 100%;
@   border-spacing: 0;
@   border-radius: 5px;
@   border: 1px solid black;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ table.diff td {
@   vertical-align: top;
@   text-align: left;
@   margin: 0;
@   padding: 0;
@   border: 0;
@   font-family: monospace;
@   line-height: inherit;
@   font-size: inherit;
@   line-height: 1.275;
@   text-size-adjust: none;
@   white-space: pre-wrap;
@   word-wrap: break-word;
@ }
@ table.diff pre {
@   margin: 0 0 0 0;
@   line-height: inherit;
@   font-size: inherit;
@ table.diff td del,
@ table.diff td ins {
@   padding: calc((1em*1.275 - 1em)/2) 0;
@   text-decoration: none;
@ }
@ td.diffln {
@   width: fit-content;
@ table.diff td.diffln {
@   width: 0%;
@   text-align: right;
@   padding: 0 1em 0 0;
@   padding: 0 0.16em 0 0.32em;
@ }
@ td.difflne {
@   padding-bottom: 0.4em;
@ table.diff td.difflne {
@   text-align: left;
@   padding: 0 0.32em;
@ }
@ td.diffsep {
@   width: fit-content;
@   padding: 0 0.3em 0 1em;
@ table.diff td.diffsep {
@   width: 0%;
@   padding: 0 0.32em 0 0.16em;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.diffsep pre {
@   line-height: inherit;
@   font-size: inherit;
@ td.difftxt {
@   max-width: 0;
@   overflow-x: hidden;
@   overflow-y: hidden;
@ }
@ td.difftxt pre {
@   overflow-x: auto;
@ td.difftxtu {
@   width: 100%;
@ }
@ td.diffln ins {
@ td.difftxtl,
@   background-color: #a0e4b2;
@   text-decoration: none;
@ td.difftxtr {
@   line-height: inherit;
@   font-size: inherit;
@   width: 50%;
@ }
@ td.diffln del {
@   background-color: #ffc0c0;
@ td.diffln.nul,
@ td.diffsep.nul,
@ td.difftxt.nul {
@   background-color: #f9f9f9;
@   text-decoration: none;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.diffln.del,
@ td.diffsep.del,
@ td.difftxt del {
@ td.difftxt.del {
@   background-color: #ffe8e8;
@   text-decoration: none;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.diffln.ins,
@ td.diffsep.ins,
@ td.difftxt del > del {
@   background-color: #ffc0c0;
@ td.difftxt.ins {
@   background-color: #dafbe1;
@   text-decoration: none;
@   font-weight: bold;
@ }
@ td.difftxt del > del.edit {
@   background-color: #c0c0ff;
@ td.difftxt.del del {
@   background-color: #ffc0c0;
@   text-decoration: none;
@   font-weight: bold;
@ }
@ td.difftxt ins {
@   background-color: #dafbe1;
@ td.difftxt.del del.edit {
@   background-color: #c0c0ff;
@   text-decoration: none;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.difftxt ins > ins {
@ td.difftxt.ins ins {
@   background-color: #a0e4b2;
@   text-decoration: none;
@   font-weight: bold;
@ }
@ td.difftxt ins > ins.edit {
@ td.difftxt.ins ins.edit {
@   background-color: #c0c0ff;
@   text-decoration: none;
@   font-weight: bold;
@ }
@ @media (prefers-color-scheme: dark) {
@   body {
@     color: #fff;
@     background-color: #353535;
@     color: #ffffff;
@   }
@   td.diffln ins {
@     background-color: #559855;
@   td.diffln.nul,
@   td.diffsep.nul,
@   td.difftxt.nul {
@     background-color: #454545;
@     color: #000000;
@   }
@   td.diffln del {
@     background-color: #cc5555;
@     color: #000000;
@   td.diffln.del,
@   td.diffsep.del,
@   td.difftxt.del {
@     color: #000;
@     background-color: #f9cfcf;
@   }
@   td.difftxt del {
@     background-color: #f9cfcf;
@     color: #000000;
@   td.diffln.ins,
@   td.diffsep.ins,
@   td.difftxt.ins {
@     color: #000;
@   }
@     td.difftxt del > del {
@     background-color: #cc5555;
@     background-color: #a2dbb2;
@     color: #000000;
@   }
@   td.difftxt ins {
@     background-color: #a2dbb2;
@   td.difftxt.del del {
@     background-color: #cc5555;
@     color: #000000;
@   }
@   td.difftxt ins > ins {
@   td.difftxt.ins ins {
@     background-color: #559855;
@   }
@ }
@
@ </style>
@ </head>
@ <body>
;
static const char zWebpageHdrDark[] =
@ <!DOCTYPE html>
@ <html>
@ <head>
@ <meta charset="UTF-8">
@ <style>
@ body {
@    color: #fff;
@    background-color: #353535;
@    color: #ffffff;
@ }
@ h1 {
@   font-size: 150%;
@ }
@
@ table.diff {
@   width: 100%;
@   border-spacing: 0;
@   border-radius: 5px;
@   border: 1px solid black;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ table.diff td {
@   vertical-align: top;
@   text-align: left;
@   margin: 0;
@   padding: 0;
@   border: 0;
@   font-family: monospace;
@   line-height: inherit;
@   font-size: inherit;
@   line-height: 1.275;
@   text-size-adjust: none;
@   white-space: pre-wrap;
@   word-wrap: break-word;
@ }
@ table.diff pre {
@   margin: 0 0 0 0;
@   line-height: inherit;
@   font-size: inherit;
@ table.diff td del,
@ table.diff td ins {
@   padding: calc((1em*1.275 - 1em)/2) 0;
@   text-decoration: none;
@ }
@ td.diffln {
@   width: fit-content;
@ table.diff td.diffln {
@   width: 0%;
@   text-align: right;
@   padding: 0 1em 0 0;
@   padding: 0 0.16em 0 0.32em;
@ }
@ td.difflne {
@   padding-bottom: 0.4em;
@ table.diff td.difflne {
@   text-align: left;
@   padding: 0 0.32em;
@ }
@ td.diffsep {
@   width: fit-content;
@   padding: 0 0.3em 0 1em;
@ table.diff td.diffsep {
@   width: 0%;
@   padding: 0 0.32em 0 0.16em;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.diffsep pre {
@   line-height: inherit;
@   font-size: inherit;
@ td.difftxt {
@   max-width: 0;
@   overflow-x: hidden;
@   overflow-y: hidden;
@ }
@ td.difftxt pre {
@   overflow-x: auto;
@ td.difftxtu {
@   width: 100%;
@ }
@ td.diffln ins {
@   background-color: #559855;
@   color: #000000;
@ td.difftxtl,
@ td.difftxtr {
@   width: 50%;
@   text-decoration: none;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.diffln del {
@   background-color: #cc5555;
@ td.diffln.nul,
@ td.diffsep.nul,
@ td.difftxt.nul {
@   background-color: #454545;
@   color: #000000;
@   text-decoration: none;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.diffln.del,
@ td.diffsep.del,
@ td.difftxt del {
@ td.difftxt.del {
@   color: #000;
@   background-color: #f9cfcf;
@   color: #000000;
@   text-decoration: none;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.diffln.ins,
@ td.diffsep.ins,
@ td.difftxt del > del {
@ td.difftxt.ins {
@   background-color: #cc5555;
@   color: #000000;
@   color: #000;
@   text-decoration: none;
@   font-weight: bold;
@   background-color: #a2dbb2;
@ }
@ td.difftxt del > del.edit {
@   background-color: #c0c0ff;
@ td.difftxt.del del {
@   color: #000;
@   background-color: #cc5555;
@   text-decoration: none;
@   font-weight: bold;
@ }
@ td.difftxt ins {
@   background-color: #a2dbb2;
@ td.difftxt.del del.edit {
@   background-color: #c0c0ff;
@   color: #000000;
@   text-decoration: none;
@   line-height: inherit;
@   font-size: inherit;
@ }
@ td.difftxt ins > ins {
@ td.difftxt.ins ins {
@   background-color: #559855;
@   text-decoration: none;
@   font-weight: bold;
@ }
@ td.difftxt ins > ins.edit {
@ td.difftxt.ins ins.edit {
@   background-color: #c0c0ff;
@   text-decoration: none;
@   font-weight: bold;
@ }
@
@ </style>
@ </head>
@ <body>
;
const char zWebpageEnd[] =
@ </body>
@ </html>
Changes to src/fossil.diff.js.
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

185
186
187

188
189
190
191
192
193
194
169
170
171
172
173
174
175









176



177
178
179
180
181
182
183
184







-
-
-
-
-
-
-
-
-
+
-
-
-
+







     line-numer column in the given tr. isSplit must be true if tr
     represents a split diff, else false. Expects its tr to be valid:
     GIGO applies.  Returns the starting line number if getStart, else
     the ending line number. Returns the line number from the LHS file
     if getLHS is true, else the RHS.
  */
  const extractLineNo = function f(getLHS, getStart, tr, isSplit){
    if(!f.rx){
      f.rx = {
        start: /^\s*(\d+)/,
        end: /(\d+)\n?$/
      }
    }
    const td = tr.querySelector('td:nth-child('+(
      /* TD element with the line numbers */
      getLHS ? 1 : (isSplit ? 4 : 2)
    var n = getLHS ? 0 : isSplit ? 3 : 1;
    )+')');
    const m = f.rx[getStart ? 'start' : 'end'].exec(td.innerText);
    return m ? +m[1] : undefined/*"shouldn't happen"*/;
    return parseInt(tr.childNodes[n].innerText);
  };

  /**
     Installs chunk-loading controls into TR.diffskip element tr.
     Each instance corresponds to a single TR.diffskip element.

     The goal is to base these controls roughly on github's, a good
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216







-
+







         neighboring TR blocks */
      startLhs: +tr.dataset.startln,
      endLhs: +tr.dataset.endln
    };
    D.clearElement(tr);
    this.e.td = D.addClass(
      /* Holder for our UI controls */
      D.attr(D.td(tr), 'colspan', this.isSplit ? 5 : 4),
      D.attr(D.td(tr), 'colspan', this.isSplit ? 6 : 4),
      'chunkctrl'
    );
    this.e.msgWidget = D.addClass(D.span(), 'hidden');
    this.e.btnWrapper = D.div();
    D.append(this.e.td, this.e.btnWrapper);
    /**
       Depending on various factors, we need one or more of:
377
378
379
380
381
382
383
384
385


386
387
388
389
390
391






392
393
394

395
396
397
398
399



400
401
402

403
404
405


406
407
408
409
410
411
412
413
414
415


416
417




418
419
420
421




422
423

424
425
426
427
428

429
430
431



432
433
434


435
436

437
438
439
440
441
442





443
444

445
446
447


448
449
450
451
452
453





454
455
456
457
458
459
460
461
462
463
464







465
466
467
468
469
470
471
472



473
474

475
476
477
478
479


480
481
482


483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
367
368
369
370
371
372
373


374
375






376
377
378
379
380
381



382





383
384
385



386



387
388










389
390


391
392
393
394




395
396
397
398


399





400



401
402
403



404
405


406






407
408
409
410
411


412



413
414






415
416
417
418
419











420
421
422
423
424
425
426





427


428
429
430


431





432
433
434


435
436
437
438
439







440
441
442








443
444
445
446
447
448
449
450
451










452
453
454





455
456
457
458
459
460
461







-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
+
+
+
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
+
-
-
-
+
+
+
-
-
-
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-

-
-
+
+
+
-
-
+
-
-
-
-
-
+
+

-
-
+
+



-
-
-
-
-
-
-



-
-
-
-
-
-
-
-









-
-
-
-
-
-
-
-
-
-



-
-
-
-
-







                               lines/*response lines*/){
      if(!lines.length){
        /* No more data to load */
        this.destroy();
        return this;
      }
      this.msg(false);
      //console.debug("Loaded line range ",
      //urlParam.from,"-",urlParam.to, "fetchType ",fetchType);
      var startLnR = -2147483648; /* ⚠ */
      switch( fetchType ){
      const lineno = [],
            trPrev = this.e.tr.previousElementSibling,
            trNext = this.e.tr.nextElementSibling,
            doAppend = (
              !!trPrev && fetchType>=this.FetchType.FillGap
            ) /* true to append to previous TR, else prepend to NEXT TR */;
        case this.FetchType.PrevDown:
          startLnR = this.pos.prev.endRhs + 1;
          break;
        case this.FetchType.NextUp:
          startLnR = this.pos.next.startRhs - lines.length;
          break;
      const tr = doAppend ? trPrev : trNext;
      const joinTr = (
        this.FetchType.FillGap===fetchType && trPrev && trNext
        case this.FetchType.FillGap:
      ) ? trNext : false
      /* Truthy if we want to combine trPrev, the new content, and
         trNext into trPrev and then remove trNext. */;
      let i, td;
      if(!f.convertLines){
          startLnR = this.pos.prev ? 
                       this.pos.prev.endRhs + 1 :
                       this.pos.next.startRhs - lines.length;
        /* Reminder: string.replaceAll() is a relatively new
           JS feature, not available in some still-widely-used
           browser versions. */
          break;
        f.rx = [[/&/g, '&amp;'], [/</g, '&lt;']];
        f.convertLines = function(li){
          var s = li.join('\n');
      }
      const lnTo = Math.min(urlParam.to,
          f.rx.forEach((a)=>s=s.replace(a[0],a[1]));
          return s + '\n';
        };
      }
      if(1){ // LHS line numbers...
        const selector = '.difflnl > pre';
        td = tr.querySelector(selector);
        const lnTo = Math.min(urlParam.to,
                              urlParam.from +
                              lines.length - 1/*b/c request range is inclusive*/);
                            urlParam.from +
                            lines.length - 1/*b/c request range is inclusive*/);
        for( i = urlParam.from; i <= lnTo; ++i ){
          lineno.push(i);
      function createDiffCommonLine(isSplit,lnl,lnr,txt){
        var tr, td;
        tr = document.createElement('tr');
        tr.className = 'diffline';
        }
        const lineNoTxt = lineno.join('\n')+'\n';
        const content = [td.innerHTML];
        if(doAppend) content.push(lineNoTxt);
        td = document.createElement('td');
        td.className = 'diffln difflnl';
        td.appendChild(document.createTextNode(lnl));
        tr.appendChild(td);
        else content.unshift(lineNoTxt);
        if(joinTr){
        if( isSplit ){
          content.push(trNext.querySelector(selector).innerHTML);
        }
        td.innerHTML = content.join('');
      }

          td = document.createElement('td');
      if(1){// code block(s)...
        const selector = '.difftxt > pre';
        td = tr.querySelectorAll(selector);
          td.className = 'diffsep';
          tr.appendChild(td);
          td = document.createElement('td');
        const code = f.convertLines(lines);
        let joinNdx = 0/*selector[X] index to join together*/;
        td.forEach(function(e){
          td.className = 'difftxt difftxtl';
          td.appendChild(document.createTextNode(txt));
          const content = [e.innerHTML];
          if(doAppend) content.push(code);
          tr.appendChild(td);
          else content.unshift(code);
          if(joinTr){
            content.push(trNext.querySelectorAll(selector)[joinNdx++].innerHTML)
          }
          e.innerHTML = content.join('');
        });
        }
        td = document.createElement('td');
        td.className = 'diffln difflnlr';
        td.appendChild(document.createTextNode(lnr));
        tr.appendChild(td);
      }

        td = document.createElement('td');
      if(1){// Add blank lines in (.diffsep>pre)
        const selector = '.diffsep > pre';
        td = tr.querySelector(selector);
        td.className = 'diffsep';
        tr.appendChild(td);
        for(i = 0; i < lineno.length; ++i) lineno[i] = '';
        const blanks = lineno.join('\n')+'\n';
        const content = [td.innerHTML];
        if(doAppend) content.push(blanks);
        else content.unshift(blanks);
        if(joinTr){
        td = document.createElement('td');
        td.className = 'difftxt difftxt' + ( isSplit ? 'r' : 'u' );
        td.appendChild(document.createTextNode(txt));
        tr.appendChild(td);
        return tr;
          content.push(trNext.querySelector(selector).innerHTML);
        }
        td.innerHTML = content.join('');
      }

      if(this.FetchType.FillGap===fetchType){
        /* Closing the whole gap between two chunks or a whole gap
           at the start or end of a diff. */
        // RHS line numbers...
        let startLnR = this.pos.prev
            ? this.pos.prev.endRhs+1 /* Closing the whole gap between two chunks
      }
      if( fetchType==this.FetchType.NextUp ){
        for( i=lnTo; i>=urlParam.from; i-- ){
          var tr =
            createDiffCommonLine(
              this.isSplit,i,startLnR+i-urlParam.from,lines[i-urlParam.from]);
          this.e.tr.parentElement.insertBefore(tr,this.e.tr.nextElementSibling);
                                        or end-of-file gap. */
            : this.pos.next.startRhs - lines.length /* start-of-file gap */;
        lineno.length = lines.length;
        for( i = startLnR; i < startLnR + lines.length; ++i ){
          lineno[i-startLnR] = i;
        }
        const selector = '.difflnr > pre';
        td = tr.querySelector(selector);
      }else{
        for( i=urlParam.from; i<=lnTo; i++ ){
          var tr =
        const lineNoTxt = lineno.join('\n')+'\n';
        lineno.length = 0;
            createDiffCommonLine(
        const content = [td.innerHTML];
        if(doAppend) content.push(lineNoTxt);
        else content.unshift(lineNoTxt);
        if(joinTr){
          content.push(trNext.querySelector(selector).innerHTML);
              this.isSplit,i,startLnR+i-urlParam.from,lines[i-urlParam.from]);
          this.e.tr.parentElement.insertBefore(tr,this.e.tr);
        }
        td.innerHTML = content.join('');
        if(joinTr) D.remove(joinTr);
      }
      if(this.FetchType.FillGap===fetchType){
        this.destroy();
        return this;
      }else if(this.FetchType.PrevDown===fetchType){
        /* Append context to previous TR. */
        // RHS line numbers...
        let startLnR = this.pos.prev.endRhs+1;
        lineno.length = lines.length;
        for( i = startLnR; i < startLnR + lines.length; ++i ){
          lineno[i-startLnR] = i;
        }
        this.pos.startLhs += lines.length;
        this.pos.prev.endRhs += lines.length;
        this.pos.prev.endLhs += lines.length;
        const selector = '.difflnr > pre';
        td = tr.querySelector(selector);
        const lineNoTxt = lineno.join('\n')+'\n';
        lineno.length = 0;
        const content = [td.innerHTML];
        if(doAppend) content.push(lineNoTxt);
        else content.unshift(lineNoTxt);
        td.innerHTML = content.join('');
        if(lines.length < (urlParam.to - urlParam.from)){
          /* No more data. */
          this.destroy();
        }else{
          this.maybeReplaceButtons();
          this.updatePosDebug();
        }
        return this;
      }else if(this.FetchType.NextUp===fetchType){
        /* Prepend content to next TR. */
        // RHS line numbers...
        if(doAppend){
          throw new Error("Internal precondition violation: doAppend is true.");
        }
        let startLnR = this.pos.next.startRhs - lines.length;
        lineno.length = lines.length;
        for( i = startLnR; i < startLnR + lines.length; ++i ){
          lineno[i-startLnR] = i;
        }
        this.pos.endLhs -= lines.length;
        this.pos.next.startRhs -= lines.length;
        this.pos.next.startLhs -= lines.length;
        const selector = '.difflnr > pre';
        td = tr.querySelector(selector);
        const lineNoTxt = lineno.join('\n')+'\n';
        lineno.length = 0;
        td.innerHTML = lineNoTxt + td.innerHTML;
        if(this.pos.endLhs<1
           || lines.length < (urlParam.to - urlParam.from)){
          /* No more data. */
          this.destroy();
        }else{
          this.maybeReplaceButtons();
          this.updatePosDebug();
696
697
698
699
700
701
702
703
704
705
706
707






708
709

710
711
712
713
714
715
716

717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732


733
734
735

736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752

753
754
755
756
757
758
759
760
761
762
763
764
765
766
767

768
769
770
771

772
773
774
775
776
777

778
779
780
781




782

783
784


785
786
787
788
789
790
791
792
793

794
795
796
797
798
799

800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815

816
817
620
621
622
623
624
625
626





627
628
629
630
631
632


633







634
















635
636



637














638


639















640




641






642




643
644
645
646
647
648


649
650









651






652









653
654

655



656









-
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
+
+
+
+

+
-
-
+
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-


-

-
-
-
+
-
-
        new ChunkLoadControls(D.addClass(tr, 'jchunk'));
      });
    });
    return F;
  };
  Diff.setupDiffContextLoad();
});
/*
** For a side-by-side diff, ensure that horizontal scrolling of either
** side of the diff is synchronized with the other side.
*/
window.fossil.onPageLoad(function(){
/* Click-handler for side-by-side diffs to activate text selection for the most
** recently clicked side (left or right). If the click-handler target is one of
** the simple-nested <del> or <ins> elements, the parent <td> is deciding. Note
** the "pointerdown" event seems to be exactly what is desired here: activating
** the clicked side just before the selection operation starts. */
(function(){
  const F = window.fossil, D = F.dom, Diff = F.diff;

  window.addEventListener('load',function(){
  /* Look for a parent element to hold the sbs-sync-scroll toggle
     checkbox.  This differs per page. If we don't find one, simply
     elide that toggle and use whatever preference the user last
     specified (defaulting to on). */
  let cbSync /* scroll-sync checkbox */;
  let eToggleParent = /* element to put the sync-scroll checkbox in */
      document.querySelector('table.diff.splitdiff')
    var s = document.getElementsByClassName('splitdiff');
      ? window.fossil.page.diffControlContainer
      : undefined;
  const keySbsScroll = 'sync-diff-scroll' /* F.storage key for persistent user preference */;
  if( eToggleParent ){
    /* Add a checkbox to toggle sbs scroll sync. Remember that in
       order to be UI-consistent in the /vdiff page we have to ensure
       that the checkbox is to the LEFT of its label. We store the
       sync-scroll preference in F.storage (not a cookie) so that it
       persists across page loads and different apps. */
    cbSync = D.checkbox(keySbsScroll, F.storage.getBool(keySbsScroll,true));
    D.append(eToggleParent, D.append(
      D.addClass(D.create('span'), 'input-with-label'),
      D.append(D.create('label'),
               cbSync, "Scroll Sync")
    ));
    cbSync.addEventListener('change', function(e){
    for( var i=0; i<s.length; i++ ){
      s[i].addEventListener('pointerdown',splitdiff_click);
      F.storage.set(keySbsScroll, e.target.checked);
    });
  }
    }
  const useSync = cbSync ? ()=>cbSync.checked : ()=>F.storage.getBool(keySbsScroll,true);

  /* Now set up the events to enable syncronized scrolling... */
  const scrollLeft = function(event){
    const table = this.parentElement/*TD*/.parentElement/*TR*/.
      parentElement/*TBODY*/.parentElement/*TABLE*/;
    if( useSync() ){
      table.$txtPres.forEach((e)=>(e===this) ? 1 : (e.scrollLeft = this.scrollLeft));
    }
    return false;
  };
  const SCROLL_LEN = 64/* pixels to scroll for keyboard events */;
  const keycodes = Object.assign(Object.create(null),{
    37/*cursor left*/: -SCROLL_LEN, 39/*cursor right*/: SCROLL_LEN
  });
  /** keydown handler for a diff element */
  const handleDiffKeydown = function(e){
  function splitdiff_click(e){
    const len = keycodes[e.keyCode];
    if( !len ) return false;
    if( useSync() ){
      this.$txtPres[0].scrollLeft += len;
    }else if( this.$preCurrent ){
      this.$preCurrent.scrollLeft += len;
    }
    return false;
  };
  /**
     Sets up synchronized scrolling of table.splitdiff element
     `diff`. If passed no argument, it scans the dom for elements to
     initialize. The second argument is for this function's own
     internal use.

    var n = e.target.nodeName,
     It's okay (but wasteful) to pass the same element to this
     function multiple times: it will only be set up for sync
     scrolling the first time it's passed to this function.

        t = n=='DEL' || n=='INS' ? e.target.parentElement : e.target;
     Note that this setup is ignorant of the cbSync toggle: the toggle
     is checked when scrolling, not when initializing the sync-scroll
     capability.
  */
  const initTableDiff = function f(diff, unifiedDiffs){
    if(!diff){
    if( /\bdifftxtl\b/.test(t.className) ){
      let i, diffs;
      diffs = document.querySelectorAll('table.splitdiff');
      for(i=0; i<diffs.length; ++i){
        f.call(this, diffs[i], false);
      var s = document.getElementsByClassName('splitdiff');
      for( var i=0; i<s.length; i++ ){
        s[i].classList.remove('select_right');
        s[i].classList.add('select_left');
      }
    }else if( /\bdifftxtr\b/.test(t.className) ){
      diffs = document.querySelectorAll('table.udiff');
      for(i=0; i<diffs.length; ++i){
      var s = document.getElementsByClassName('splitdiff');
      for( var i=0; i<s.length; i++ ){
        f.call(this, diffs[i], true);
      }
      return this;
    }
    diff.$txtCols = diff.querySelectorAll('td.difftxt');
    diff.$txtPres = diff.querySelectorAll('td.difftxt pre');
    if(!unifiedDiffs){
      diff.$txtPres.forEach(function(e){
        if(!e.classList.contains('scroller')){
        s[i].classList.remove('select_left');
          D.addClass(e, 'scroller');
          e.addEventListener('scroll', scrollLeft, false);
        }
      });
      diff.tabIndex = 0;
      if(!diff.classList.contains('scroller')){
        s[i].classList.add('select_right');
        /* Keyboard-based scrolling requires special-case handling to
           ensure that we scroll the proper side of the diff when sync
           is off. */
        D.addClass(diff, 'scroller');
        diff.addEventListener('keydown', handleDiffKeydown, false);
        const handleLRClick = function(ev){
          diff.$preCurrent = this /* NOT ev.target, which is probably a child element */;
        };
        diff.$txtPres.forEach((e)=>e.addEventListener('click', handleLRClick, false));
      }
    }
    return this;
  }
  window.fossil.page.tweakSbsDiffs = function(){
    document.querySelectorAll('table.splitdiff').forEach((e)=>initTableDiff(e));
  };
}());
  initTableDiff();
}, false);