Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | First draft to implement word-wrap for web UI diffs. The list of TODO items can be found on the branch wiki page. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | diff-word-wrap |
| Files: | files | file ages | folders |
| SHA3-256: |
faf4b4718d51d887420f7e5254db4c37 |
| User & Date: | florian 2024-08-17 16:03:00.000 |
Context
|
2024-08-23
| ||
| 05:21 | Fix a JS ternary operator precedence bug to mess up later loaded diff context. ... (check-in: 18c5117b11 user: florian tags: diff-word-wrap) | |
|
2024-08-17
| ||
| 16:03 | First draft to implement word-wrap for web UI diffs. The list of TODO items can be found on the branch wiki page. ... (check-in: faf4b4718d user: florian tags: diff-word-wrap) | |
|
2024-08-16
| ||
| 19:28 | Make sure Fossil is run with a version of SQLite that include the order-by-subquery optimization, to avoid a performance problem. ... (check-in: 668fefe796 user: drh tags: trunk) | |
Changes
Changes to src/default.css.
| ︙ | ︙ | |||
555 556 557 558 559 560 561 |
/* Rules governing diff layout and colors */
table.diff {
width: 100%;
border-spacing: 0;
border-radius: 5px;
border: 1px solid black;
| < < < < < < < < | < < < | | > > | | > | | | < | < < < < < < | | > | | > | < < < < < | 555 556 557 558 559 560 561 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 |
/* Rules governing diff layout and colors */
table.diff {
width: 100%;
border-spacing: 0;
border-radius: 5px;
border: 1px solid black;
}
table.diff td {
vertical-align: top;
text-align: left;
margin: 0;
padding: 0;
border: 0;
font-family: monospace;
line-height: 1.2;
text-size-adjust: none;
white-space: pre-wrap;
word-wrap: break-word;
}
table.diff td.diffln {
width: 0%;
text-align: right;
padding: 0 0.16em 0 0.32em;
}
table.diff td.difflne {
text-align: left;
padding: 0 0.32em;
}
table.diff td.diffsep {
width: 0%;
padding: 0 0.32em 0 0.16em;
}
tr.diffskip.jchunk {
/* jchunk gets added from JS to diffskip rows when they are
plugged into the /jchunk route. */
background-color: aliceblue;
padding: 0;
}
|
| ︙ | ︙ | |||
621 622 623 624 625 626 627 |
text-align: left;
}
tr.diffskip > td.chunkctrl > div {
display: flex;
align-items: center;
}
tr.diffskip > td.chunkctrl > div > span.error {
| | | 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
text-align: left;
}
tr.diffskip > td.chunkctrl > div {
display: flex;
align-items: center;
}
tr.diffskip > td.chunkctrl > div > span.error {
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;
|
| ︙ | ︙ | |||
666 667 668 669 670 671 672 |
content: '⇡⇣';
}
tr.diffskip > td.chunkctrl .jcbutton:hover {
cursor: pointer;
opacity: 1;
filter: contrast(1);
}
| | < | < < < < < | < < > < < < | < | | < < | | > > | < < | < | | | < < < | < < < | | < | | | < < | < < < < | | < < | 648 649 650 651 652 653 654 655 656 657 658 659 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 |
content: '⇡⇣';
}
tr.diffskip > td.chunkctrl .jcbutton:hover {
cursor: pointer;
opacity: 1;
filter: contrast(1);
}
td.difftxt {
max-width: 0;
}
td.difftxtu {
width: 100%;
}
td.difftxtl,
td.difftxtr {
width: 50%;
}
td.diffln.nul,
td.diffsep.nul,
td.difftxt.nul {
background-color: #f9f9f9;
}
td.diffln.del,
td.diffsep.del,
td.difftxt.del {
background-color: #ffe8e8;
}
td.diffln.ins,
td.diffsep.ins,
td.difftxt.ins {
background-color: #dafbe1;
}
td.difftxt.del del {
background-color: #ffc0c0;
text-decoration: none;
display: inline-block;
}
td.difftxt.del del.edit {
background-color: #c0c0ff;
}
td.difftxt.ins ins {
background-color: #a0e4b2;
text-decoration: none;
display: inline-block;
}
td.difftxt.ins ins.edit {
background-color: #c0c0ff;
}
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.
| ︙ | ︙ | |||
926 927 928 929 930 931 932 | 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 */ | < | | 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | 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 */ int eState; /* State of the output */ int width; /* Display width */ Blob *pOut; /* Output blob */ 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 |
| ︙ | ︙ | |||
1218 1219 1220 1221 1222 1223 1224 | /************************* 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. | | | | | < | | < < | < < < | < | | < < < | < < < < < < | < < < < < < < < < < < < < < < < < < < < < < | < | | > | | | > | | > > > > | | > | | | < < > | | | | | > | < < < < < < < < < < < < | < < < < < < < < < < > | | | | | | | | | | | | > > > | > > | | | | | | | | | > < | | | < < < < | | > | < | > | > | | | < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < | < | | < < > | > > | | > | | | | > < < | | | > | | > | > | < < > | | > | | | | > | < < < < < < < | < < < < < < < < > | > > | | | | | | | | | | | < | | | | | | | | > < | | < < < < < | 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 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 |
/************************* 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 blank.
** 4. Text of the line.
**
** 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
** 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
** and .del CSS classes.
**
** Accumulator strategy:
**
** * Retained insert text goes to p->bBuf2
** * Anything else goes directly to p->pOut
**
** eState is 1 if the last line was a deletion.
*/
static void dfunifiedFinishDelete(DiffBuilder *p){
if( p->eState==0 ) return;
p->eState = 0;
}
static void dfunifiedFinishInsert(DiffBuilder *p){
if( blob_size(&p->bBuf2)==0 ) return;
dfunifiedFinishDelete(p);
blob_append_xfer(p->pOut,&p->bBuf2);
}
static void dfunifiedFinishRow(DiffBuilder *p){
dfunifiedFinishDelete(p);
dfunifiedFinishInsert(p);
}
static void dfunifiedStartRow(DiffBuilder *p){
}
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, nChunk, p->lnLeft, n);
}else{
blob_append(p->pOut, "<tr>", 4);
}
blob_append(p->pOut, "<td class=\"diffln difflne\" colspan=\"4\">"
"︙</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, "<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>",
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);
p->eState = 1;
}
p->lnLeft++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
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){
assert( 0 && "The seemingly unused function dfunifiedReplace() was called!");
}
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);
p->eState = 1;
}
p->lnLeft++;
p->lnRight++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
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->pOut, pX->z+x, ofst - x);
x = ofst;
blob_append(p->pOut, "<del>", 5);
htmlize_to_blob(p->pOut, pX->z+x, len);
x += len;
blob_append(p->pOut, "</del>", 6);
}
}
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->bBuf2, pY->z+x, ofst - x);
x = ofst;
blob_append(&p->bBuf2, "<ins>", 5);
htmlize_to_blob(&p->bBuf2, pY->z+x, len);
x += len;
blob_append(&p->bBuf2, "</ins>", 6);
}
}
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", 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->pOut = pOut;
if( pCfg->zLeftHash ){
blob_appendf(pOut, "<table class=\"diff udiff\" data-lefthash=\"%s\">\n",
pCfg->zLeftHash);
}else{
blob_append(pOut, "<table class=\"diff udiff\">\n", 27);
}
blob_init(&p->bBuf2, 0, 0);
p->pCfg = pCfg;
return p;
}
/************************* DiffBuilderSplit ******************************/
/* This formatter creates a side-by-side diff in HTML. The output is a
** <table> with 6 columns:
**
** 1. Line numbers for the first file.
** 2. First difference mark: "+", "-" or blank.
** 3. Text for the first 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
** <del> elements is the same as for the unified diffs above. In fact, the
** same CSS can be used for both.
**
** Accumulator strategy:
**
** * All output goes directly to p->pOut
**
** eState is not unused.
*/
static void dfsplitSkip(DiffBuilder *p, unsigned int n, int isFinal){
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, nChunk, p->lnLeft, n);
}else{
blob_append(p->pOut, "<tr>", 4);
}
blob_append(p->pOut,
"<td class=\"diffln difflnl difflne\" colspan=\"3\">︙</td>"
"<td class=\"diffln difflnr difflne\" colspan=\"3\">︙</td>"
"</tr>\n", -1);
p->lnLeft += n;
p->lnRight += n;
}
static void dfsplitCommon(DiffBuilder *p, const DLine *pLine){
p->lnLeft++;
p->lnRight++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
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){
p->lnRight++;
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){
p->lnLeft++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
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){
assert( 0 && "The seemingly unused function dfsplitReplace() was called!");
}
static void dfsplitEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
int i;
int x;
LineChange chng;
oneLineChange(pX, pY, &chng);
p->lnLeft++;
p->lnRight++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
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->pOut, pX->z+x, ofst - x);
x = ofst;
if( chng.a[i].iLen2 ){
blob_append(p->pOut, "<del class=\"edit\">", 18);
}else{
blob_append(p->pOut, "<del>", 5);
}
htmlize_to_blob(p->pOut, pX->z+x, len);
x += len;
blob_append(p->pOut, "</del>", 6);
}
}
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);
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->pOut, pY->z+x, ofst - x);
x = ofst;
if( chng.a[i].iLen1 ){
blob_append(p->pOut, "<ins class=\"edit\">", 18);
}else{
blob_append(p->pOut, "<ins>", 5);
}
htmlize_to_blob(p->pOut, pY->z+x, len);
x += len;
blob_append(p->pOut, "</ins>", 6);
}
}
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){
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", 31);
}
p->pCfg = pCfg;
return p;
}
/************************* DiffBuilderSbs ******************************/
/* This formatter creates a side-by-side diff in text.
*/
|
| ︙ | ︙ |
Changes to src/diff.js.
|
| | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1 2 | /* TODO: Run tools/makemake.tcl to regenerate the makefiles and to remove this ** file from the built-in files if it remains unused. */ |
Changes to src/diffcmd.c.
| ︙ | ︙ | |||
228 229 230 231 232 233 234 |
@ <style>
@ body {
@ background-color: white;
@ }
@ h1 {
@ font-size: 150%;
@ }
| < > < < < | < < | > > > | | > > | | | | > | | | | < < | | < | | | < | < | | > > | < < < > > | < < < > > | | < < | | | | | < < < | | | < < > < | > > | < | | > | > | | > | < < | < | | < | < > < < > < < > > > > > | | > > | | | | | < | | > > > > | | | | < < < | | | > > | | | > | | < | < | > > > | > > | > | < | | < < < < | | < | < < < < < | < < < < < < < < < < < < < < < | 228 229 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 |
@ <style>
@ body {
@ background-color: white;
@ }
@ h1 {
@ font-size: 150%;
@ }
@ table.diff {
@ width: 100%;
@ border-spacing: 0;
@ border-radius: 5px;
@ border: 1px solid black;
@ }
@ table.diff td {
@ vertical-align: top;
@ text-align: left;
@ margin: 0;
@ padding: 0;
@ border: 0;
@ font-family: monospace;
@ line-height: 1.2;
@ text-size-adjust: none;
@ white-space: pre-wrap;
@ word-wrap: break-word;
@ }
@ table.diff td.diffln {
@ width: 0%;
@ text-align: right;
@ padding: 0 0.16em 0 0.32em;
@ }
@ table.diff td.difflne {
@ text-align: left;
@ padding: 0 0.32em;
@ }
@ table.diff td.diffsep {
@ width: 0%;
@ padding: 0 0.32em 0 0.16em;
@ }
@ td.difftxt {
@ max-width: 0;
@ }
@ td.difftxtu {
@ width: 100%;
@ }
@ td.difftxtl,
@ td.difftxtr {
@ width: 50%;
@ }
@ td.diffln.nul,
@ td.diffsep.nul,
@ td.difftxt.nul {
@ background-color: #f9f9f9;
@ }
@ td.diffln.del,
@ td.diffsep.del,
@ td.difftxt.del {
@ background-color: #ffe8e8;
@ }
@ td.diffln.ins,
@ td.diffsep.ins,
@ td.difftxt.ins {
@ background-color: #dafbe1;
@ }
@ td.difftxt.del del {
@ background-color: #ffc0c0;
@ text-decoration: none;
@ display: inline-block;
@ }
@ td.difftxt.del del.edit {
@ background-color: #c0c0ff;
@ }
@ td.difftxt.ins ins {
@ background-color: #a0e4b2;
@ text-decoration: none;
@ display: inline-block;
@ }
@ td.difftxt.ins ins.edit {
@ background-color: #c0c0ff;
@ }
@ @media (prefers-color-scheme: dark) {
@ body {
@ color: #fff;
@ background-color: #353535;
@ }
@ td.diffln.nul,
@ td.diffsep.nul,
@ td.difftxt.nul {
@ background-color: #454545;
@ }
@ td.diffln.del,
@ td.diffsep.del,
@ td.difftxt.del {
@ color: #000;
@ background-color: #f9cfcf;
@ }
@ td.diffln.ins,
@ td.diffsep.ins,
@ td.difftxt.ins {
@ color: #000;
@ background-color: #a2dbb2;
@ }
@ td.difftxt.del del {
@ background-color: #cc5555;
@ }
@ 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;
@ }
@ h1 {
@ font-size: 150%;
@ }
@ table.diff {
@ width: 100%;
@ border-spacing: 0;
@ border-radius: 5px;
@ border: 1px solid black;
@ }
@ table.diff td {
@ vertical-align: top;
@ text-align: left;
@ margin: 0;
@ padding: 0;
@ border: 0;
@ font-family: monospace;
@ line-height: 1.2;
@ text-size-adjust: none;
@ white-space: pre-wrap;
@ word-wrap: break-word;
@ }
@ table.diff td.diffln {
@ width: 0%;
@ text-align: right;
@ padding: 0 0.16em 0 0.32em;
@ }
@ table.diff td.difflne {
@ text-align: left;
@ padding: 0 0.32em;
@ }
@ table.diff td.diffsep {
@ width: 0%;
@ padding: 0 0.32em 0 0.16em;
@ }
@ td.difftxt {
@ max-width: 0;
@ }
@ td.difftxtu {
@ width: 100%;
@ }
@ td.difftxtl,
@ td.difftxtr {
@ width: 50%;
@ }
@ td.diffln.nul,
@ td.diffsep.nul,
@ td.difftxt.nul {
@ background-color: #454545;
@ }
@ td.diffln.del,
@ td.diffsep.del,
@ td.difftxt.del {
@ color: #000;
@ background-color: #f9cfcf;
@ }
@ td.diffln.ins,
@ td.diffsep.ins,
@ td.difftxt.ins {
@ color: #000;
@ background-color: #a2dbb2;
@ }
@ td.difftxt.del del {
@ color: #000;
@ background-color: #cc5555;
@ text-decoration: none;
@ display: inline-block;
@ }
@ td.difftxt.del del.edit {
@ background-color: #c0c0ff;
@ }
@ td.difftxt.ins ins {
@ background-color: #559855;
@ text-decoration: none;
@ display: inline-block;
@ }
@ td.difftxt.ins ins.edit {
@ background-color: #c0c0ff;
@ }
@ </style>
@ </head>
@ <body>
;
const char zWebpageEnd[] =
@ </body>
@ </html>
|
| ︙ | ︙ |
Changes to src/fossil.diff.js.
| ︙ | ︙ | |||
91 92 93 94 95 96 97 |
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){
| < < < < < < < < | < < | | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
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){
var n = getLHS ? 0 : isSplit ? 3 : 1;
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
|
| ︙ | ︙ | |||
134 135 136 137 138 139 140 |
neighboring TR blocks */
startLhs: +tr.dataset.startln,
endLhs: +tr.dataset.endln
};
D.clearElement(tr);
this.e.td = D.addClass(
/* Holder for our UI controls */
| | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
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 ? 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:
|
| ︙ | ︙ | |||
299 300 301 302 303 304 305 |
lines/*response lines*/){
if(!lines.length){
/* No more data to load */
this.destroy();
return this;
}
this.msg(false);
| | | < | | | | > | < < | < < < | > | < < | < < > | < < < < < < < < | | < > > > | < < > | > | < | < < < < | < | > | < | | < | < < < | | > > | < | < | | < < < | > | > | < < < < | | | | | | | < < < < < | > | < | < < < < < > > < < > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 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 |
lines/*response lines*/){
if(!lines.length){
/* No more data to load */
this.destroy();
return this;
}
this.msg(false);
var startLnR = -2147483648; /* ⚠ */
switch( fetchType ){
case this.FetchType.PrevDown:
startLnR = this.pos.prev.endRhs + 1;
break;
case this.FetchType.NextUp:
startLnR = this.pos.next.startRhs - lines.length;
break;
case this.FetchType.FillGap:
startLnR = this.pos.prev ?
this.pos.prev.endRhs + 1 :
this.pos.next.startRhs - lines.length;
break;
}
const lnTo = Math.min(urlParam.to,
urlParam.from +
lines.length - 1/*b/c request range is inclusive*/);
function createDiffCommonLine(isSplit,lnl,lnr,txt){
var tr, td;
tr = document.createElement('tr');
tr.className = 'diffline';
td = document.createElement('td');
td.className = 'diffln difflnl';
td.appendChild(document.createTextNode(lnl));
tr.appendChild(td);
if( isSplit ){
td = document.createElement('td');
td.className = 'diffsep';
tr.appendChild(td);
td = document.createElement('td');
td.className = 'difftxt difftxtl';
td.appendChild(document.createTextNode(txt));
tr.appendChild(td);
}
td = document.createElement('td');
td.className = 'diffln difflnlr';
td.appendChild(document.createTextNode(lnr));
tr.appendChild(td);
td = document.createElement('td');
td.className = 'diffsep';
tr.appendChild(td);
td = document.createElement('td');
td.className = 'difftxt difftxt' + isSplit ? 'r' : 'u';
td.appendChild(document.createTextNode(txt));
tr.appendChild(td);
return tr;
}
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);
}
}else{
for( i=urlParam.from; i<=lnTo; i++ ){
var tr =
createDiffCommonLine(
this.isSplit,i,startLnR+i-urlParam.from,lines[i-urlParam.from]);
this.e.tr.parentElement.insertBefore(tr,this.e.tr);
}
}
if(this.FetchType.FillGap===fetchType){
this.destroy();
return this;
}else if(this.FetchType.PrevDown===fetchType){
this.pos.startLhs += lines.length;
this.pos.prev.endRhs += lines.length;
this.pos.prev.endLhs += lines.length;
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){
this.pos.endLhs -= lines.length;
this.pos.next.startRhs -= lines.length;
this.pos.next.startLhs -= lines.length;
if(this.pos.endLhs<1
|| lines.length < (urlParam.to - urlParam.from)){
/* No more data. */
this.destroy();
}else{
this.maybeReplaceButtons();
this.updatePosDebug();
|
| ︙ | ︙ |