fixed bug on setSelection with a margin