Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

Code Block
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.

    // 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;