8
0
Pārlūkot izejas kodu

Do not customize getSelectedContent() when the selection is empty.

Aleksander Nowodzinski 6 gadi atpakaļ
vecāks
revīzija
d51aa72eda

+ 1 - 1
packages/ckeditor5-code-block/src/codeblockediting.js

@@ -128,7 +128,7 @@ export default class CodeBlockEditing extends Plugin {
 		this.listenTo( model, 'getSelectedContent', ( evt, [ selection ] ) => {
 			const anchor = selection.anchor;
 
-			if ( !anchor.parent.is( 'codeBlock' ) || !anchor.hasSameParentAs( selection.focus ) ) {
+			if ( selection.isCollapsed || !anchor.parent.is( 'codeBlock' ) || !anchor.hasSameParentAs( selection.focus ) ) {
 				return;
 			}
 

+ 6 - 0
packages/ckeditor5-code-block/tests/codeblockediting.js

@@ -735,6 +735,12 @@ describe( 'CodeBlockEditing', () => {
 		} );
 
 		describe( 'getSelectedContent', () => {
+			it( 'should not engage when there is nothing selected', () => {
+				setModelData( model, '<codeBlock language="css">fo[]o<softBreak></softBreak>bar</codeBlock>' );
+
+				expect( stringify( model.getSelectedContent( model.document.selection ) ) ).to.equal( '' );
+			} );
+
 			it( 'should wrap a partial multi-line selection into a code block (#1)', () => {
 				setModelData( model, '<codeBlock language="css">fo[o<softBreak></softBreak>b]ar</codeBlock>' );