Disable the Movement of Text Annotations but Allow Editing the Text

There might be cases when you want to disable movements (dragging and resizing) of text annotations but allow a user to edit the text. You can do this by using the following code:

PSPDFKit.load(options).then((instance) => {
  const stopPropagation = (event) => event.stopImmediatePropagation();

  instance.addEventListener("annotationSelection.change", (ann) => {
    if (ann && ann instanceof PSPDFKit.Annotations.TextAnnotation) {
      instance.contentDocument.addEventListener(
        "pointermove",
        stopPropagation,
        { capture: true }
      );
      instance.contentDocument.addEventListener(
        "mousemove",
        stopPropagation,
        {
          capture: true
        }
      );
      instance.contentDocument.addEventListener(
        "touchmove",
        stopPropagation,
        {
          capture: true
        }
      );

      instance.contentDocument.addEventListener(
        "keydown",
        stopPropagation,
        {
          capture: true
        }
      );
    } else {
      instance.contentDocument.removeEventListener(
        "pointermove",
        stopPropagation,
        { capture: true }
      );

      instance.contentDocument.removeEventListener(
        "mousemove",
        stopPropagation,
        {
          capture: true
        }
      );
      instance.contentDocument.removeEventListener(
        "touchmove",
        stopPropagation,
        {
          capture: true
        }
      );

      instance.contentDocument.removeEventListener(
        "keydown",
        stopPropagation,
        {
          capture: true
        }
      );
    }
  });
});

All the other annotations, except the text annotation, will work as expected.

This has been tested with PSPDFKit for Web 2020.6.0