Fossil SCM
Additional fixes to side-by-side diff coloration for multibyte UTF8 text.
Commit
85ca387557c92151384a825c4b9d497758ce389c
Parent
82081837b3ba9a1…
1 file changed
+9
-10
+9
-10
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -858,16 +858,16 @@ | ||
| 858 | 858 | ** * If iStart is a null-change then move iStart2 into iStart |
| 859 | 859 | ** * Make sure any null-changes are in canonoical form. |
| 860 | 860 | ** * Make sure all changes are at character boundaries for |
| 861 | 861 | ** multi-byte characters. |
| 862 | 862 | */ |
| 863 | -static void sbsSimplifyLine(SbsLine *p){ | |
| 863 | +static void sbsSimplifyLine(SbsLine *p, const char *z){ | |
| 864 | 864 | if( p->iStart2==p->iEnd2 ){ |
| 865 | 865 | p->iStart2 = p->iEnd2 = 0; |
| 866 | 866 | }else if( p->iStart2 ){ |
| 867 | - while( p->iStart2>0 && (p->zLine[p->iStart2]&0xc0)==0x80 ) p->iStart2--; | |
| 868 | - while( (p->zLine[p->iEnd2+1]&0xc0)==0x80 ) p->iEnd2++; | |
| 867 | + while( p->iStart2>0 && (z[p->iStart2]&0xc0)==0x80 ) p->iStart2--; | |
| 868 | + while( (z[p->iEnd2]&0xc0)==0x80 ) p->iEnd2++; | |
| 869 | 869 | } |
| 870 | 870 | if( p->iStart==p->iEnd ){ |
| 871 | 871 | p->iStart = p->iStart2; |
| 872 | 872 | p->iEnd = p->iEnd2; |
| 873 | 873 | p->zStart = p->zStart2; |
| @@ -875,12 +875,12 @@ | ||
| 875 | 875 | p->iEnd2 = 0; |
| 876 | 876 | } |
| 877 | 877 | if( p->iStart==p->iEnd ){ |
| 878 | 878 | p->iStart = p->iEnd = -1; |
| 879 | 879 | }else if( p->iStart>0 ){ |
| 880 | - while( p->iStart>0 && (p->zLine[p->iStart]&0xc0)==0x80 ) p->iStart--; | |
| 881 | - while( (p->zLine[p->iEnd+1]&0xc0)==0x80 ) p->iEnd++; | |
| 880 | + while( p->iStart>0 && (z[p->iStart]&0xc0)==0x80 ) p->iStart--; | |
| 881 | + while( (z[p->iEnd]&0xc0)==0x80 ) p->iEnd++; | |
| 882 | 882 | } |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | /* |
| 886 | 886 | ** Write out lines that have been edited. Adjust the highlight to cover |
| @@ -920,16 +920,15 @@ | ||
| 920 | 920 | if( nPrefix<nShort ){ |
| 921 | 921 | while( nPrefix>0 && (zLeft[nPrefix]&0xc0)==0x80 ) nPrefix--; |
| 922 | 922 | } |
| 923 | 923 | nSuffix = 0; |
| 924 | 924 | if( nPrefix<nShort ){ |
| 925 | - while( nSuffix<nShort | |
| 926 | - && zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){ | |
| 925 | + while( nSuffix<nShort && zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){ | |
| 927 | 926 | nSuffix++; |
| 928 | 927 | } |
| 929 | 928 | if( nSuffix<nShort ){ |
| 930 | - while( nSuffix>0 && (zLeft[nLeft-nSuffix+1]&0xc0)==0x80 ) nSuffix--; | |
| 929 | + while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--; | |
| 931 | 930 | } |
| 932 | 931 | if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0; |
| 933 | 932 | } |
| 934 | 933 | if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix; |
| 935 | 934 | |
| @@ -990,11 +989,11 @@ | ||
| 990 | 989 | p->zStart = zClassChng; |
| 991 | 990 | } |
| 992 | 991 | p->iStart2 = nPrefix + aLCS[1]; |
| 993 | 992 | p->iEnd2 = nLeft - nSuffix; |
| 994 | 993 | p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng; |
| 995 | - sbsSimplifyLine(p); | |
| 994 | + sbsSimplifyLine(p, zLeft+nPrefix); | |
| 996 | 995 | sbsWriteText(p, pLeft, SBS_PAD); |
| 997 | 996 | sbsWrite(p, " | ", 3); |
| 998 | 997 | sbsWriteLineno(p, lnRight); |
| 999 | 998 | p->iStart = nPrefix; |
| 1000 | 999 | p->iEnd = nPrefix + aLCS[2]; |
| @@ -1005,11 +1004,11 @@ | ||
| 1005 | 1004 | p->zStart = zClassChng; |
| 1006 | 1005 | } |
| 1007 | 1006 | p->iStart2 = nPrefix + aLCS[3]; |
| 1008 | 1007 | p->iEnd2 = nRight - nSuffix; |
| 1009 | 1008 | p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng; |
| 1010 | - sbsSimplifyLine(p); | |
| 1009 | + sbsSimplifyLine(p, zRight+nPrefix); | |
| 1011 | 1010 | sbsWriteText(p, pRight, SBS_NEWLINE); |
| 1012 | 1011 | return; |
| 1013 | 1012 | } |
| 1014 | 1013 | |
| 1015 | 1014 | /* If all else fails, show a single big change between left and right */ |
| 1016 | 1015 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -858,16 +858,16 @@ | |
| 858 | ** * If iStart is a null-change then move iStart2 into iStart |
| 859 | ** * Make sure any null-changes are in canonoical form. |
| 860 | ** * Make sure all changes are at character boundaries for |
| 861 | ** multi-byte characters. |
| 862 | */ |
| 863 | static void sbsSimplifyLine(SbsLine *p){ |
| 864 | if( p->iStart2==p->iEnd2 ){ |
| 865 | p->iStart2 = p->iEnd2 = 0; |
| 866 | }else if( p->iStart2 ){ |
| 867 | while( p->iStart2>0 && (p->zLine[p->iStart2]&0xc0)==0x80 ) p->iStart2--; |
| 868 | while( (p->zLine[p->iEnd2+1]&0xc0)==0x80 ) p->iEnd2++; |
| 869 | } |
| 870 | if( p->iStart==p->iEnd ){ |
| 871 | p->iStart = p->iStart2; |
| 872 | p->iEnd = p->iEnd2; |
| 873 | p->zStart = p->zStart2; |
| @@ -875,12 +875,12 @@ | |
| 875 | p->iEnd2 = 0; |
| 876 | } |
| 877 | if( p->iStart==p->iEnd ){ |
| 878 | p->iStart = p->iEnd = -1; |
| 879 | }else if( p->iStart>0 ){ |
| 880 | while( p->iStart>0 && (p->zLine[p->iStart]&0xc0)==0x80 ) p->iStart--; |
| 881 | while( (p->zLine[p->iEnd+1]&0xc0)==0x80 ) p->iEnd++; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /* |
| 886 | ** Write out lines that have been edited. Adjust the highlight to cover |
| @@ -920,16 +920,15 @@ | |
| 920 | if( nPrefix<nShort ){ |
| 921 | while( nPrefix>0 && (zLeft[nPrefix]&0xc0)==0x80 ) nPrefix--; |
| 922 | } |
| 923 | nSuffix = 0; |
| 924 | if( nPrefix<nShort ){ |
| 925 | while( nSuffix<nShort |
| 926 | && zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){ |
| 927 | nSuffix++; |
| 928 | } |
| 929 | if( nSuffix<nShort ){ |
| 930 | while( nSuffix>0 && (zLeft[nLeft-nSuffix+1]&0xc0)==0x80 ) nSuffix--; |
| 931 | } |
| 932 | if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0; |
| 933 | } |
| 934 | if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix; |
| 935 | |
| @@ -990,11 +989,11 @@ | |
| 990 | p->zStart = zClassChng; |
| 991 | } |
| 992 | p->iStart2 = nPrefix + aLCS[1]; |
| 993 | p->iEnd2 = nLeft - nSuffix; |
| 994 | p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng; |
| 995 | sbsSimplifyLine(p); |
| 996 | sbsWriteText(p, pLeft, SBS_PAD); |
| 997 | sbsWrite(p, " | ", 3); |
| 998 | sbsWriteLineno(p, lnRight); |
| 999 | p->iStart = nPrefix; |
| 1000 | p->iEnd = nPrefix + aLCS[2]; |
| @@ -1005,11 +1004,11 @@ | |
| 1005 | p->zStart = zClassChng; |
| 1006 | } |
| 1007 | p->iStart2 = nPrefix + aLCS[3]; |
| 1008 | p->iEnd2 = nRight - nSuffix; |
| 1009 | p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng; |
| 1010 | sbsSimplifyLine(p); |
| 1011 | sbsWriteText(p, pRight, SBS_NEWLINE); |
| 1012 | return; |
| 1013 | } |
| 1014 | |
| 1015 | /* If all else fails, show a single big change between left and right */ |
| 1016 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -858,16 +858,16 @@ | |
| 858 | ** * If iStart is a null-change then move iStart2 into iStart |
| 859 | ** * Make sure any null-changes are in canonoical form. |
| 860 | ** * Make sure all changes are at character boundaries for |
| 861 | ** multi-byte characters. |
| 862 | */ |
| 863 | static void sbsSimplifyLine(SbsLine *p, const char *z){ |
| 864 | if( p->iStart2==p->iEnd2 ){ |
| 865 | p->iStart2 = p->iEnd2 = 0; |
| 866 | }else if( p->iStart2 ){ |
| 867 | while( p->iStart2>0 && (z[p->iStart2]&0xc0)==0x80 ) p->iStart2--; |
| 868 | while( (z[p->iEnd2]&0xc0)==0x80 ) p->iEnd2++; |
| 869 | } |
| 870 | if( p->iStart==p->iEnd ){ |
| 871 | p->iStart = p->iStart2; |
| 872 | p->iEnd = p->iEnd2; |
| 873 | p->zStart = p->zStart2; |
| @@ -875,12 +875,12 @@ | |
| 875 | p->iEnd2 = 0; |
| 876 | } |
| 877 | if( p->iStart==p->iEnd ){ |
| 878 | p->iStart = p->iEnd = -1; |
| 879 | }else if( p->iStart>0 ){ |
| 880 | while( p->iStart>0 && (z[p->iStart]&0xc0)==0x80 ) p->iStart--; |
| 881 | while( (z[p->iEnd]&0xc0)==0x80 ) p->iEnd++; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /* |
| 886 | ** Write out lines that have been edited. Adjust the highlight to cover |
| @@ -920,16 +920,15 @@ | |
| 920 | if( nPrefix<nShort ){ |
| 921 | while( nPrefix>0 && (zLeft[nPrefix]&0xc0)==0x80 ) nPrefix--; |
| 922 | } |
| 923 | nSuffix = 0; |
| 924 | if( nPrefix<nShort ){ |
| 925 | while( nSuffix<nShort && zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){ |
| 926 | nSuffix++; |
| 927 | } |
| 928 | if( nSuffix<nShort ){ |
| 929 | while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--; |
| 930 | } |
| 931 | if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0; |
| 932 | } |
| 933 | if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix; |
| 934 | |
| @@ -990,11 +989,11 @@ | |
| 989 | p->zStart = zClassChng; |
| 990 | } |
| 991 | p->iStart2 = nPrefix + aLCS[1]; |
| 992 | p->iEnd2 = nLeft - nSuffix; |
| 993 | p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng; |
| 994 | sbsSimplifyLine(p, zLeft+nPrefix); |
| 995 | sbsWriteText(p, pLeft, SBS_PAD); |
| 996 | sbsWrite(p, " | ", 3); |
| 997 | sbsWriteLineno(p, lnRight); |
| 998 | p->iStart = nPrefix; |
| 999 | p->iEnd = nPrefix + aLCS[2]; |
| @@ -1005,11 +1004,11 @@ | |
| 1004 | p->zStart = zClassChng; |
| 1005 | } |
| 1006 | p->iStart2 = nPrefix + aLCS[3]; |
| 1007 | p->iEnd2 = nRight - nSuffix; |
| 1008 | p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng; |
| 1009 | sbsSimplifyLine(p, zRight+nPrefix); |
| 1010 | sbsWriteText(p, pRight, SBS_NEWLINE); |
| 1011 | return; |
| 1012 | } |
| 1013 | |
| 1014 | /* If all else fails, show a single big change between left and right */ |
| 1015 |