Interface DocumentPasteEditProvider<T>

Provider invoked when the user copies or pastes in a TextDocument.

interface DocumentPasteEditProvider<T> {
    prepareDocumentPaste?(document, ranges, dataTransfer, token): void | Thenable<void>;
    provideDocumentPasteEdits?(document, ranges, dataTransfer, context, token): ProviderResult<T[]>;
    resolveDocumentPasteEdit?(pasteEdit, token): ProviderResult<T>;
}

Type Parameters

Methods

  • Optional method invoked after the user copies from a text editor.

    This allows the provider to attach metadata about the copied text to the DataTransfer. This data transfer is then passed back to providers in provideDocumentPasteEdits.

    Note that currently any changes to the DataTransfer are isolated to the current editor window. This means that any added metadata cannot be seen by other editor windows or by other applications.

    Parameters

    • document: TextDocument

      Text document where the copy took place.

    • ranges: readonly Range[]

      Ranges being copied in document.

    • dataTransfer: DataTransfer

      The data transfer associated with the copy. You can store additional values on this for later use in provideDocumentPasteEdits. This object is only valid for the duration of this method.

    • token: CancellationToken

      A cancellation token.

    Returns void | Thenable<void>

    Optional thenable that resolves when all changes to the dataTransfer are complete.

  • Invoked before the user pastes into a text editor.

    Returned edits can replace the standard pasting behavior.

    Parameters

    Returns ProviderResult<T[]>

    Set of potential edits that can apply the paste. Only a single returned DocumentPasteEdit is applied at a time. If multiple edits are returned from all providers, then the first is automatically applied and a widget is shown that lets the user switch to the other edits.