there is a default time after which the system logs you out for inactivity...detected by you clicking around. When making a long post, it sees you as "inactive" after the default. It is to protect your account
As Koala explained, checking "remember me" sets the default to staying logged in, even during inactivity, until you choose to use the log off feature.
Using "remember me" should solve your problem.