diff --git a/package.json b/package.json index c90c0401..63a30cde 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@ckeditor/ckeditor5-widget": "^0.2.0" }, "devDependencies": { + "@ckeditor/ckeditor5-basic-styles": "^0.9.0", "@ckeditor/ckeditor5-clipboard": "^0.7.0", "@ckeditor/ckeditor5-dev-lint": "^3.1.0", "@ckeditor/ckeditor5-editor-classic": "^0.8.0", diff --git a/src/imagecaption/imagecaptionengine.js b/src/imagecaption/imagecaptionengine.js index 3e3c546f..a3c0a480 100644 --- a/src/imagecaption/imagecaptionengine.js +++ b/src/imagecaption/imagecaptionengine.js @@ -16,10 +16,9 @@ import viewWriter from '@ckeditor/ckeditor5-engine/src/view/writer'; import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position'; import ViewPosition from '@ckeditor/ckeditor5-engine/src/view/position'; import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter'; -import { isImage, isImageWidget } from '../image/utils'; +import { isImage } from '../image/utils'; import { captionElementCreator, - isCaption, getCaptionFromImage, matchImageCaption } from './utils'; @@ -100,8 +99,6 @@ export default class ImageCaptionEngine extends Plugin { */ _updateCaptionVisibility() { const mapper = this.editor.editing.mapper; - const viewSelection = this.editor.editing.view.selection; - const selectedElement = viewSelection.getSelectedElement(); let viewCaption; // Hide last selected caption if have no child elements. @@ -109,16 +106,21 @@ export default class ImageCaptionEngine extends Plugin { this._lastSelectedCaption.addClass( 'ck-hidden' ); } - // If whole image widget is selected. - if ( selectedElement && isImageWidget( selectedElement ) ) { - const modelImage = mapper.toModelElement( selectedElement ); - const modelCaption = getCaptionFromImage( modelImage ); + // If whole image is selected. + const modelSelection = this.editor.document.selection; + const selectedElement = modelSelection.getSelectedElement(); + + if ( selectedElement && selectedElement.is( 'image' ) ) { + const modelCaption = getCaptionFromImage( selectedElement ); viewCaption = mapper.toViewElement( modelCaption ); } // If selection is placed inside caption. - if ( isCaption( viewSelection.editableElement ) ) { - viewCaption = viewSelection.editableElement; + const position = modelSelection.getFirstPosition(); + const modelCaption = getParentCaption( position.parent ); + + if ( modelCaption ) { + viewCaption = mapper.toViewElement( modelCaption ); } if ( viewCaption ) { diff --git a/tests/manual/tickets/127/1.html b/tests/manual/tickets/127/1.html new file mode 100644 index 00000000..b66076e1 --- /dev/null +++ b/tests/manual/tickets/127/1.html @@ -0,0 +1,6 @@ +
foo bar Link bold
+ +