If $\mathfrak{g}=\bigoplus\mathfrak{g}_i$ is a semisimple Lie algebra, why does $\mathfrak{h}=\bigoplus\left(\mathfrak{h}\cap\mathfrak{g}_i\right)$?

There is this property about Cartan subalgebras that is not clear to me.

Suppose $\mathfrak{g}$ is a semisimple Lie algebra. Then I know we can decompose it uniquely as $\mathfrak{g}=\bigoplus\mathfrak{g}_i$, where the $\mathfrak{g}_i$ are simple ideals. If $\mathfrak{h}$ is a Cartan subalgebra (maximal toral subalgebra), then $\mathfrak{h}=\bigoplus(\mathfrak{h}\cap\mathfrak{g}_i)$. The $\supseteq$ direction is clear.

Why does the other follow? I thought of something like this, take $x\in\mathfrak{h}$, and write $x=\sum x_i$ for $x_i\in\mathfrak{g}_i$. I want to show $x_i\in\mathfrak{h}$ for each $i$. I did this by induction on the number of nonzero summands. If there is only one summand so $x=x_i$, the claim is clear. If there's more than one summand, I'm not sure how to reduce it to imply the induction, if this is the right idea.

Suppose that $$K$$ is the base field. Fix $$h\in\mathfrak{h}$$. Let $$h_i\in\mathfrak{g}_i$$ be such that $$h=\sum\limits_i\,h_i$$ (the $$h_i$$'s are unique). We claim that $$h_i\in\mathfrak{h}$$ for all $$i$$. Let $$t\in\mathfrak{h}$$. Write $$t=\sum\limits_{i}\,t_i$$ with $$t_i\in\mathfrak{g}_i$$. For $$i\neq j$$, $$\left[t_i,h_j\right]\in\mathfrak{g}_i\cap\mathfrak{g}_j=\{0\}\,,$$ so $$\left[t_i,h_j\right]=0$$. Ergo, $$\sum\limits_{i}\,\left[t_i,h_i\right]=[t,h]=0\,.$$ Since $$\left[t_i,h_i\right]\in\mathfrak{g}_i$$, we conclude that $$\left[t_i,h_i\right]=0$$ for every $$i$$. Thus, $$\left[h_i,t\right]=\left[h_i,t_i\right]=0$$ for every $$t\in\mathfrak{h}$$.
Because $$h$$ is a semisimple element of $$\mathfrak{g}$$, $$h_i$$ is also a semisimple element of $$\mathfrak{g}$$ (to be proven below). If $$h_i\notin\mathfrak{h}$$, then $$\mathfrak{h}\oplus K\mathfrak{h}_i$$ is a strictly larger toral subalgebra containing $$h$$, which is a contradiction. Thus, $$h_i\in \mathfrak{h}$$ for all $$i$$, so $$h_i\in\mathfrak{h}\cap\mathfrak{g}_i$$. Therefore, $$h=\sum\limits_i\,h_i\in\bigoplus\limits_i\,\left(\mathfrak{h}\cap\mathfrak{g}_i\right)\,,$$ whence $$\mathfrak{h}\subseteq \bigoplus\limits_i\,\left(\mathfrak{h}\cap\mathfrak{g}_i\right)$$. Since it is trivial that $$\mathfrak{h}\supseteq \bigoplus\limits_i\,\left(\mathfrak{h}\cap\mathfrak{g}_i\right)$$, $$\mathfrak{h}= \bigoplus\limits_i\,\left(\mathfrak{h}\cap\mathfrak{g}_i\right)$$, as required.
To show that $$h_i$$ is a semisimple element of $$\mathfrak{g}$$, we let $$V^\lambda$$ be the eigenspace of $$\text{ad}_\mathfrak{g}(h)$$ with the eigenvalue $$\lambda\in K$$. For each $$i$$, take $$V_i^\lambda$$ to be the intersection $$V^\lambda\cap\mathfrak{g}_i$$. Trivially, $$\bigoplus\limits_{\lambda\in K}\,V^\lambda_i=\mathfrak{g}_i$$. However, as $$V^\lambda_i$$ is the eigenspace with eigenvalue $$\lambda$$ of $$\text{ad}_{\mathfrak{g}_i}\left(h_i\right)$$, we see that $$h_i$$ is a semisimple element of $$\mathfrak{g}_i$$. Now, define $$\tilde{V}^\lambda_i:=V^\lambda_i$$ if $$\lambda\neq 0$$, and $$\tilde{V}^0_i:=V^0_i\oplus\left(\bigoplus\limits_{j\neq i}\,\mathfrak{g}_j\right)$$. Then, $$\tilde{V}^\lambda_i$$ is the eigenspace of $$\text{ad}_\mathfrak{g}\left(h_i\right)$$ with eigenvalue $$\lambda$$. Since $$\bigoplus\limits_{\lambda \in K}\,\tilde{V}^\lambda_i=\mathfrak{g}$$, we conclude that $$h_i$$ is a semisimple element of $$\mathfrak{g}$$.
If we have $$\mathfrak{g}=\prod_{i=1}^n\mathfrak{g}_i$$ a direct product of such Lie algebras and $$\mathfrak{h}$$ is nilpotent and $$\mathfrak{h}_i$$ is its projection to $$\mathfrak{g}_i$$, then $$\prod_{i=1}^n\mathfrak{h}_i$$ is nilpotent and contains $$\mathfrak{h}$$. In particular, if $$\mathfrak{h}$$ is maximal nilpotent, then we deduce that $$\mathfrak{h}=\prod_{i=1}^n\mathfrak{h}_i$$, that is, $$\mathfrak{h}$$ is stable under taking projection to the direct summands. This applies in particular when $$\mathfrak{h}$$ is Cartan.