summaryrefslogtreecommitdiffstats
path: root/devtools/server/actors/utils/style-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/server/actors/utils/style-utils.js')
-rw-r--r--devtools/server/actors/utils/style-utils.js66
1 files changed, 5 insertions, 61 deletions
diff --git a/devtools/server/actors/utils/style-utils.js b/devtools/server/actors/utils/style-utils.js
index 5f2e912002..1d52448fb6 100644
--- a/devtools/server/actors/utils/style-utils.js
+++ b/devtools/server/actors/utils/style-utils.js
@@ -4,8 +4,6 @@
"use strict";
-const { getCSSLexer } = require("resource://devtools/shared/css/lexer.js");
-
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const FONT_PREVIEW_TEXT = "Abc";
const FONT_PREVIEW_FONT_SIZE = 40;
@@ -120,66 +118,12 @@ function getRuleText(initialText, line, column) {
throw new Error("Location information is missing");
}
- const { offset: textOffset, text } = getTextAtLineColumn(
- initialText,
- line,
- column
- );
- const lexer = getCSSLexer(text);
-
- // Search forward for the opening brace.
- while (true) {
- const token = lexer.nextToken();
- if (!token) {
- throw new Error("couldn't find start of the rule");
- }
- if (token.tokenType === "symbol" && token.text === "{") {
- break;
- }
- }
-
- // Now collect text until we see the matching close brace.
- let braceDepth = 1;
- let startOffset, endOffset;
- while (true) {
- const token = lexer.nextToken();
- if (!token) {
- break;
- }
- if (startOffset === undefined) {
- startOffset = token.startOffset;
- }
- if (token.tokenType === "symbol") {
- if (token.text === "{") {
- ++braceDepth;
- } else if (token.text === "}") {
- --braceDepth;
- if (braceDepth == 0) {
- break;
- }
- }
- }
- endOffset = token.endOffset;
- }
-
- // If the rule was of the form "selector {" with no closing brace
- // and no properties, just return an empty string.
- if (startOffset === undefined) {
- return { offset: 0, text: "" };
- }
- // If the input didn't have any tokens between the braces (e.g.,
- // "div {}"), then the endOffset won't have been set yet; so account
- // for that here.
- if (endOffset === undefined) {
- endOffset = startOffset;
+ const { text } = getTextAtLineColumn(initialText, line, column);
+ const res = InspectorUtils.getRuleBodyText(text);
+ if (res === null || typeof res === "undefined") {
+ throw new Error("Couldn't find rule");
}
-
- // Note that this approach will preserve comments, despite the fact
- // that cssTokenizer skips them.
- return {
- offset: textOffset + startOffset,
- text: text.substring(startOffset, endOffset),
- };
+ return res;
}
exports.getRuleText = getRuleText;