diff --git a/src/language/CSSUtils.js b/src/language/CSSUtils.js index 7984882386d..6ad0da3c800 100644 --- a/src/language/CSSUtils.js +++ b/src/language/CSSUtils.js @@ -81,6 +81,20 @@ define(function (require, exports, module) { return (/\S/.test(text)); } + /** + * @private + * Returns state of a token + * @param {{editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}}} ctx + * @return {{tokenize:function, state:string, stateArg:string, context:Object}} + */ + function _getState(ctx) { + var state = ctx.token.state.localState || ctx.token.state; + if (!state.context && ctx.token.state.html.localState) { + state = ctx.token.state.html.localState; + } + return state; + } + /** * @private * Checks if the current cursor position is inside the property name context @@ -88,14 +102,12 @@ define(function (require, exports, module) { * @return {boolean} true if the context is in property name */ function _isInPropName(ctx) { - var state, + var state = _getState(ctx), lastToken; - if (!ctx || !ctx.token || !ctx.token.state || ctx.token.type === "comment") { + if (!state || !ctx || !ctx.token || ctx.token.type === "comment") { return false; } - state = ctx.token.state.localState || ctx.token.state; - if (!state.context) { return false; } @@ -124,13 +136,11 @@ define(function (require, exports, module) { return isInsideParens(context.prev); } - var state; - if (!ctx || !ctx.token || !ctx.token.state || ctx.token.type === "comment") { + var state = _getState(ctx); + if (!state || !ctx || !ctx.token || ctx.token.type === "comment") { return false; } - state = ctx.token.state.localState || ctx.token.state; - if (!state.context || !state.context.prev) { return false; } @@ -146,13 +156,11 @@ define(function (require, exports, module) { * @return {boolean} true if the context is in property value */ function _isInAtRule(ctx) { - var state; - if (!ctx || !ctx.token || !ctx.token.state) { + var state = _getState(ctx); + if (!state || !ctx || !ctx.token) { return false; } - state = ctx.token.state.localState || ctx.token.state; - if (!state.context) { return false; } @@ -1566,12 +1574,13 @@ define(function (require, exports, module) { return selector; } - var skipPrevSibling = false; + var skipPrevSibling = false, + state = _getState(ctx); // If the cursor is inside a non-whitespace token with "block" or "top" state, then it is inside a // selector. The only exception is when it is immediately after the '{'. if (isPreprocessorDoc && _hasNonWhitespace(ctx.token.string) && ctx.token.string !== "{" && - (ctx.token.state.state === "block" || ctx.token.state.state === "top")) { + (state.state === "block" || state.state === "top")) { foundChars = true; } @@ -1580,7 +1589,7 @@ define(function (require, exports, module) { if (ctx.token.type !== "comment") { if (ctx.token.string === "}") { if (isPreprocessorDoc) { - if (ctx.token.state.state === "top") { + if (state.state === "top") { break; } skipPrevSibling = true;