userdiff: expand detected chunk headers for css
The regex used for the CSS builtin diff driver in git is only able to show chunk headers for lines that start with a number, a letter or an underscore. However, the regex fails to detect classes (starts with a .), ids (starts with a #), :root and attribute-value based selectors (for example [class*="col-"]), as well as @based block-level statements like @page,@keyframes and @media since all of them, start with a special character. Allow the selectors and block level statements to begin with these special characters. Signed-off-by: Sohom Datta <sohom.datta@learner.manipal.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sohom Datta committed
Oct 8, 2020 at 08:36 UTC
ff01513f45a74d08fdd43f72461800a915e15c90
6 files changed
+27
-1
t/t4018/css-attribute-value-selector
new
+4
@@ -0,0 +1,4 @@
1
+[class*="RIGHT"] {
2
+ background : #000;
3
+ border : 10px ChangeMe #C6C6C6;
4
+}
t/t4018/css-block-level-@-statements
new
+10
@@ -0,0 +1,10 @@
1
+@keyframes RIGHT {
2
+ from {
3
+ background : #000;
4
+ border : 10px ChangeMe #C6C6C6;
5
+ }
6
+ to {
7
+ background : #fff;
8
+ border : 10px solid #C6C6C6;
9
+ }
10
+}
t/t4018/css-class-selector
new
+4
@@ -0,0 +1,4 @@
1
+.RIGHT {
2
+ background : #000;
3
+ border : 10px ChangeMe #C6C6C6;
4
+}
t/t4018/css-id-selector
new
+4
@@ -0,0 +1,4 @@
1
+#RIGHT {
2
+ background : #000;
3
+ border : 10px ChangeMe #C6C6C6;
4
+}
t/t4018/css-root-selector
new
+4
@@ -0,0 +1,4 @@
1
+:RIGHT {
2
+ background : #000;
3
+ border : 10px ChangeMe #C6C6C6;
4
+}
userdiff.c
+1
-1
@@ -200,7 +200,7 @@ PATTERNS("csharp",
200
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
201
IPATTERN("css",
202
"![:;][[:space:]]*$\n"
203
- "^[_a-z0-9].*$",
203
+ "^[:[@.#]?[_a-z0-9].*$",
204
/* -- */
205
/*
206
* This regex comes from W3C CSS specs. Should theoretically also