Refactor keyboard navigation for heading commands to avoid breaking undo