private static Document extractDocumentFromCommand(@NotNull CommandEvent event) {
      Document affectedDocument = event.getDocument();
      if (affectedDocument != null) return affectedDocument;
      Object id = event.getCommandGroupId();

      if (id instanceof Document document) {
        affectedDocument = document;
      }
      else if (id instanceof DocCommandGroupId docId) {
        affectedDocument = docId.getDocument();
      }
      return affectedDocument;
    }
private static Document extractDocumentFromCommand(@NotNull CommandEvent event)