Skip to content

Latest commit

 

History

History
230 lines (174 loc) · 9.23 KB

File metadata and controls

230 lines (174 loc) · 9.23 KB

Import :

const CSSUtils = brackets.getModule("language/CSSUtils")

CodeMirror

Set of utilities for simple parsing of CSS text.

Kind: global variable

SELECTOR : string

CSS selector, used to target specific elements

Kind: global constant

PROP_NAME : string

name of the property

Kind: global constant

PROP_VALUE : string

value of the specified property

Kind: global constant

IMPORT_URL : string

url for import

Kind: global constant

isCSSPreprocessorFile(filePath) ⇒ boolean

Determines if the given path is a CSS preprocessor file that CSSUtils supports.

Kind: global function
Returns: boolean - true if LanguageManager identifies filePath as less or scss language.

Param Type Description
filePath string Absolute path to the file.

getInfoAtPos(editor, constPos) ⇒ Object

Returns a context info object for the given cursor position

Kind: global function
Returns: Object - A CSS context info object.

Param Type Description
editor Editor
constPos Object A CM pos (likely from editor.getCursorPos())

getInfoAtPos._contextCM

We will use this CM to cook css context in case of style attribute value as CM in htmlmixed mode doesn't yet identify this as css context. We provide a no-op display function to run CM without a DOM head.

Kind: inner property of getInfoAtPos

getCompleteSelectors(info, [useGroup]) ⇒ string

Return a string that shows the literal parent hierarchy of the selector in info.

Kind: global function
Returns: string - the literal parent hierarchy of the selector

Param Type Description
info SelectorInfo
[useGroup] boolean true to append selectorGroup instead of selector

extractAllSelectors(text, documentMode) ⇒ Array.<SelectorInfo>

Extracts all CSS selectors from the given text Returns an array of SelectorInfo. Each SelectorInfo is an object with the following properties: selector: the text of the selector (note: comma separated selector groups like "h1, h2" are broken into separate selectors) ruleStartLine: line in the text where the rule (including preceding comment) appears ruleStartChar: column in the line where the rule (including preceding comment) starts selectorStartLine: line in the text where the selector appears selectorStartChar: column in the line where the selector starts selectorEndLine: line where the selector ends selectorEndChar: column where the selector ends selectorGroupStartLine: line where the comma-separated selector group (e.g. .foo, .bar, .baz) starts that this selector (e.g. .baz) is part of. Particularly relevant for groups that are on multiple lines. selectorGroupStartChar: column in line where the selector group starts. selectorGroup: the entire selector group containing this selector, or undefined if there is only one selector in the rule. declListStartLine: line where the declaration list for the rule starts declListStartChar: column in line where the declaration list for the rule starts declListEndLine: line where the declaration list for the rule ends declListEndChar: column in the line where the declaration list for the rule ends level: the level of the current selector including any containing @media block in the nesting level count. Use this property with caution since it is primarily for internal parsing use. For example, two sibling selectors may have different levels if one of them is nested inside an @media block and it should not be used for sibling info. parentSelectors: all ancestor selectors separated with '/' if the current selector is a nested one

Kind: global function
Returns: Array.<SelectorInfo> - Array with objects specifying selectors.

Param Type Description
text string CSS text to extract from
documentMode string language mode of the document that text belongs to, default to css if undefined.

findMatchingRules(selector, htmlDocument) ⇒ $.Promise

Return all rules matching the specified selector. For now, we only look at the rightmost simple selector. For example, searching for ".foo" will match these rules: .foo {} div .foo {} div.foo {} div .foo[bar="42"] {} div .foo:hovered {} div .foo::first-child but will not match these rules: .foobar {} .foo .bar {} div .foo .bar {} .foo.bar {}

Kind: global function
Returns: $.Promise - that will be resolved with an Array of objects containing the source document, start line, and end line (0-based, inclusive range) for each matching declaration list. Does not addRef() the documents returned in the array.

Param Type Description
selector string The selector to match. This can be a tag selector, class selector or id selector
htmlDocument Document An HTML file for context (so we can search 'style' blocks)

findSelectorAtDocumentPos(editor, pos) ⇒ string

Returns the selector(s) of the rule at the specified document pos, or "" if the position is is not within a style rule.

Kind: global function
Returns: string - Selector(s) for the rule at the specified position, or "" if the position is not within a style rule. If the rule has multiple selectors, a comma-separated selector string is returned.

Param Type Description
editor Editor Editor to search
pos Object Position to search

reduceStyleSheetForRegExParsing(content) ⇒ string

Reduces the style sheet by removing comments and strings so that the content can be parsed using a regular expression

Kind: global function
Returns: string - reduced content

Param Type Description
content string to reduce

addRuleToDocument(doc, selector, useTabChar, indentUnit) ⇒ Object

Adds a new rule to the end of the given document, and returns the range of the added rule and the position of the cursor on the indented blank line within it. Note that the range will not include all the inserted text (we insert extra newlines before and after the rule).

Kind: global function
Returns: Object - The range of the inserted rule and the location where the cursor should be placed.

Param Type Description
doc Document The document to insert the rule into.
selector string The selector to use for the given rule.
useTabChar boolean Whether to indent with a tab.
indentUnit number If useTabChar is false, how many spaces to indent with.

consolidateRules()

In the given rule array (as returned by findMatchingRules()), if multiple rules in a row refer to the same rule (because there were multiple matching selectors), eliminate the redundant rules. Also, always use the selector group if available instead of the original matching selector.

Kind: global function

getRangeSelectors(range) ⇒ string

Given a TextRange, extracts the selector(s) for the rule in the range and returns it. Assumes the range only contains one rule; if there's more than one, it will return the selector(s) for the first rule.

Kind: global function
Returns: string - The selector(s) for the rule in the range.

Param Type Description
range TextRange The range to extract the selector(s) from.

getAllCssSelectorsInProject(options)

Responsible to get all the CSS selectors in project

Kind: global function

Param Type
options Object

SelectorInfo : Object

Kind: global typedef