Check boundary of cursor position