better cursor position detection
References #185