Skip to content

Commit 12f61a1

Browse files
committed
Fixed grid and grid-gap ordering #137
1 parent 1f3d718 commit 12f61a1

File tree

8 files changed

+55
-35
lines changed

8 files changed

+55
-35
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Released on tbd.
77
- Fixed issue with appended EOF character in `CssText` (#123)
88
- Fixed missing semicolon in `@page` rule (#135)
99
- Fixed integer serialization of keyframe stops (#128)
10+
- Fixed ordering of rows and columns in `grid` and `grid-gap` (#137)
1011

1112
# 0.17.0
1213

src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs

+16
Original file line numberDiff line numberDiff line change
@@ -909,5 +909,21 @@ public void CssGridTemplateLonghands_Issue68()
909909
var style = ParseDeclarations(snippet);
910910
Assert.AreEqual("grid-template: none", style.CssText);
911911
}
912+
913+
[Test]
914+
public void CssGridPreservesParts_Issue137()
915+
{
916+
var snippet = "grid: 10px / 80px";
917+
var style = ParseDeclarations(snippet);
918+
Assert.AreEqual("grid: 10px / 80px", style.CssText);
919+
}
920+
921+
[Test]
922+
public void CssGridGapPreservesParts_Issue137()
923+
{
924+
var snippet = "grid-gap: 10px 80px";
925+
var style = ParseDeclarations(snippet);
926+
Assert.AreEqual("grid-gap: 10px 80px", style.CssText);
927+
}
912928
}
913929
}

src/AngleSharp.Css/Declarations/GapDeclaration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ sealed class GapAggregagtor : IValueAggregator, IValueConverter
3030

3131
public ICssValue Merge(ICssValue[] values)
3232
{
33-
var col = values[0];
34-
var row = values[1];
33+
var row = values[0];
34+
var col = values[1];
3535

3636
if (row != null || col != null)
3737
{

src/AngleSharp.Css/Declarations/GridDeclaration.cs

+26-25
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace AngleSharp.Css.Declarations
66
using AngleSharp.Text;
77
using System;
88
using System.Collections.Generic;
9+
using System.Linq;
910

1011
static class GridDeclaration
1112
{
@@ -37,11 +38,11 @@ public ICssValue Convert(StringSource source)
3738
{
3839
var template = source.ParseGridTemplate();
3940

40-
if (template == null)
41+
if (template is null)
4142
{
4243
var rows = source.ParseTrackList() ?? source.ParseAutoTrackList();
4344

44-
if (rows != null)
45+
if (rows is not null)
4546
{
4647
if (source.SkipSpacesAndComments() == Symbols.Solidus)
4748
{
@@ -153,30 +154,30 @@ public ICssValue[] Split(ICssValue value)
153154
gt.TemplateRows,
154155
gt.TemplateColumns,
155156
gt.TemplateAreas,
156-
null,
157-
null,
158-
null,
159-
null,
160-
null,
161-
null,
162-
null,
157+
null, //new Identifier(CssKeywords.Auto),
158+
null, //new Identifier(CssKeywords.Auto),
159+
null, //new Identifier(CssKeywords.Row),
160+
null, //Length.Zero,
161+
null, //Length.Zero,
162+
null, //new Identifier(CssKeywords.Normal),
163+
null, //new Identifier(CssKeywords.Normal),
163164
};
164165
}
165166
else if (value is CssGridValue grid)
166167
{
167-
var dense = grid.Rows != null ? CssKeywords.Row : CssKeywords.Column;
168+
var dense = grid.Rows is not null ? CssKeywords.Row : CssKeywords.Column;
168169
return new[]
169170
{
170171
grid.Rows,
171172
grid.Columns,
172-
null,
173-
grid.Columns != null ? new CssTupleValue(grid.Sizes) : null,
174-
grid.Rows != null ? new CssTupleValue(grid.Sizes) : null,
175-
grid.IsDense ? new Identifier(dense) as ICssValue : null,
176-
null,
177-
null,
178-
null,
179-
null,
173+
null, //new Identifier(CssKeywords.None),
174+
grid.Columns is not null ? new CssTupleValue(grid.Sizes) : null, //new Identifier(CssKeywords.Auto),
175+
grid.Rows is not null ? new CssTupleValue(grid.Sizes) : null, //new Identifier(CssKeywords.Auto),
176+
grid.IsDense ? new Identifier(dense) : null,
177+
null, //Length.Zero,
178+
null, //Length.Zero,
179+
null, //new Identifier(CssKeywords.Normal),
180+
null, //new Identifier(CssKeywords.Normal),
180181
};
181182
}
182183
else if (value is Identifier)
@@ -186,13 +187,13 @@ public ICssValue[] Split(ICssValue value)
186187
value,
187188
value,
188189
value,
189-
null,
190-
null,
191-
null,
192-
null,
193-
null,
194-
null,
195-
null,
190+
null, //new Identifier(CssKeywords.Auto),
191+
null, //new Identifier(CssKeywords.Auto),
192+
null, //new Identifier(CssKeywords.Row),
193+
null, //Length.Zero,
194+
null, //Length.Zero,
195+
null, //new Identifier(CssKeywords.Normal),
196+
null, //new Identifier(CssKeywords.Normal),
196197
};
197198
}
198199

src/AngleSharp.Css/Declarations/GridGapDeclaration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ sealed class GridGapAggregagtor : IValueAggregator, IValueConverter
3030

3131
public ICssValue Merge(ICssValue[] values)
3232
{
33-
var col = values[0];
34-
var row = values[1];
33+
var row = values[0];
34+
var col = values[1];
3535

3636
if (row != null || col != null)
3737
{

src/AngleSharp.Css/Declarations/GridTemplateAreasDeclaration.cs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static class GridTemplateAreasDeclaration
1111

1212
public static readonly String[] Shorthands = new[]
1313
{
14+
PropertyNames.Grid,
1415
PropertyNames.GridTemplate,
1516
};
1617

src/AngleSharp.Css/Declarations/GridTemplateColumnsDeclaration.cs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static class GridTemplateColumnsDeclaration
1010

1111
public static readonly String[] Shorthands = new[]
1212
{
13+
PropertyNames.Grid,
1314
PropertyNames.GridTemplate,
1415
};
1516

src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public String ToCssBlock(IStyleFormatter formatter)
175175
var usedProperties = new List<String>();
176176
var shorthand = TryCreateShorthand(shorthandName, serialized, usedProperties, false);
177177

178-
if (shorthand != null)
178+
if (shorthand is not null)
179179
{
180180
list.Add(shorthand);
181181

@@ -278,17 +278,17 @@ public void SetProperty(String propertyName, String propertyValue, String priori
278278

279279
if (!String.IsNullOrEmpty(propertyValue))
280280
{
281-
if (priority == null || priority.Isi(CssKeywords.Important))
281+
if (priority is null || priority.Isi(CssKeywords.Important))
282282
{
283283
var property = CreateProperty(propertyName);
284284

285-
if (property != null)
285+
if (property is not null)
286286
{
287287
property.Value = propertyValue;
288288

289-
if (property.RawValue != null)
289+
if (property.RawValue is not null)
290290
{
291-
property.IsImportant = priority != null;
291+
property.IsImportant = priority is not null;
292292
SetProperty(property);
293293
RaiseChanged();
294294
}
@@ -421,7 +421,7 @@ private void SetShorthand(ICssProperty shorthand)
421421
{
422422
var properties = _context.CreateLonghands(shorthand);
423423

424-
if (properties != null)
424+
if (properties is not null)
425425
{
426426
foreach (var property in properties)
427427
{

0 commit comments

Comments
 (0)