Could you please turn this section into a small help function, which then is used both from here and setUnfilteredPosition? While doing so also add a small comment what actually is done here, I have an idea but would be nice for future times to not have the grasp the logic of the lines to see why it is done.
No, actually I have no idea, puzzled about the logic... even more in need of an explaining comment.