cursor.getSelectedRange will only ever return a range just after construction. A neater fix might be to inject a range on construction rather than casting this every time?