Refactored Jeff's code in EditorState.as