How to use the @ckeditor/ckeditor5-widget/src/utils.findOptimalInsertionPosition function in @ckeditor/ckeditor5-widget

To help you get started, we’ve selected a few @ckeditor/ckeditor5-widget examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ckeditor / ckeditor5-image / src / image / utils.js View on Github external
export function insertImage( writer, model, attributes = {} ) {
	const imageElement = writer.createElement( 'image', attributes );

	const insertAtSelection = findOptimalInsertionPosition( model.document.selection, model );

	model.insertContent( imageElement, insertAtSelection );

	// Inserting an image might've failed due to schema regulations.
	if ( imageElement.parent ) {
		writer.setSelection( imageElement, 'on' );
	}
}
github ckeditor / ckeditor5-image / src / image / utils.js View on Github external
function getInsertImageParent( selection, model ) {
	const insertAt = findOptimalInsertionPosition( selection, model );

	const parent = insertAt.parent;

	if ( parent.isEmpty && !parent.is( '$root' ) ) {
		return parent.parent;
	}

	return parent;
}
github ckeditor / ckeditor5-media-embed / src / mediaembedcommand.js View on Github external
execute( url ) {
		const model = this.editor.model;
		const selection = model.document.selection;
		const selectedMedia = getSelectedMediaModelWidget( selection );

		if ( selectedMedia ) {
			model.change( writer => {
				writer.setAttribute( 'url', url, selectedMedia );
			} );
		} else {
			const insertPosition = findOptimalInsertionPosition( selection, model );

			insertMedia( model, url, insertPosition );
		}
	}
}
github ckeditor / ckeditor5-table / src / commands / inserttablecommand.js View on Github external
execute( options = {} ) {
		const model = this.editor.model;
		const selection = model.document.selection;
		const tableUtils = this.editor.plugins.get( 'TableUtils' );

		const rows = parseInt( options.rows ) || 2;
		const columns = parseInt( options.columns ) || 2;

		const insertPosition = findOptimalInsertionPosition( selection, model );

		model.change( writer => {
			const table = tableUtils.createTable( writer, rows, columns );

			model.insertContent( table, insertPosition );

			writer.setSelection( writer.createPositionAt( table.getNodeByPath( [ 0, 0, 0 ] ), 0 ) );
		} );
	}
}