Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Allow CSS Code Hints in PHP #11751

Merged
merged 1 commit into from
Sep 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions src/language/CSSUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,36 @@ define(function (require, exports, module) {
return (/\S/.test(text));
}

/**
* @private
* Returns state of a context
* @param {{editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}}} ctx
* @return {{tokenize:function, state:string, stateArg:string, context:Object}}
*/
function _getContextState(ctx) {
if (!ctx || !ctx.token) {
return null;
}
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
* @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} context
* @return {boolean} true if the context is in property name
*/
function _isInPropName(ctx) {
var state,
var state = _getContextState(ctx),
lastToken;
if (!ctx || !ctx.token || !ctx.token.state || ctx.token.type === "comment") {
if (!state || !state.context || ctx.token.type === "comment") {
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, and twice below, you should move the check at the end of the if (after you are sure ctx is valid)
or simply move the assignment after the first if.

}

state = ctx.token.state.localState || ctx.token.state;

if (!state.context) {
return false;
}

lastToken = state.context.type;
return (lastToken === "{" || lastToken === "rule" || lastToken === "block");
}
Expand All @@ -124,16 +135,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 = _getContextState(ctx);
if (!state || !state.context || !state.context.prev || ctx.token.type === "comment") {
return false;
}

state = ctx.token.state.localState || ctx.token.state;

if (!state.context || !state.context.prev) {
return false;
}
return ((state.context.type === "prop" &&
(state.context.prev.type === "rule" || state.context.prev.type === "block")) ||
isInsideParens(state.context));
Expand All @@ -146,14 +152,8 @@ 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) {
return false;
}

state = ctx.token.state.localState || ctx.token.state;

if (!state.context) {
var state = _getContextState(ctx);
if (!state || !state.context) {
return false;
}
return (state.context.type === "at");
Expand Down Expand Up @@ -1566,12 +1566,13 @@ define(function (require, exports, module) {
return selector;
}

var skipPrevSibling = false;
var skipPrevSibling = false,
state = _getContextState(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;
}

Expand All @@ -1580,7 +1581,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;
Expand Down