import { Keys } from '@ephox/agar'; import { context, describe, it } from '@ephox/bedrock-client'; import { TinyAssertions, TinyContentActions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import Editor from 'tinymce/core/api/Editor'; describe('browser.tinymce.core.keyboard.HomeEndKeysTest', () => { const hook = TinyHooks.bddSetupLight({ add_unload_trigger: false, base_url: '/project/tinymce/js/tinymce', indent: false }, [], true); context('Home key', () => { it('Home key should move caret before cef within the same block', () => { const editor = hook.editor(); editor.setContent('

123

CEF456

'); TinySelections.setCursor(editor, [ 1, 1 ], 3); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 1, 0 ], 0); }); it('Home key should move caret from after cef to before cef', () => { const editor = hook.editor(); editor.setContent('

CEF

'); TinySelections.setCursor(editor, [ 0 ], 1); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 0, 0 ], 0); }); it('Home key should move caret to before cef from the start of range', () => { const editor = hook.editor(); editor.setContent('

123

CEF456
789

'); TinySelections.setSelection(editor, [ 1, 1 ], 3, [ 1, 1 ], 3); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 1, 0 ], 0); }); it('Home key should not move caret before cef within the same block if there is a BR in between', () => { const editor = hook.editor(); editor.setContent('

123

CEF
456

'); TinySelections.setCursor(editor, [ 1, 2 ], 3); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 1, 2 ], 3); }); it('Home key should not move caret if there is no cef', () => { const editor = hook.editor(); editor.setContent('

123

'); TinySelections.setCursor(editor, [ 0, 0 ], 1); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 0, 0 ], 1); }); it('TINY-8201: Home key should not move caret outside of closest editing host', () => { const editor = hook.editor(); editor.setContent('

x

123

'); TinySelections.setCursor(editor, [ 1, 0, 0, 0 ], 1); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 1, 0, 0, 0 ], 1); }); it('TINY-8201: Home key should move caret to closest cef inside the closest editing host', () => { const editor = hook.editor(); editor.setContent('

x

CEF123

'); TinySelections.setCursor(editor, [ 1, 0, 0, 1 ], 1); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 1, 0, 0, 0 ], 0); }); context('Inline boundaries', () => { it('TINY-4612: move caret out and at the beginning of the element', () => { const editor = hook.editor(); editor.setContent('

linktest

'); TinySelections.setCursor(editor, [ 0, 0, 0 ], 2); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 0, 0 ], 0); }); it('TINY-4612: move caret at the beginning of the line (parent) if the first element is an inline element', () => { const editor = hook.editor(); editor.setContent('

link1test

'); TinySelections.setCursor(editor, [ 0, 1 ], 3); TinyContentActions.keystroke(editor, Keys.home()); TinyAssertions.assertCursor(editor, [ 0, 0 ], 0); }); }); }); context('End key', () => { it('End key should move caret after cef within the same block', () => { const editor = hook.editor(); editor.setContent('

123CEF

456

'); TinySelections.setCursor(editor, [ 0, 0 ], 0); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 0, 2 ], 1); }); it('End key should move caret from before cef to after cef', () => { const editor = hook.editor(); editor.setContent('

CEF

'); TinySelections.setCursor(editor, [ 0 ], 0); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 0, 1 ], 1); }); it('End key should move caret to after cef from the end of range', () => { const editor = hook.editor(); editor.setContent('

123
456CEF

'); TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 0, 2 ], 0); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 0, 4 ], 1); }); it('End key should not move caret after cef within the same block if there is a BR in between', () => { const editor = hook.editor(); editor.setContent('

123
CEF

456

'); TinySelections.setCursor(editor, [ 0, 0 ], 0); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 0, 0 ], 0); }); it('End key should not move caret if there is no cef', () => { const editor = hook.editor(); editor.setContent('

123

'); TinySelections.setCursor(editor, [ 0, 0 ], 1); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 0, 0 ], 1); }); it('TINY-8201: End key should not move caret outside of closest editing host', () => { const editor = hook.editor(); editor.setContent('

x

123

'); TinySelections.setCursor(editor, [ 1, 0, 0, 0 ], 1); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 1, 0, 0, 0 ], 1); }); it('TINY-8201: End key should move caret to closest cef inside the closest editing host', () => { const editor = hook.editor(); editor.setContent('

x

123CEF

'); TinySelections.setCursor(editor, [ 1, 0, 0, 0 ], 1); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 1, 0, 0, 2 ], 1); }); context('Inline boundaries', () => { it('TINY-4612: move caret out and at end of the element', () => { const editor = hook.editor(); editor.setContent('

testlink

'); TinySelections.setCursor(editor, [ 0, 1, 0 ], 0); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 0, 2 ], 1); }); it('TINY-4612: move caret at the end of the line (parent) if the last element is an inline element', () => { const editor = hook.editor(); editor.setContent('

testlink 2

'); TinySelections.setCursor(editor, [ 0, 0 ], 0); TinyContentActions.keystroke(editor, Keys.end()); TinyAssertions.assertCursor(editor, [ 0, 2 ], 1); }); }); }); });