left/rightMargin are assigned to but never read. Did you mean to check that the cursor position was within bounds or can this be removed?