@b4n I took some ideas from your implementation and kept some bits from my implementation and this is the result. I believe it behaves quite reasonably now.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/958#issuecomment-195311482