This thread is related and would be a good starting point: Expanding the selection to the active mark? - #2 by marijn