summaryrefslogtreecommitdiffstats
path: root/devtools/server/actors/utils/style-utils.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /devtools/server/actors/utils/style-utils.js
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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;