Handle ESC and ENTER keyboard events during editing.

Handle ESC and ENTER keyboard events during editing with expected behaviors.
Could be a switch statement - leave as is for older browser support?