diff --git a/src/editor/CSSInlineEditor.js b/src/editor/CSSInlineEditor.js index 04f945141cb..4bf0b69f17e 100644 --- a/src/editor/CSSInlineEditor.js +++ b/src/editor/CSSInlineEditor.js @@ -22,7 +22,7 @@ */ -/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ +/*jslint regexp: true, vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ /*global define, $, window, Mustache */ define(function (require, exports, module) { @@ -75,7 +75,7 @@ define(function (require, exports, module) { // class="error-dialog modal hide" // and the insertion point is inside "modal", we want ".modal" var attributeValue = tagInfo.attr.value; - if (attributeValue.trim()) { + if (/\S/.test(attributeValue)) { var startIndex = attributeValue.substr(0, tagInfo.position.offset).lastIndexOf(" "); var endIndex = attributeValue.indexOf(" ", tagInfo.position.offset); selectorName = "." + diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index 5ba7e49b274..5cb11d464c9 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -303,7 +303,7 @@ define(function (require, exports, module) { var result, text, line; // Move the context to the first non-empty token. - if (!ctx.token.type && ctx.token.string.trim().length === 0) { + if (!ctx.token.type && !/\S/.test(ctx.token.string)) { result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx); } diff --git a/src/extensions/default/JavaScriptCodeHints/Session.js b/src/extensions/default/JavaScriptCodeHints/Session.js index f8cc9fdcfc6..a269a93923b 100644 --- a/src/extensions/default/JavaScriptCodeHints/Session.js +++ b/src/extensions/default/JavaScriptCodeHints/Session.js @@ -200,7 +200,7 @@ define(function (require, exports, module) { break; } prev = this.getToken(cursor); - } while (prev.string.trim() === ""); + } while (!/\S/.test(prev.string)); return prev; }; @@ -232,7 +232,7 @@ define(function (require, exports, module) { break; } next = this.getToken(cursor); - } while (skipWhitespace && next.string.trim() === ""); + } while (skipWhitespace && !/\S/.test(next.string)); return next; }; diff --git a/src/extensions/default/JavaScriptQuickEdit/main.js b/src/extensions/default/JavaScriptQuickEdit/main.js index 5b0303ea08f..e72446f1e4e 100644 --- a/src/extensions/default/JavaScriptQuickEdit/main.js +++ b/src/extensions/default/JavaScriptQuickEdit/main.js @@ -49,7 +49,7 @@ define(function (require, exports, module) { // If the pos is at the beginning of a name, token will be the // preceding whitespace or dot. In that case, try the next pos. - if (token.string.trim().length === 0 || token.string === ".") { + if (!/\S/.test(token.string) || token.string === ".") { token = hostEditor._codeMirror.getTokenAt({line: pos.line, ch: pos.ch + 1}, true); } diff --git a/src/extensions/samples/InlineImageViewer/main.js b/src/extensions/samples/InlineImageViewer/main.js index 173ac0e4d7c..7dfce389375 100644 --- a/src/extensions/samples/InlineImageViewer/main.js +++ b/src/extensions/samples/InlineImageViewer/main.js @@ -47,7 +47,7 @@ define(function (require, exports, module) { // If the pos is at the beginning of a name, token will be the // preceding whitespace or dot. In that case, try the next pos. - if (token.string.trim().length === 0 || token.string === ".") { + if (!/\S/.match(token.string) || token.string === ".") { token = hostEditor._codeMirror.getTokenAt({line: pos.line, ch: pos.ch + 1}, true); } diff --git a/src/language/CSSUtils.js b/src/language/CSSUtils.js index 348badcbca3..66a99e35195 100644 --- a/src/language/CSSUtils.js +++ b/src/language/CSSUtils.js @@ -184,7 +184,7 @@ define(function (require, exports, module) { if (ctx.token.type === "property" || ctx.token.type === "property error" || ctx.token.type === "tag") { propName = tokenString; - if (TokenUtils.movePrevToken(ctx) && ctx.token.string.trim() !== "" && + if (TokenUtils.movePrevToken(ctx) && /\S/.test(ctx.token.string) && excludedCharacters.indexOf(ctx.token.string) === -1) { propName = ctx.token.string + tokenString; offset += ctx.token.string.length; @@ -196,7 +196,7 @@ define(function (require, exports, module) { ctx.token.type === "tag")) { propName += ctx.token.string; } - } else if (tokenString.trim() !== "" && excludedCharacters.indexOf(tokenString) === -1) { + } else if (/\S/.test(tokenString) && excludedCharacters.indexOf(tokenString) === -1) { // We're not inside the property name context. return createInfo(); } else { @@ -360,14 +360,14 @@ define(function (require, exports, module) { // Skip the ":" and any leading whitespace while (TokenUtils.moveNextToken(startCtx)) { - if (startCtx.token.string.trim()) { + if (/\S/.test(startCtx.token.string)) { break; } } // Skip the trailing whitespace and property separators. while (endCtx.token.string === ";" || endCtx.token.string === "}" || - !endCtx.token.string.trim()) { + !/\S/.test(endCtx.token.string)) { TokenUtils.movePrevToken(endCtx); } @@ -1033,7 +1033,7 @@ define(function (require, exports, module) { result.push(entry); } else if (!classOrIdSelector) { // Special case for tag selectors - match "*" as the rightmost character - if (entry.selector.trim().search(/\*$/) !== -1) { + if (/\*\s*$/.test(entry.selector)) { result.push(entry); } } @@ -1230,7 +1230,7 @@ define(function (require, exports, module) { selector = _parseSelector(ctx); break; } else { - if (ctx.token.string.trim() !== "") { + if (/\S/.test(ctx.token.string)) { foundChars = true; } } @@ -1249,7 +1249,7 @@ define(function (require, exports, module) { // special case - we aren't in a selector and haven't found any chars, // look at the next immediate token to see if it is non-whitespace if (!selector && !foundChars) { - if (TokenUtils.moveNextToken(ctx) && ctx.token.type !== "comment" && ctx.token.string.trim() !== "") { + if (TokenUtils.moveNextToken(ctx) && ctx.token.type !== "comment" && /\S/.test(ctx.token.string)) { foundChars = true; ctx = TokenUtils.getInitialContext(cm, $.extend({}, pos)); } diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index 9c7a0279dc9..2ff22a27cda 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -153,7 +153,7 @@ define(function (require, exports, module) { } // If we type the first letter of the next attribute, it comes as an error // token. We need to double check for possible invalidated attributes. - if (forwardCtx.token.string.trim() !== "" && + if (/\S/.test(forwardCtx.token.string) && forwardCtx.token.string.indexOf("\"") === -1 && forwardCtx.token.string.indexOf("'") === -1 && forwardCtx.token.string.indexOf("=") === -1) { @@ -316,7 +316,7 @@ define(function (require, exports, module) { } //check and see where we are in the tag - if (ctx.token.string.length > 0 && ctx.token.string.trim().length === 0) { + if (ctx.token.string.length > 0 && !/\S/.test(ctx.token.string)) { // token at (i.e. before) pos is whitespace, so test token at next pos // @@ -326,7 +326,7 @@ define(function (require, exports, module) { var testPos = {ch: ctx.pos.ch + 1, line: ctx.pos.line}, testToken = editor._codeMirror.getTokenAt(testPos, true); - if (testToken.string.length > 0 && testToken.string.trim().length > 0 && + if (testToken.string.length > 0 && /\S/.test(testToken.string) && testToken.string.charAt(0) !== ">") { // pos has whitespace before it and non-whitespace after it, so use token after ctx.token = testToken; diff --git a/src/utils/TokenUtils.js b/src/utils/TokenUtils.js index ec12ed726d3..0ee085ccfaa 100644 --- a/src/utils/TokenUtils.js +++ b/src/utils/TokenUtils.js @@ -113,7 +113,7 @@ define(function (require, exports, module) { if (!moveFxn(ctx)) { return false; } - while (!ctx.token.type && ctx.token.string.trim().length === 0) { + while (!ctx.token.type && !/\S/.test(ctx.token.string)) { if (!moveFxn(ctx)) { return false; } diff --git a/test/spec/InlineEditorProviders-test-files/test1.css b/test/spec/InlineEditorProviders-test-files/test1.css index ce1a29576aa..db6adcc125b 100644 --- a/test/spec/InlineEditorProviders-test-files/test1.css +++ b/test/spec/InlineEditorProviders-test-files/test1.css @@ -7,6 +7,10 @@ {{5}} color: #f00; {{6}} }{{3}} {{7}} +{{8}}.bar { + background-image: url(fu.bar); +} + {{2}}#myDiv { display: block; } \ No newline at end of file diff --git a/test/spec/InlineEditorProviders-test-files/test1.html b/test/spec/InlineEditorProviders-test-files/test1.html index 80abdaab32d..9341d310deb 100644 --- a/test/spec/InlineEditorProviders-test-files/test1.html +++ b/test/spec/InlineEditorProviders-test-files/test1.html @@ -16,5 +16,6 @@