Daniel,
I know its annoying, but It has happened to me, I guess you need to cancel query mode before you leave the canvas, perhaps you can write something to cancel query mode if you leave that particular tab. I am not sure that woould work, I am learning all this myself.