When the adverbial particle か is combined with と, the う-Verb 思（おも）う, and either of the hypothetical markers たら or と, it forms a compound that is used to illustrate uncertainty about whether (A) has been finalized or not. In most cases, this translates as ‘(A), then again (B)’, ‘just when I thought (A), (B)’, or ‘no sooner than (A), (B)’. Literally, the meaning is close to ‘before (A) could even be confirmed as having happened, (B)’.
will regularly appear after verbs in either their dictionary or past-tense forms.
Just when I thought of something to say, he started bad-mouthing me in front of everyone.
Just when I thought the baby had stopped crying, he started to cry loudly again.
Just when I thought my daughter was going to start doing her homework, she opened the computer and started watching YouTube.
Just when I thought my kid fell down, she got up and started running.
Alternatively, this structure may also be seen following nouns, especially when the meaning is focused on the speaker's feelings about (A).
No sooner than thinking that Tanaka-san is a cold person, I found out that he was just shy.
Just when I remembered that today’s game is the last one, I got sad.
Either なの (or の when used with verbs) may appear between the target phrase and かと思（おも）ったら
when the (B) phrase includes the speaker’s feelings.
Caution - Occasionally, か may be omitted from this phrase, leaving only と思（おも）うと
. Although the meaning is exactly the same, omission of the か will make the expression sound softer.
Just when I thought a new employee had joined us, he had quit by the next day.
Just when I thought that my son and his friend were fighting, I heard him giggling while playing video games with his friend.