My mare used to do this also, and I did a couple of things which I'm not sure which "one" worked. Number one, I took my lunge whip in and cracked it a couple of times when she did this to get her attention and corner her (I did not hit her with it). When she stopped, I gave her a reward. I would not feed her when she was "walking." Number two, I started adding B1 to her feed every day. I've heard it helps calm them, and it seems to be working.
Of course, these may not work for you, especially if you're graining her. I only give her grass hay and the B1 now, although I'm looking for a good mineral/vitamin supplement with the B1 in it, that goes well with a grass hay only diet.
Good luck.
Judy