import { Keys } from '@ephox/agar'; import { beforeEach, context, describe, it } from '@ephox/bedrock-client'; import { TinyAssertions, TinyContentActions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import Editor from 'tinymce/core/api/Editor'; describe('browser.tinymce.core.keyboard.SpaceKeyTest', () => { const hook = TinyHooks.bddSetupLight({ indent: false, base_url: '/project/tinymce/js/tinymce' }, []); beforeEach(() => { hook.editor().focus(); }); context('Space key around inline boundary elements', () => { it('Press space at beginning of inline boundary inserting nbsp', () => { const inputEvents: Array<{ inputType: string; data: string | null }> = []; const editor = hook.editor(); const collect = ({ inputType, data }: InputEvent) => { inputEvents.push({ inputType, data }); }; editor.on('input', collect); editor.setContent('

a b c

'); TinySelections.setCursor(editor, [ 0, 1, 0 ], 0); editor.nodeChanged(); TinyContentActions.keystroke(editor, Keys.space()); editor.off('input', collect); TinyAssertions.assertSelection(editor, [ 0, 1, 0 ], 1, [ 0, 1, 0 ], 1); assert.deepEqual([{ inputType: 'insertText', data: ' ' }], inputEvents, 'Events not fired as expected'); TinyAssertions.assertContent(editor, '

a  b c

'); }); it('Press space at end of inline boundary inserting nbsp', () => { const editor = hook.editor(); editor.setContent('

a b c

'); TinySelections.setCursor(editor, [ 0, 1, 0 ], 1); editor.nodeChanged(); TinyContentActions.keystroke(editor, Keys.space()); TinyAssertions.assertSelection(editor, [ 0, 1, 0 ], 2, [ 0, 1, 0 ], 2); TinyAssertions.assertContent(editor, '

a c

'); }); it('Press space at beginning of inline boundary inserting space', () => { const editor = hook.editor(); editor.setContent('

abc

'); TinySelections.setCursor(editor, [ 0, 1, 0 ], 0); editor.nodeChanged(); TinyContentActions.keystroke(editor, Keys.space()); TinyAssertions.assertSelection(editor, [ 0, 1, 0 ], 1, [ 0, 1, 0 ], 1); TinyAssertions.assertContent(editor, '

a bc

'); }); it('Press space at end of inline boundary inserting space', () => { const editor = hook.editor(); editor.setContent('

abc

'); TinySelections.setCursor(editor, [ 0, 1, 0 ], 1); editor.nodeChanged(); TinyContentActions.keystroke(editor, Keys.space()); TinyAssertions.assertSelection(editor, [ 0, 1, 0 ], 2, [ 0, 1, 0 ], 2); TinyAssertions.assertContent(editor, '

ab c

'); }); it('Press space at start of inline boundary with leading space inserting nbsp', () => { const editor = hook.editor(); editor.setContent('

a bc

'); TinySelections.setCursor(editor, [ 0, 1, 0 ], 0); editor.nodeChanged(); TinyContentActions.keystroke(editor, Keys.space()); TinyAssertions.assertSelection(editor, [ 0, 1, 0 ], 1, [ 0, 1, 0 ], 1); TinyAssertions.assertContent(editor, '

a  bc

'); }); it('Press space at end of inline boundary with trailing space inserting nbsp', () => { const editor = hook.editor(); editor.setContent('

ab c

'); TinySelections.setCursor(editor, [ 0, 1, 0 ], 2); editor.nodeChanged(); TinyContentActions.keystroke(editor, Keys.space()); TinyAssertions.assertSelection(editor, [ 0, 1, 0 ], 3, [ 0, 1, 0 ], 3); TinyAssertions.assertContent(editor, '

ab  c

'); }); }); });