Skip to main content

Summary

Read the editor’s current selection as a portable SelectionInfo with a text-anchored TextTarget. Primitive for building custom comments UIs, floating toolbars, and other selection-driven components without reaching into ProseMirror internals.
  • Operation ID: selection.current
  • API member path: editor.doc.selection.current(...)
  • Mutates document: no
  • Idempotency: idempotent
  • Supports tracked mode: no
  • Supports dry run: no
  • Deterministic target resolution: yes

Expected result

Returns a SelectionInfo with empty, target (TextTarget or null), activeMarks, and optionally text when includeText: true.

Input fields

FieldTypeRequiredDescription
includeTextbooleanno

Example request

{
  "includeText": true
}

Output fields

FieldTypeRequiredDescription
activeMarksstring[]yes
emptybooleanyes
targetTextTarget \nullyesOne of: TextTarget, null
textstringno

Example response

{
  "activeMarks": [
    "example"
  ],
  "empty": true,
  "target": {
    "kind": "text",
    "segments": [
      {
        "blockId": "block-abc123",
        "range": {
          "end": 10,
          "start": 0
        }
      }
    ]
  },
  "text": "Hello, world."
}

Pre-apply throws

  • INVALID_INPUT
  • INVALID_CONTEXT

Non-applied failure codes

  • None

Raw schemas

{
  "additionalProperties": false,
  "properties": {
    "includeText": {
      "type": "boolean"
    }
  },
  "type": "object"
}
{
  "additionalProperties": false,
  "properties": {
    "activeMarks": {
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "empty": {
      "type": "boolean"
    },
    "target": {
      "oneOf": [
        {
          "$ref": "#/$defs/TextTarget"
        },
        {
          "type": "null"
        }
      ]
    },
    "text": {
      "type": "string"
    }
  },
  "required": [
    "empty",
    "target",
    "activeMarks"
  ],
  "type": "object"
}