Patch attached. Could you please test it, and confirm that it correctly fixes the issue? Cc'ing Martin, who authored most of the handle-select-window function. The recipe is upthread.