<!--
{
  "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/init(attributedSelectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "BrowserEngineKit"
    ],
    "preciseIdentifier" : "c:objc(cs)BETextDocumentContext(im)initWithAttributedSelectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:"
  },
  "title" : "init(attributedSelectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:)"
}
-->

# init(attributedSelectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:)

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

```
init(attributedSelectedText selectedText: NSAttributedString?, contextBefore: NSAttributedString?, contextAfter: NSAttributedString?, markedText: NSAttributedString?, selectedRangeInMarkedText: NSRange)
```

## Discussion

The `attributedSelectedText`, `contextBefore`, and `contextAfter` parameters represent the same ranges as their counterparts in [`init(selectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:)`](/documentation/BrowserEngineKit/BETextDocumentContext/init(selectedText:contextBefore:contextAfter:markedText:selectedRangeInMarkedText:)), and carry the same requirements, with the addition of text formatting and style attributes.

---

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)