This commit is contained in:
Timothee Cour 2020-10-01 13:13:54 -07:00 • committed by GitHub
commit bd18fc980c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -303,6 +303,12 @@ proc sameAttrs*(a, b: VNode): bool =
proc addEventListener*(n: VNode; event: EventKind; handler: EventHandler) =
n.events.add((event, handler, nil))
when kstring is cstring:
proc len(a: kstring): int =
# xxx: maybe move where kstring is defined
# without this, `n.field.len` fails on js (non web) platform
if a == nil: 0 else: a.len
template toStringAttr(field) =
if n.field.len > 0:
result.add " " & astToStr(field) & " = " & $n.field

View file

@ -235,6 +235,9 @@ proc eq*(a, b: VStyle): bool =
return true
proc setAttr*(s: VStyle; a, value: kstring) {.noSideEffect.} =
## inserts (a, value) in sorted order of key `a`
# worst case quadratic complexity (if given styles in reverse order), hopefully
# not a concern assuming small cardinal
var i = 0
while i < s.len:
if s[i] == a:
@ -243,8 +246,8 @@ proc setAttr*(s: VStyle; a, value: kstring) {.noSideEffect.} =
elif s[i] > a:
s.add ""
s.add ""
# insertion point here:
for j in countdown(s.len-1, i, 2):
# insertion point here, shift all remaining pairs by 2 indexes
for j in countdown(s.len-1, i+3, 2):
s[j] = s[j-2]
s[j-1] = s[j-3]
s[i] = a