Skip to main content

code

import {...} from "@revideo/2d/lib/code";

Classes

Interfaces

Type Aliases

CodeDiffer


CodePoint

type CodePoint = numbernumber

CodeRange

type CodeRange = CodePointCodePoint

CodeSelection

type CodeSelection = CodeRange[]

CodeSignal

Type Parameters


CodeTag


CodeTokenizer

type CodeTokenizer = input: string => string[]

PossibleCodeFragment

type PossibleCodeFragment = CodeFragmentCodeMetricsRawCodeFragmentstring

PossibleCodeScope

type PossibleCodeScope = CodeScopeCodeTag[]string

PossibleCodeSelection

type PossibleCodeSelection = CodeRangeCodeRange[]

Variables

DefaultHighlightStyle

const DefaultHighlightStyle: HighlightStyle = ...

Functions

CODE

public CODEstrings: TemplateStringsArray...tags: CodeTag[]: CodeTag[]

Parameters


codeSignal

public codeSignal(): PropertyDecorator

consolidateCodeRanges

public consolidateCodeRangesranges: CodeRange[]: CodeRange[]

Parameters


defaultDiffer

Default diffing function utilizing patienceDiff.

Parameters


defaultTokenize

public defaultTokenizeinput: string: string[]

Default tokenizer function used by ownerless code signals.

Parameters

  • input: string

    The code to tokenize.


extractRange

public extractRangerange: CodeRangefragments: CodeTag[]: CodeTag[]number

Transform the fragments to isolate the given range into its own fragment.

This function will try to preserve the original fragments, resolving them only if they overlap with the range.

Parameters


findAllCodeRanges

public findAllCodeRangescode: stringpattern: stringRegExplimit: number = Infinity: CodeRange[]

Find all code ranges that match the given pattern.

Parameters

  • code: string

    The code to search in.

  • pattern: stringRegExp

    Either a string or a regular expression to search for.

  • limit: number = Infinity

    An optional limit on the number of ranges to find.


insert

public insertcode: string: RawCodeFragment

Create a code fragment that represents an insertion of code.

Can be used in conjunction with edit.

Parameters

  • code: string

    The code to insert.


inverseCodeRange

public inverseCodeRangeranges: CodeRange[]: CodeRange[]

Parameters


isCodeRange

public isCodeRangevalue: unknown: value is CodeRange

Parameters


isCodeScope

public isCodeScopevalue: any: value is CodeScope

Parameters


isPointInCodeRange

public isPointInCodeRangepoint: CodePointrange: CodeRange: boolean

Parameters


isPointInCodeSelection

public isPointInCodeSelectionpoint: CodePointselection: CodeSelection: boolean

Parameters


lines

public linesfrom: numberto?: number: CodeRange

Create a code range that spans the given lines.

Parameters

  • from: number

    The line from which the range starts.

  • to?: number

    The line at which the range ends. If omitted, the range will cover only one line.


metricsToFragment

public metricsToFragmentvalue: CodeMetrics: CodeFragment

Parameters


parseCodeFragment

Parameters


parseCodeScope

public parseCodeScopevalue: PossibleCodeScope: CodeScope

Parameters


parseCodeSelection

public parseCodeSelectionvalue: PossibleCodeSelection: CodeSelection

Parameters


patienceDiff

public patienceDiffaLines: string[]bLines: string[]: lineCountDeleted: numberlineCountInserted: numberlines: aIndex: numberbIndex: numberline: string[]

Performs a patience diff on two arrays of strings, returning an object containing the lines that were deleted, inserted, and potentially moved lines. The plus parameter can result in a significant performance hit due to additional Longest Common Substring searches.

Parameters

  • aLines: string[]

    The original array of strings

  • bLines: string[]

    The new array of strings


pointToPoint

public pointToPointstartLine: numberstartColumn: numberendLine: numberendColumn: number: CodeRange

Create a custom selection range.

Parameters

  • startLine: number

    The line at which the selection starts.

  • startColumn: number

    The column at which the selection starts.

  • endLine: number

    The line at which the selection ends.

  • endColumn: number

    The column at which the selection ends.


remove

public removecode: string: RawCodeFragment

Create a code fragment that represents a removal of code.

Can be used in conjunction with edit.

Parameters

  • code: string

    The code to remove.


replace

public replacebefore: stringafter: string: RawCodeFragment

Create a code fragment that represents a change from one piece of code to another.

Can be used in conjunction with edit.

Parameters

  • before: string

    The code to change from.

  • after: string

    The code to change to.


resolveCodeTag

public resolveCodeTagwrapped: CodeTagafter: booleanisAfter: IsAfterPredicate = after: string

Parameters


resolveScope

public resolveScopescope: CodeScopeisAfter: IsAfterPredicate: string

Parameters


word

public wordline: numberfrom: numberlength?: number: CodeRange

Create a code range that highlights the given word.

Parameters

  • line: number

    The line at which the word appears.

  • from: number

    The column at which the word starts.

  • length?: number

    The length of the word. If omitted, the range will cover the rest of the line.