> For the complete documentation index, see [llms.txt](https://docs.wproofreader.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wproofreader.com/v6.11.1/integrations/how-tos/custom-inserttext-event.md).

# Custom insertText event

Here is an example of using **customInsertText** event for managing the insert text mechanism flexibly.

```javascript
var container = document.querySelector('.container'); // Get the main editable container.

container.addEventListener('customInsertText', function(event) {
    // Call 'preventDefault' to prevent WProofreader from replacing text.
    // After that the text replacent mechanism can be handled manually.
    event.preventDefault();

    // Obtain text for replacing from 'detail' field of the 'event' object.
    var text = event.detail.text;

    // Get the selection for the text insertion.
    // The text that is to be replaced are already in the browser Selection.
    var selection = window.getSelection();

    // Keep the error highlighting if needed.
    event.keepHighlight = true;
});

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.wproofreader.com/v6.11.1/integrations/how-tos/custom-inserttext-event.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
