/** * EnterKey.js * * Released under LGPL License. * Copyright (c) 1999-2017 Ephox Corp. All rights reserved * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ import InsertNewLine from '../newline/InsertNewLine'; import VK from '../api/util/VK'; import { Editor } from 'tinymce/core/api/Editor'; import { EditorEvent } from 'tinymce/core/api/dom/EventUtils'; const endTypingLevel = function (undoManager) { if (undoManager.typing) { undoManager.typing = false; undoManager.add(); } }; const handleEnterKeyEvent = function (editor: Editor, event: EditorEvent) { if (event.isDefaultPrevented()) { return; } event.preventDefault(); endTypingLevel(editor.undoManager); editor.undoManager.transact(function () { if (editor.selection.isCollapsed() === false) { editor.execCommand('Delete'); } InsertNewLine.insert(editor, event); }); }; const setup = function (editor: Editor) { editor.on('keydown', function (event: EditorEvent) { if (event.keyCode === VK.ENTER) { handleEnterKeyEvent(editor, event); } }); }; export default { setup };