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

Commit 5f5579b

Browse files
committed
Merge pull request #11751 from sprintr/css-code-hints-php
Allow CSS Code Hints in PHP
2 parents de9c39a + 439d185 commit 5f5579b

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

src/language/CSSUtils.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,36 @@ define(function (require, exports, module) {
8181
return (/\S/.test(text));
8282
}
8383

84+
/**
85+
* @private
86+
* Returns state of a context
87+
* @param {{editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}}} ctx
88+
* @return {{tokenize:function, state:string, stateArg:string, context:Object}}
89+
*/
90+
function _getContextState(ctx) {
91+
if (!ctx || !ctx.token) {
92+
return null;
93+
}
94+
var state = ctx.token.state.localState || ctx.token.state;
95+
if (!state.context && ctx.token.state.html.localState) {
96+
state = ctx.token.state.html.localState;
97+
}
98+
return state;
99+
}
100+
84101
/**
85102
* @private
86103
* Checks if the current cursor position is inside the property name context
87104
* @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} context
88105
* @return {boolean} true if the context is in property name
89106
*/
90107
function _isInPropName(ctx) {
91-
var state,
108+
var state = _getContextState(ctx),
92109
lastToken;
93-
if (!ctx || !ctx.token || !ctx.token.state || ctx.token.type === "comment") {
110+
if (!state || !state.context || ctx.token.type === "comment") {
94111
return false;
95112
}
96113

97-
state = ctx.token.state.localState || ctx.token.state;
98-
99-
if (!state.context) {
100-
return false;
101-
}
102-
103114
lastToken = state.context.type;
104115
return (lastToken === "{" || lastToken === "rule" || lastToken === "block");
105116
}
@@ -124,16 +135,11 @@ define(function (require, exports, module) {
124135
return isInsideParens(context.prev);
125136
}
126137

127-
var state;
128-
if (!ctx || !ctx.token || !ctx.token.state || ctx.token.type === "comment") {
138+
var state = _getContextState(ctx);
139+
if (!state || !state.context || !state.context.prev || ctx.token.type === "comment") {
129140
return false;
130141
}
131142

132-
state = ctx.token.state.localState || ctx.token.state;
133-
134-
if (!state.context || !state.context.prev) {
135-
return false;
136-
}
137143
return ((state.context.type === "prop" &&
138144
(state.context.prev.type === "rule" || state.context.prev.type === "block")) ||
139145
isInsideParens(state.context));
@@ -146,14 +152,8 @@ define(function (require, exports, module) {
146152
* @return {boolean} true if the context is in property value
147153
*/
148154
function _isInAtRule(ctx) {
149-
var state;
150-
if (!ctx || !ctx.token || !ctx.token.state) {
151-
return false;
152-
}
153-
154-
state = ctx.token.state.localState || ctx.token.state;
155-
156-
if (!state.context) {
155+
var state = _getContextState(ctx);
156+
if (!state || !state.context) {
157157
return false;
158158
}
159159
return (state.context.type === "at");
@@ -1566,12 +1566,13 @@ define(function (require, exports, module) {
15661566
return selector;
15671567
}
15681568

1569-
var skipPrevSibling = false;
1569+
var skipPrevSibling = false,
1570+
state = _getContextState(ctx);
15701571

15711572
// If the cursor is inside a non-whitespace token with "block" or "top" state, then it is inside a
15721573
// selector. The only exception is when it is immediately after the '{'.
15731574
if (isPreprocessorDoc && _hasNonWhitespace(ctx.token.string) && ctx.token.string !== "{" &&
1574-
(ctx.token.state.state === "block" || ctx.token.state.state === "top")) {
1575+
(state.state === "block" || state.state === "top")) {
15751576
foundChars = true;
15761577
}
15771578

@@ -1580,7 +1581,7 @@ define(function (require, exports, module) {
15801581
if (ctx.token.type !== "comment") {
15811582
if (ctx.token.string === "}") {
15821583
if (isPreprocessorDoc) {
1583-
if (ctx.token.state.state === "top") {
1584+
if (state.state === "top") {
15841585
break;
15851586
}
15861587
skipPrevSibling = true;

0 commit comments

Comments
 (0)