void (@NotNull LinkedList<UndoableGroup> stack, @NotNull UndoableGroup group, int limit) { if (!group.isUndoable() && stack.isEmpty()) return; stack.add(group); while (stack.size() > limit) { clearStacksFrom(stack.getFirst()); } }