Trilium Frontend API
    Preparing search index...

    Class Transaction

    Changes to the editor state are grouped into transactions. Typically, a user action creates a single transaction, which may contain any number of document changes, may change the selection, or have other effects. Create a transaction by calling EditorState.update, or immediately dispatch one by calling EditorView.dispatch.

    Index

    Properties

    changes: ChangeSet

    The document changes made by this transaction.

    effects: readonly StateEffect<any>[]

    The effects added to the transaction.

    scrollIntoView: boolean

    Whether the selection should be scrolled into view after this transaction is dispatched.

    selection: EditorSelection

    The selection set by this transaction, or undefined if it doesn't explicitly set a selection.

    startState: EditorState

    The state from which the transaction starts.

    addToHistory: AnnotationType<boolean>

    Annotation indicating whether a transaction should be added to the undo history or not.

    remote: AnnotationType<boolean>

    Annotation indicating (when present and true) that a transaction represents a change made by some other actor, not the user. This is used, for example, to tag other people's changes in collaborative editing.

    time: AnnotationType<number>

    Annotation used to store transaction timestamps. Automatically added to every transaction, holding Date.now().

    userEvent: AnnotationType<string>

    Annotation used to associate a transaction with a user interface event. Holds a string identifying the event, using a dot-separated format to support attaching more specific information. The events used by the core libraries are:

    • "input" when content is entered
      • "input.type" for typed input
        • "input.type.compose" for composition
      • "input.paste" for pasted input
      • "input.drop" when adding content with drag-and-drop
      • "input.complete" when autocompleting
    • "delete" when the user deletes content
      • "delete.selection" when deleting the selection
      • "delete.forward" when deleting forward from the selection
      • "delete.backward" when deleting backward from the selection
      • "delete.cut" when cutting to the clipboard
    • "move" when content is moved
      • "move.drop" when content is moved within the editor through drag-and-drop
    • "select" when explicitly changing the selection
      • "select.pointer" when selecting with a mouse or other pointing device
    • "undo" and "redo" for history actions

    Use isUserEvent to check whether the annotation matches a given event.

    Accessors

    • get docChanged(): boolean

      Indicates whether the transaction changed the document.

      Returns boolean

    • get newDoc(): Text

      The new document produced by the transaction. Contrary to .state.doc, accessing this won't force the entire new state to be computed right away, so it is recommended that transaction filters use this getter when they need to look at the new document.

      Returns Text

    • get newSelection(): EditorSelection

      The new selection produced by the transaction. If this.selection is undefined, this will map the start state's current selection through the changes made by the transaction.

      Returns EditorSelection

    • get reconfigured(): boolean

      Indicates whether this transaction reconfigures the state (through a configuration compartment or with a top-level configuration effect.

      Returns boolean

    • get state(): EditorState

      The new state created by the transaction. Computed on demand (but retained for subsequent access), so it is recommended not to access it in transaction filters when possible.

      Returns EditorState

    Methods

    • Get the value of the given annotation type, if any.

      Type Parameters

      • T

      Parameters

      Returns T

    • Returns true if the transaction has a user event annotation that is equal to or more specific than event. For example, if the transaction has "select.pointer" as user event, "select" and "select.pointer" will match it.

      Parameters

      • event: string

      Returns boolean