Skip to content
Browse files

Quote complex font names when cycling (issue 5390)

  • Loading branch information...
1 parent e34d84c commit 2dc93d893b2da7d84615a94d80c5de0a7781a0e7 @simonlindholm simonlindholm committed May 22, 2012
Showing with 31 additions and 11 deletions.
  1. +31 −11 extension/content/firebug/css/cssPanel.js
View
42 extension/content/firebug/css/cssPanel.js
@@ -1727,18 +1727,38 @@ CSSEditor.prototype = domplate(Firebug.InlineEditor.prototype,
keywords = Arr.merge(keywords, ar);
}
- var q = expr.charAt(0);
- if (expr.length > 1 && (q === '"' || q === "'"))
+ var q = expr.charAt(0), isQuoted = (q === '"' || q === "'");
+ if (!isQuoted)
{
- keywords = keywords.slice();
- for (var i = 0; i < keywords.length; ++i)
- {
- // Treat values starting with capital letters as font names
- // that can be quoted.
- var k = keywords[i];
- if (k.charAt(0).toLowerCase() !== k.charAt(0))
- keywords[i] = q + k + q;
- }
+ // Default to ' quotes, unless " occurs somewhere.
+ q = (/"/.test(preExpr + postExpr) ? '"' : "'");
+ }
+
+ // Don't complete '.
+ if (expr.length <= 1 && isQuoted)
+ return [];
+
+ // When completing, quote fonts if the input is quoted; when
+ // cycling, quote them instead in the way the user seems to
+ // expect to have them quoted.
+ var reSimple = /^[a-z][a-z0-9-]*$/i;
+ var isComplex = !reSimple.test(expr.replace(/^['"]?|['"]?$/g, ""));
+ var quote = function(str)
+ {
+ if (!cycle || isComplex !== isQuoted)
+ return (isQuoted ? q + str + q : str);
+ else
+ return (reSimple.test(str) ? str : q + str + q);
+ };
+
+ keywords = keywords.slice();
+ for (var i = 0; i < keywords.length; ++i)
+ {
+ // Treat values starting with capital letters as font names
+ // that can be quoted.
+ var k = keywords[i];
+ if (k.charAt(0).toLowerCase() !== k.charAt(0))
+ keywords[i] = quote(k);
}
}
else

0 comments on commit 2dc93d8

Please sign in to comment.
Something went wrong with that request. Please try again.