と　particle after a full sentence


In my book I have this sentence:

> 生徒が学校へ行こうと思って野を歩いていると、一ぴきのきつねが遠くにいるのをみた。

I understand the sentence, "The student, who is walking in the field while he
wants to go to school, saw a fox far away".

But what's the purpose of "と" here?




と in this case implies that something **unexpected** is following. "The
student was walking in the field to go to school, when he saw a fox far away."
Or we can emphasize like that to see the nuance: "Just when the student
thought of going to school and was walking in the field, he saw a fox far
away."

