@Override
  public void beforeDocumentChange(@NotNull DocumentEvent e) {
    if (!myEditor.getDocument().isInBulkUpdate() && e.isWholeTextReplaced()) {
      for (CaretImpl caret : myCarets) {
        caret.updateCachedStateIfNeeded(); // logical position will be needed to restore caret position via diff
      }
    }
    myIsInUpdate = true;
    myVisualPositionUpdateScheduled = false;
  }
@Override
  public void beforeDocumentChange(@NotNull DocumentEvent e)