@Override
  public void documentChanged(@NotNull DocumentEvent e) {
    if (UndoManager.getInstance(myProject).isUndoOrRedoInProgress()) {
      // allow undo/redo up until 'creation stamp' back in time
      // and check it after action is completed
      if (e.getDocument() == myOrigDocument) {
        ApplicationManager.getApplication().invokeLater(() -> {
          if (myOrigCreationStamp > myOrigDocument.getModificationStamp()) {
            closeEditor();
          }
        }, myProject.getDisposed());
      }
    }
    else if (e.getDocument() == myNewDocument) {
      commitToOriginal(e);
      if (!isValid()) {
        ApplicationManager.getApplication().invokeLater(() -> closeEditor(), myProject.getDisposed());
      }
    }
    else if (e.getDocument() == myOrigDocument) {
      if (myCommittingToOriginal) return;
      InjectedFileChangesHandler injectedFileChangesHandler =
        Objects.requireNonNull(myEditChangesHandler, "seems that 'myEditChangesHandler' was not initialized");
      if (!injectedFileChangesHandler.handlesRange(TextRange.from(e.getOffset(), e.getOldLength()))) return;
      ApplicationManager.getApplication().invokeLater(() -> {
        Component owner = FocusManager.getCurrentManager().getFocusOwner();
        closeEditor();
        if (owner != null) owner.requestFocus();
      }, myProject.getDisposed());
    }
  }
@Override
  public void documentChanged(@NotNull DocumentEvent e)