 
 props = qw 'fg bg bold italic underlined' # properties in style objects
 getModelAsObject = -> # keyed by token type, contains only diffs from defaults, suitable for putting in localStorage
-  v = {}; (for g, i in G then m = model[i]; for p in props when m[p] != g.d[p] then (v[g.t] ?= {})[p] = m[p]); v
+  v = {}
+  for g, i in G
+    m = model[i]
+    for p in props when m[p] != (g.d[p] || '') then (v[g.t] ?= {})[p] = m[p]
+  v
 
 @save = -> prefs.hi getModelAsObject(); return
 @resize = -> cm.setSize $cm.width(), $cm.height(); return

renderCSS = (v, rp = '') -> # v: style objects keyed by token type, rp: css rule prefix
  join G.map (g) ->
    h = $.extend {}, g.d, v[g.t] # h: effective style
    selector = g.c.split(',').map((x) -> rp + ' ' + x).join ','
    "#{selector}{color:#{h.fg};" +
      (h.bg         && "background-color:#{h.bg};"  || '') +
      (h.bold       && 'font-weight:bold;'          || '') +
      (h.italic     && 'font-style:italic;'         || '') +


selectGroup = (i, forceRefresh) ->
  if i != sel || forceRefresh
    h = model[i]; $('#col-group').val i
    $('#col-fg-cb').prop 'checked', !!h.fg; $('#col-fg').val(h.fg).toggle !!h.fg
    $('#col-bg-cb').prop 'checked', !!h.bg; $('#col-bg').val(h.bg).toggle !!h.bg
    $('#col-bold'      ).prop 'checked', !!h.bold
    $('#col-italic'    ).prop 'checked', !!h.italic
    $('#col-underlined').prop 'checked', !!h.underlined
