188.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  6. import Input from '../../src/input';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
  9. import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  10. describe( 'Bug ckeditor5-typing#188', () => {
  11. let editor;
  12. beforeEach( () => {
  13. return VirtualTestEditor.create( {
  14. plugins: [ Input, Paragraph, BoldEditing ]
  15. } ).then( newEditor => {
  16. editor = newEditor;
  17. } );
  18. } );
  19. afterEach( () => {
  20. return editor.destroy();
  21. } );
  22. it( 'should not lost attributes while typing - IME', () => {
  23. const view = editor.editing.view;
  24. const p = view.document.getRoot().getChild( 0 );
  25. editor.execute( 'bold' );
  26. simulateMutation( view, p, 0, 0, '', 'u' );
  27. expect( getData( view, { withoutSelection: true } ) ).to.equal( '<p><strong>u</strong></p>' );
  28. simulateMutation( view, p, 0, 1, 'u', 'ü' );
  29. expect( getData( view, { withoutSelection: true } ) ).to.equal( '<p><strong>ü</strong></p>' );
  30. } );
  31. } );
  32. function simulateMutation( view, node, startOffset, endOffset, oldText, newText ) {
  33. const viewSelection = view.createSelection();
  34. viewSelection.setTo( view.createRange(
  35. view.createPositionAt( node, startOffset ),
  36. view.createPositionAt( node, endOffset )
  37. ) );
  38. view.document.fire( 'mutations',
  39. [
  40. {
  41. type: 'text',
  42. oldText,
  43. newText,
  44. node
  45. }
  46. ],
  47. viewSelection
  48. );
  49. }