-
Notifications
You must be signed in to change notification settings - Fork 40
T/ckeditor5/1243: Unify widget insertion #1545
Changes from 11 commits
7cd3f5e
97cb888
4c233e5
b91dc3b
e0ba244
f18462a
b00ca26
dcb0c54
6163265
abfff1f
259bd57
6e779db
63e4f18
aa31f0f
e95e695
3cb0b59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,7 +275,7 @@ export default class Model { | |
* | ||
* // insertContent() doesn't have to be used in a change() block. It can, though, | ||
* // so this code could be moved to the callback defined above. | ||
* editor.model.insertContent( docFrag, editor.model.document.selection ); | ||
* editor.model.insertContent( docFrag ); | ||
* | ||
* Using `insertContent()` with HTML string converted to a model document fragment (similar to the pasting mechanism): | ||
* | ||
|
@@ -296,15 +296,44 @@ export default class Model { | |
* // which has a loosened schema. | ||
* const modelFragment = editor.data.toModel( viewFragment ); | ||
* | ||
* editor.model.insertContent( modelFragment, editor.model.document.selection ); | ||
* editor.model.insertContent( modelFragment ); | ||
* | ||
* By default the method will use document selection but it can be also used with position, range or selection instances. | ||
* | ||
* // Insert text at current document selection position. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the current |
||
* editor.model.change( writer => { | ||
* editor.model.insertContent( writer.createText( 'x' ) ); | ||
* // equal to editor.model.insertContent( model, writer.createText( 'x' ), editor.model.document.selection ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a bit unnecessary and makes it more visually complex. Plus, there's a mistake (the |
||
* } ); | ||
* | ||
* // Insert text at some position - model's selection will not be modified. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at a given position document selection there are two kinds of model selection - static selection and document selection; the one you refer to is called the document selection. |
||
* editor.model.change( writer => { | ||
* editor.model.insertContent( writer.createText( 'x' ), new Position( doc.getRoot(), [ 2 ] ) ); | ||
* } ); | ||
* | ||
* If an instance of {module:engine/model/selection~Selection} is passed as `selectable` | ||
* it will be moved to the target position (where the document selection should be moved after the insertion). | ||
* | ||
* // Insert text replacing given selection instance. | ||
* const selection = new Selection( new Position( doc.getRoot(), [ 2 ] ), new Position( doc.getRoot(), [ 5 ] ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's maybe use a more human readable method, like – Also, I don't think that const selection = new Selection( paragraph, 'in' ); |
||
* | ||
* editor.model.change( writer => { | ||
* editor.model.insertContent( writer.createText( 'x' ), selection ); | ||
* | ||
* // insertContent() modifies the passed selection instance so it can be used to set the document selection. | ||
* // Note: This is not necessary when you passed document selection to insertContent(). | ||
* writer.setSelection( selection ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* } ); | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sample with range/position is missing. |
||
* @fires insertContent | ||
* @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert. | ||
* @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection | ||
* Selection into which the content should be inserted. | ||
* @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection| | ||
* module:engine/model/position~Position|module:engine/model/element~Element| | ||
* Iterable.<module:engine/model/range~Range>|module:engine/model/range~Range|null} [selectable] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't it supposed to default to the document selection? If yes, make sure to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that you made this change. So you also need to update these docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still missing the default value in the documentation:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bonus – I think that we should define a typedef called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah - I though about this also - I can make it here though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* Selection into which the content should be inserted. If not provided the current model document selection will be used. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can add a note that if you use a selection object, it will be modified and you will be able to get the insertion selection. |
||
*/ | ||
insertContent( content, selection ) { | ||
insertContent( this, content, selection ); | ||
insertContent( content, selectable ) { | ||
insertContent( this, content, selectable ); | ||
} | ||
|
||
/** | ||
|
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 method
the document selection
it can also be used with a position, range or selection instance