import { Keys } from '@ephox/agar'; import { describe, it, context } from '@ephox/bedrock-client'; import { PlatformDetection } from '@ephox/sand'; import { TinyAssertions, TinyContentActions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import Editor from 'tinymce/core/api/Editor'; import * as CaretContainer from 'tinymce/core/caret/CaretContainer'; describe('browser.tinymce.core.keyboard.ArrowKeysEdgeCefTest', () => { const hook = TinyHooks.bddSetupLight({ base_url: '/project/tinymce/js/tinymce', }, [], true); const os = PlatformDetection.detect().os; const assertRangeInCaretContainerBlock = (editor: Editor) => assert.isTrue(CaretContainer.isRangeInCaretContainerBlock(editor.selection.getRng())); const selectToBeginning = (editor: Editor) => { if (os.isMacOS()) { TinyContentActions.keystroke(editor, Keys.up(), { metaKey: true, shiftKey: true }); } else { TinyContentActions.keystroke(editor, Keys.home(), { ctrlKey: true, shiftKey: true }); } }; const selectToEnd = (editor: Editor) => { if (os.isMacOS()) { TinyContentActions.keystroke(editor, Keys.down(), { metaKey: true, shiftKey: true }); } else { TinyContentActions.keystroke(editor, Keys.end(), { ctrlKey: true, shiftKey: true }); } }; context('Cmd+Shift+Up/Down should expand selection to the edge of the content', () => { it('TINY-7795: Cmd+Shift+Up when a cef block is at the start', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

'); // actual content:

CEF

abc

TinySelections.setCursor(editor, [ 2, 0 ], 2); selectToBeginning(editor); TinyAssertions.assertSelection(editor, [ ], 0, [ 1, 0 ], 2); }); it('TINY-7795: Cmd+Shift+Down when a cef block is at the end', () => { const editor = hook.editor(); editor.setContent('

abc

CEF

'); TinySelections.setCursor(editor, [ 0, 0 ], 1); selectToEnd(editor); TinyAssertions.assertSelection(editor, [ 0, 0 ], 1, [ ], 2); }); it('TINY-7795: Cmd+Shift+Up/Down when a cef block is at the start and at the end', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

CEF

'); TinyAssertions.assertCursor(editor, [ 0 ], 0); selectToEnd(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertSelection(editor, [ 0 ], 0, [ ], 4); TinySelections.setCursor(editor, [ ], 4); selectToBeginning(editor); // actual content:

CEF

abc

CEF


TinyAssertions.assertSelection(editor, [ ], 0, [ 3 ], 0); }); it('TINY-7795: Cmd+Shift+Up when a cef block is at the start and content is wrapped in div', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

'); // actual content:

CEF

abc

TinySelections.setCursor(editor, [ 0, 2, 0 ], 2); selectToBeginning(editor); TinyAssertions.assertSelection(editor, [ 0 ], 0, [ 0, 1, 0 ], 2); }); it('TINY-7795: Cmd+Shift+Down when a cef block is at the end and content is wrapped in div', () => { const editor = hook.editor(); editor.setContent('

abc

CEF

'); TinySelections.setCursor(editor, [ 0, 0, 0 ], 1); selectToEnd(editor); TinyAssertions.assertSelection(editor, [ 0, 0, 0 ], 1, [ 0 ], 2); }); it('TINY-7795: Cmd+Shift+Up/Down when a cef block is at the start and at the end and content is wrapped in div', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

CEF

'); TinyAssertions.assertCursor(editor, [ 0, 0 ], 0); selectToEnd(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertSelection(editor, [ 0, 0 ], 0, [ 0 ], 4); TinySelections.setCursor(editor, [ 0 ], 4); selectToBeginning(editor); // actual content:

CEF

abc

CEF


TinyAssertions.assertSelection(editor, [ 0 ], 0, [ 0, 3 ], 0); }); }); context('Left/Right arrow key should collapse selection', () => { it('TINY-7795: cef block at the start', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

'); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

TinySelections.setCursor(editor, [ 2, 0 ], 2); selectToBeginning(editor); // actual content:

CEF

abc

TinyAssertions.assertSelection(editor, [ ], 0, [ 1, 0 ], 2); TinyContentActions.keystroke(editor, Keys.right()); // actual content:

CEF

abc

TinyAssertions.assertCursor(editor, [ 1, 0 ], 2); selectToBeginning(editor); // actual content:

CEF

abc

TinyAssertions.assertSelection(editor, [ ], 0, [ 1, 0 ], 2); TinyContentActions.keystroke(editor, Keys.left()); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

TinyAssertions.assertCursor(editor, [ 0 ], 0); }); it('TINY-7795: a cef block is at the end', () => { const editor = hook.editor(); editor.setContent('

abc

CEF

'); TinySelections.setCursor(editor, [ 0, 0 ], 1); selectToEnd(editor); TinyAssertions.assertSelection(editor, [ 0, 0 ], 1, [ ], 2); TinyContentActions.keystroke(editor, Keys.left()); TinyAssertions.assertCursor(editor, [ 0, 0 ], 1); selectToEnd(editor); TinyAssertions.assertSelection(editor, [ 0, 0 ], 1, [ ], 2); TinyContentActions.keystroke(editor, Keys.right()); assertRangeInCaretContainerBlock(editor); // actual content:

abc

CEF


TinyAssertions.assertCursor(editor, [ 2 ], 0); }); it('TINY-7795: a cef block is at the start and at the end ', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

CEF

'); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertCursor(editor, [ 0 ], 0); selectToEnd(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertSelection(editor, [ 0 ], 0, [ ], 4); TinyContentActions.keystroke(editor, Keys.right()); assertRangeInCaretContainerBlock(editor); // actual content:

CEF

abc

CEF


TinyAssertions.assertCursor(editor, [ 3 ], 0); selectToBeginning(editor); // actual content:

CEF

abc

CEF


TinyAssertions.assertSelection(editor, [ ], 0, [ 3 ], 0); TinyContentActions.keystroke(editor, Keys.left()); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertCursor(editor, [ 0 ], 0); }); it('TINY-7795: a cef block is at the start and content is wrapped in div', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

'); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

TinySelections.setCursor(editor, [ 0, 2, 0 ], 2); selectToBeginning(editor); // actual content:

CEF

abc

TinyAssertions.assertSelection(editor, [ 0 ], 0, [ 0, 1, 0 ], 2); TinyContentActions.keystroke(editor, Keys.right()); // actual content:

CEF

abc

TinyAssertions.assertCursor(editor, [ 0, 1, 0 ], 2); selectToBeginning(editor); // actual content:

CEF

abc

TinyAssertions.assertSelection(editor, [ 0 ], 0, [ 0, 1, 0 ], 2); TinyContentActions.keystroke(editor, Keys.left()); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

TinyAssertions.assertCursor(editor, [ 0, 0 ], 0); }); it('TINY-7795: a cef block is at the end and content is wrapped in div ', () => { const editor = hook.editor(); editor.setContent('

abc

CEF

'); TinySelections.setCursor(editor, [ 0, 0, 0 ], 1); selectToEnd(editor); TinyAssertions.assertSelection(editor, [ 0, 0, 0 ], 1, [ 0 ], 2); TinyContentActions.keystroke(editor, Keys.left()); TinyAssertions.assertCursor(editor, [ 0, 0, 0 ], 1); selectToEnd(editor); TinyAssertions.assertSelection(editor, [ 0, 0, 0 ], 1, [ 0 ], 2); TinyContentActions.keystroke(editor, Keys.right()); assertRangeInCaretContainerBlock(editor); // actual content:

abc

CEF


TinyAssertions.assertCursor(editor, [ 0, 2 ], 0); }); it('TINY-7795: a cef block is at the start and at the end and content is wrapped in div ', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

CEF

'); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertCursor(editor, [ 0, 0 ], 0); selectToEnd(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertSelection(editor, [ 0, 0 ], 0, [ 0 ], 4); TinyContentActions.keystroke(editor, Keys.right()); assertRangeInCaretContainerBlock(editor); // actual content:

CEF

abc

CEF


TinyAssertions.assertCursor(editor, [ 0, 3 ], 0); selectToBeginning(editor); // actual content:

CEF

abc

CEF


TinyAssertions.assertSelection(editor, [ 0 ], 0, [ 0, 3 ], 0); TinyContentActions.keystroke(editor, Keys.left()); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertCursor(editor, [ 0, 0 ], 0); }); }); context('Up/Down arrow key should collapse the selection and move the caret above/below', () => { it('TINY-7795: a cef block is at the start', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

def

'); // actual content:


CEF

abc

def

TinySelections.setCursor(editor, [ 2, 0 ], 2); selectToBeginning(editor); // actual content:

CEF

abc

def

TinyAssertions.assertSelection(editor, [ ], 0, [ 1, 0 ], 2); TinyContentActions.keystroke(editor, Keys.down()); // actual content:

CEF

abc

def

TinyAssertions.assertCursor(editor, [ 2, 0 ], 2); selectToBeginning(editor); // actual content:

CEF

abc

def

TinyAssertions.assertSelection(editor, [ ], 0, [ 2, 0 ], 2); TinyContentActions.keystroke(editor, Keys.up()); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

def

TinyAssertions.assertCursor(editor, [ 0 ], 0); }); it('TINY-7795: a cef block is at the end', () => { const editor = hook.editor(); editor.setContent('

abc

def

CEF

'); TinySelections.setCursor(editor, [ 1, 0 ], 2); selectToEnd(editor); TinyAssertions.assertSelection(editor, [ 1, 0 ], 2, [ ], 3); TinyContentActions.keystroke(editor, Keys.up()); TinyAssertions.assertCursor(editor, [ 0, 0 ], 2); selectToEnd(editor); TinyAssertions.assertSelection(editor, [ 0, 0 ], 2, [ ], 3); TinyContentActions.keystroke(editor, Keys.down()); assertRangeInCaretContainerBlock(editor); // actual content:

abc

def

CEF


TinyAssertions.assertCursor(editor, [ 3 ], 0); }); it('TINY-7795: a cef block is at the start and the end', () => { const editor = hook.editor(); editor.setContent('

CEF

abc

CEF

'); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertCursor(editor, [ 0 ], 0); selectToEnd(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertSelection(editor, [ 0 ], 0, [ ], 4); TinyContentActions.keystroke(editor, Keys.down()); assertRangeInCaretContainerBlock(editor); // actual content:

CEF

abc

CEF


TinyAssertions.assertCursor(editor, [ 3 ], 0); selectToBeginning(editor); // actual content:

CEF

abc

CEF


TinyAssertions.assertSelection(editor, [ ], 0, [ 3 ], 0); TinyContentActions.keystroke(editor, Keys.up()); assertRangeInCaretContainerBlock(editor); // actual content:


CEF

abc

CEF

TinyAssertions.assertCursor(editor, [ 0 ], 0); }); }); });