Deselect the Current Text Selection

There’s currently no specific API for deselecting text programmatically. However, as a workaround, you can quickly change the current interaction mode and immediately set it back to the previous one. That will clear the text selection:

function deselectText() {
  const interactionMode = instance.viewState.interactionMode;
  instance.setViewState((v) =>
    v.set("interactionMode", PSPDFKit.InteractionMode.PAN)
  );
  instance.setViewState((v) =>
    v.set("interactionMode", interactionMode)
  );
}

PSPDFKit.InteractionMode.PAN is a good option since it doesn’t trigger a change on the user interface (UI). Unlike when using other interaction modes, such as the transition one, this won’t result in any flash of quickly disappearing content.

This has been tested with PSPDFKit for Web 2020.4.2.