TokenUtils
Import :
const TokenUtils = brackets.getModule("utils/TokenUtils")
_
Functions for iterating through tokens in the current editor buffer. Useful for doing light parsing that can rely purely on information gathered by the code coloring mechanism.
Kind: global variable
getTokenAt(cm, pos, precise) ⇒ Object
Like cm.getTokenAt, but with caching. Way more performant for long lines.
Kind: global function
Returns: Object - Token for position
| Param | Type | Description |
|---|---|---|
| cm | CodeMirror | |
| pos | Object | |
| precise | boolean | If given, results in more current results. Suppresses caching. |
getInitialContext(cm, pos) ⇒ Object
Creates a context object for the given editor and position, suitable for passing to the move functions.
Kind: global function
| Param | Type |
|---|---|
| cm | CodeMirror |
| pos | Object |
movePrevToken(ctx, [precise]) ⇒ boolean
Moves the given context backwards by one token.
Kind: global function
Returns: boolean - whether the context changed
| Param | Type | Description |
|---|---|---|
| ctx | Object | |
| [precise] | boolean | If code is being edited, use true (default) for accuracy. If parsing unchanging code, use false to use cache for performance. |
isAtStart(ctx) ⇒ boolean
Kind: global function
Returns: boolean - true if movePrevToken() would return false without changing pos
| Param | Type |
|---|---|
| ctx | Object |
moveNextToken(ctx, [precise]) ⇒ boolean
Moves the given context forward by one token.
Kind: global function
Returns: boolean - whether the context changed
| Param | Type | Description |
|---|---|---|
| ctx | Object | |
| [precise] | boolean | If code is being edited, use true (default) for accuracy. If parsing unchanging code, use false to use cache for performance. |
isAtEnd(ctx) ⇒ boolean
Kind: global function
Returns: boolean - true if moveNextToken() would return false without changing pos
| Param | Type |
|---|---|
| ctx | Object |
moveSkippingWhitespace(moveFxn, ctx) ⇒ boolean
Moves the given context in the given direction, skipping any whitespace it hits.
Kind: global function
Returns: boolean - whether the context changed
| Param | Type | Description |
|---|---|---|
| moveFxn | function | the function to move the context |
| ctx | Object |
offsetInToken(context) ⇒ number
In the given context, get the character offset of pos from the start of the token.
Kind: global function
| Param | Type |
|---|---|
| context | Object |
getModeAt(cm, pos, precise) ⇒ Object
Returns the mode object and mode name string at a given position
Kind: global function
| Param | Type | Description |
|---|---|---|
| cm | CodeMirror | CodeMirror instance |
| pos | Object | Position to query for mode |
| precise | boolean | If given, results in more current results. Suppresses caching. |