Fix underflow problem when cursor pos is 0
Add test cases for Up/Down keys