void gatherGlobalCommand(@NotNull UndoRedo undoRedo) {
    UndoableGroup group = undoRedo.myUndoableGroup;
    UndoableGroup.UndoableGroupOriginalContext context = group.getGroupOriginalContext();
    if (context == null) return;

    Collection<DocumentReference> refs = undoRedo.getDocRefs();
    if (refs.size() > 1) return;
    DocumentReference docRef = refs.iterator().next();

    ClientState clientState = getClientState(undoRedo.myEditor);
    if (clientState == null) return;
    UndoRedoStacksHolder stackHolder = getStackHolder(clientState, true);
    UndoRedoList<UndoableGroup> stack = stackHolder.getStack(docRef);
    if (stack.getLast() != group) return;

    boolean shouldGatherGroup = stackHolder.replaceOnStacks(context.getCurrentStackGroup(), context.getOriginalGroup());
    if (!shouldGatherGroup) return;

    stack.removeLast();
    stack.add(context.getOriginalGroup());
  }
void gatherGlobalCommand(@NotNull UndoRedo undoRedo)