diff options
author | bptato <nincsnevem662@gmail.com> | 2022-08-23 19:02:52 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-08-23 19:02:52 +0200 |
commit | 48c236c0dbd58edebf558ebb822e4ceaa56038f2 (patch) | |
tree | c284dcaf5536c2235bbdd16677be4b179f21ba6e /src/css | |
parent | 01a6051deb585696be18e6b90e9214fd8f5a64df (diff) | |
download | chawan-48c236c0dbd58edebf558ebb822e4ceaa56038f2.tar.gz |
Fix :nth-last-child
Diffstat (limited to 'src/css')
-rw-r--r-- | src/css/match.nim | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/css/match.nim b/src/css/match.nim index 31eba22e..1fcb9fda 100644 --- a/src/css/match.nim +++ b/src/css/match.nim @@ -63,7 +63,7 @@ func pseudoSelectorMatches[T: Element|StyledNode](elem: T, sel: Selector, felem: inc i return false of PSEUDO_NTH_LAST_CHILD: - if sel.pseudo.ofsels.issome and not elem.selectorsMatch(sel.pseudo.ofsels.get): + if sel.pseudo.ofsels.issome and not selem.selectorsMatch(sel.pseudo.ofsels.get, felem): return false let A = sel.pseudo.anb.A # step let B = sel.pseudo.anb.B # start @@ -72,9 +72,15 @@ func pseudoSelectorMatches[T: Element|StyledNode](elem: T, sel: Selector, felem: else: selem.parentNode if parent == nil: return false for child in parent.children_rev: + when selem is StyledNode: + if not child.isDomElement: continue if child == selem: - return i == B or i > B and A != 0 and (i - B) mod A == 0 - if sel.pseudo.ofsels.isnone or child.selectorsMatch(sel.pseudo.ofsels.get): + if A == 0: + return i == B + if A < 0: + return (i - B) <= 0 and (i - B) mod A == 0 + return (i - B) >= 0 and (i - B) mod A == 0 + if sel.pseudo.ofsels.isnone or child.selectorsMatch(sel.pseudo.ofsels.get, felem): inc i return false of PSEUDO_CHECKED: |