-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add insertObject() function. #11425
Add insertObject() function. #11425
Conversation
…lists, changing image type, widget type around and deleting content.
} else { | ||
insertionContext = model.document.selection.anchor.parent; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imageType is calculated below, so the order should be different.
… insertContent smarter.
…ertparagraph command.
…utesWithProperty to schema, other minor improvements.
// This applies only when we don't have the selectable specified (i.e., we insert multiple block images at once). | ||
findOptimalPosition: !selectable && imageType != 'imageInline' | ||
} | ||
); | ||
|
||
// Inserting an image might've failed due to schema regulations. | ||
if ( imageElement.parent ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this condition be also included in setSelection inside insertObject?
const firstSelectedBlock = selection.getSelectedBlocks().next().value; | ||
const attributesToCopy = model.schema.getAttributesWithProperty( firstSelectedBlock, 'copyOnReplace', true ); | ||
|
||
writer.setAttributes( attributesToCopy, object ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be set on the block element (so for an inline image that requires auto paragraphing those attributes should be set on the paragraph that wrapped an inline image.
Also attributes should be verified if are applicable to a specified object (according to the schema).
model.deleteContent( insertionSelection, { doNotAutoparagraph: true } ); | ||
} | ||
|
||
writer.insert( paragraph, insertionSelection.anchor ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would wrap the object with this paragraph and use the paragraph with the inline object as an object to be inserted. On the new object (the paragraph) we need to set those attributes that should persist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember that final selection should be set relative to the object, not the paragraph (set selection on an object, not on a paragraph).
insertionSelection = writer.createPositionAt( paragraph, 0 ); | ||
} | ||
|
||
const affectedRange = model.insertContent( object, insertionSelection, offset, options ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const affectedRange = model.insertContent( object, insertionSelection, offset, options ); | |
const affectedRange = model.insertContent( object, insertionSelection, offset ); |
|
||
// If the element is missing, but a paragraph could be inserted next to the element, let's add it. | ||
if ( !canSetSelection && model.schema.checkChild( contextElement.parent, 'paragraph' ) ) { | ||
nextElement = writer.createElement( 'paragraph' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably should also apply those attributes that should persist.
@@ -281,6 +282,8 @@ export function toWidgetEditable( editable, writer ) { | |||
} | |||
|
|||
/** | |||
* TODO this is only wrapping the engine util for the cases where selection is tested for possibility to insert some object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO.
} ); | ||
} | ||
|
||
// TODO findOptimalInsertionRange should be exported or exposed in some reasonable place to be used in the widget util of the same name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO.
…tor/ckeditor5 into ck/11198-make-sure-list-isnt-split
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍. Waiting for feedback from the QA team.
Suggested merge commit message (convention)
Feature (engine): Added a new function
insertObject()
to theModel
for inserting elements defined as objects by schema into a model.Feature (engine): Added a new function
setAllowedAttributes()
to theSchema
that validates attributes if they are allowed on given element before setting them.Feature (engine): Added a new function
getAttributesWithProperty()
to theSchema
that retrieves attributes from a node which have given property.Feature (media-embed): Added optional
findOptimalPosition
parameter toinsertMedia()
function that allows for insertingmedia
element without breaking content.Feature (paragraph): Added optional
options.attributes
parameter toInsertParagraph
command that allows setting attributes on created paragraph.Fix (list): Fixed fixing indent of inserted content into document list in
documentlistediting
fixer.Internal (engine):
findOptimalPosition()
is now also included in engine for internal use.Internal (table, page-break, horizontal-line, media-embed, html-embed, image):
table
,pageBreak
,horizontalLine
,media
,imageBlock
,imageInline
elements are now inserted withinsertObject()
function instead ofinsertContent()
. Closes #11198.Additional information
Changes to deletecontent, widgettypearound that handles copyOnReplace attributes' property are not described above. Changes to moving findOptimalPosition to engine not described yet.