<!--
{
  "availability" : [
    "iOS: 17.4.0 -",
    "iPadOS: 17.4.0 -",
    "tvOS: 17.4.0 -",
    "visionOS: 1.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "BrowserEngineKit",
  "identifier" : "/documentation/BrowserEngineKit/BETextDocumentContext",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "BrowserEngineKit"
    ],
    "preciseIdentifier" : "c:objc(cs)BETextDocumentContext"
  },
  "title" : "BETextDocumentContext"
}
-->

# BETextDocumentContext

Information about the text surrounding a selection in a document.

```
class BETextDocumentContext
```

## Overview

The [`BETextInput`](/documentation/BrowserEngineKit/BETextInput) protocol’s [`requestDocumentContext(_:completionHandler:)`](/documentation/BrowserEngineKit/BETextInput/requestDocumentContext(_:completionHandler:)) and [`requestTextContextForAutocorrection(completionHandler:)`](/documentation/BrowserEngineKit/BETextInput/requestTextContextForAutocorrection(completionHandler:)) methods provide an instance of this class to their completion handlers.

## Topics

### Creating a text document context

[`init(attributedSelectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:)`](/documentation/BrowserEngineKit/BETextDocumentContext/init(attributedSelectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:))

Initializes a document with attributed strings that represent the selection and its surrounding context.

[`init(selectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:)`](/documentation/BrowserEngineKit/BETextDocumentContext/init(selectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:))

Initializes a document with plain text strings that represent the selection and its surrounding context.

### Accessing autocorrected ranges

[`autocorrectedRanges`](/documentation/BrowserEngineKit/BETextDocumentContext/autocorrectedRanges)

An array of ranges that identify text the system autocorrects, relative to the context string.

### Adding text rectangles

[`addTextRect(_:forCharacterRange:)`](/documentation/BrowserEngineKit/BETextDocumentContext/addTextRect(_:forCharacterRange:))

Adds a rectangle that corresponds to the specified character range in the document.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)