8
0
Просмотр исходного кода

Used first() util to get first selected block.

Oskar Wróbel 6 лет назад
Родитель
Сommit
8c959f39fb
1 измененных файлов с 3 добавлено и 2 удалено
  1. 3 2
      packages/ckeditor5-heading/src/title.js

+ 3 - 2
packages/ckeditor5-heading/src/title.js

@@ -17,6 +17,7 @@ import {
 	hidePlaceholder,
 	enablePlaceholder
 } from '@ckeditor/ckeditor5-engine/src/view/placeholder';
+import first from '@ckeditor/ckeditor5-utils/src/first';
 
 // A list of element names which should be treated by the Title plugin as title-like.
 // This means that element of a type from this list will be changed to a title element
@@ -379,7 +380,7 @@ export default class Title extends Plugin {
 				const selection = model.document.selection;
 				const selectedElements = Array.from( selection.getSelectedBlocks() );
 
-				if ( selectedElements.length === 1 && selectedElements[ 0 ].name === 'title-content' ) {
+				if ( selectedElements.length === 1 && selectedElements[ 0 ].is( 'title-content' ) ) {
 					const firstBodyElement = model.document.getRoot().getChild( 1 );
 					writer.setSelection( firstBodyElement, 0 );
 					cancel();
@@ -397,7 +398,7 @@ export default class Title extends Plugin {
 				}
 
 				const root = editor.model.document.getRoot();
-				const selectedElement = Array.from( selection.getSelectedBlocks() )[ 0 ];
+				const selectedElement = first( selection.getSelectedBlocks() );
 				const selectionPosition = selection.getFirstPosition();
 
 				const title = root.getChild( 0 );