Skip to content

Commit

Permalink
Fixed grid and grid-gap ordering #137
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jun 14, 2023
1 parent 1f3d718 commit 12f61a1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Released on tbd.
- Fixed issue with appended EOF character in `CssText` (#123)
- Fixed missing semicolon in `@page` rule (#135)
- Fixed integer serialization of keyframe stops (#128)
- Fixed ordering of rows and columns in `grid` and `grid-gap` (#137)

# 0.17.0

Expand Down
16 changes: 16 additions & 0 deletions src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,5 +909,21 @@ public void CssGridTemplateLonghands_Issue68()
var style = ParseDeclarations(snippet);
Assert.AreEqual("grid-template: none", style.CssText);
}

[Test]
public void CssGridPreservesParts_Issue137()
{
var snippet = "grid: 10px / 80px";
var style = ParseDeclarations(snippet);
Assert.AreEqual("grid: 10px / 80px", style.CssText);
}

[Test]
public void CssGridGapPreservesParts_Issue137()
{
var snippet = "grid-gap: 10px 80px";
var style = ParseDeclarations(snippet);
Assert.AreEqual("grid-gap: 10px 80px", style.CssText);
}
}
}
4 changes: 2 additions & 2 deletions src/AngleSharp.Css/Declarations/GapDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ sealed class GapAggregagtor : IValueAggregator, IValueConverter

public ICssValue Merge(ICssValue[] values)
{
var col = values[0];
var row = values[1];
var row = values[0];
var col = values[1];

if (row != null || col != null)
{
Expand Down
51 changes: 26 additions & 25 deletions src/AngleSharp.Css/Declarations/GridDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace AngleSharp.Css.Declarations
using AngleSharp.Text;
using System;
using System.Collections.Generic;
using System.Linq;

static class GridDeclaration
{
Expand Down Expand Up @@ -37,11 +38,11 @@ public ICssValue Convert(StringSource source)
{
var template = source.ParseGridTemplate();

if (template == null)
if (template is null)
{
var rows = source.ParseTrackList() ?? source.ParseAutoTrackList();

if (rows != null)
if (rows is not null)
{
if (source.SkipSpacesAndComments() == Symbols.Solidus)
{
Expand Down Expand Up @@ -153,30 +154,30 @@ public ICssValue[] Split(ICssValue value)
gt.TemplateRows,
gt.TemplateColumns,
gt.TemplateAreas,
null,
null,
null,
null,
null,
null,
null,
null, //new Identifier(CssKeywords.Auto),
null, //new Identifier(CssKeywords.Auto),
null, //new Identifier(CssKeywords.Row),
null, //Length.Zero,
null, //Length.Zero,
null, //new Identifier(CssKeywords.Normal),
null, //new Identifier(CssKeywords.Normal),
};
}
else if (value is CssGridValue grid)
{
var dense = grid.Rows != null ? CssKeywords.Row : CssKeywords.Column;
var dense = grid.Rows is not null ? CssKeywords.Row : CssKeywords.Column;
return new[]
{
grid.Rows,
grid.Columns,
null,
grid.Columns != null ? new CssTupleValue(grid.Sizes) : null,
grid.Rows != null ? new CssTupleValue(grid.Sizes) : null,
grid.IsDense ? new Identifier(dense) as ICssValue : null,
null,
null,
null,
null,
null, //new Identifier(CssKeywords.None),
grid.Columns is not null ? new CssTupleValue(grid.Sizes) : null, //new Identifier(CssKeywords.Auto),
grid.Rows is not null ? new CssTupleValue(grid.Sizes) : null, //new Identifier(CssKeywords.Auto),
grid.IsDense ? new Identifier(dense) : null,
null, //Length.Zero,
null, //Length.Zero,
null, //new Identifier(CssKeywords.Normal),
null, //new Identifier(CssKeywords.Normal),
};
}
else if (value is Identifier)
Expand All @@ -186,13 +187,13 @@ public ICssValue[] Split(ICssValue value)
value,
value,
value,
null,
null,
null,
null,
null,
null,
null,
null, //new Identifier(CssKeywords.Auto),
null, //new Identifier(CssKeywords.Auto),
null, //new Identifier(CssKeywords.Row),
null, //Length.Zero,
null, //Length.Zero,
null, //new Identifier(CssKeywords.Normal),
null, //new Identifier(CssKeywords.Normal),
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/AngleSharp.Css/Declarations/GridGapDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ sealed class GridGapAggregagtor : IValueAggregator, IValueConverter

public ICssValue Merge(ICssValue[] values)
{
var col = values[0];
var row = values[1];
var row = values[0];
var col = values[1];

if (row != null || col != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static class GridTemplateAreasDeclaration

public static readonly String[] Shorthands = new[]
{
PropertyNames.Grid,
PropertyNames.GridTemplate,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static class GridTemplateColumnsDeclaration

public static readonly String[] Shorthands = new[]
{
PropertyNames.Grid,
PropertyNames.GridTemplate,
};

Expand Down
12 changes: 6 additions & 6 deletions src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public String ToCssBlock(IStyleFormatter formatter)
var usedProperties = new List<String>();
var shorthand = TryCreateShorthand(shorthandName, serialized, usedProperties, false);

if (shorthand != null)
if (shorthand is not null)
{
list.Add(shorthand);

Expand Down Expand Up @@ -278,17 +278,17 @@ public void SetProperty(String propertyName, String propertyValue, String priori

if (!String.IsNullOrEmpty(propertyValue))
{
if (priority == null || priority.Isi(CssKeywords.Important))
if (priority is null || priority.Isi(CssKeywords.Important))
{
var property = CreateProperty(propertyName);

if (property != null)
if (property is not null)
{
property.Value = propertyValue;

if (property.RawValue != null)
if (property.RawValue is not null)
{
property.IsImportant = priority != null;
property.IsImportant = priority is not null;
SetProperty(property);
RaiseChanged();
}
Expand Down Expand Up @@ -421,7 +421,7 @@ private void SetShorthand(ICssProperty shorthand)
{
var properties = _context.CreateLonghands(shorthand);

if (properties != null)
if (properties is not null)
{
foreach (var property in properties)
{
Expand Down

0 comments on commit 12f61a1

Please sign in to comment.