Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_getObjectElementNextToSelection( forward ) {
const modelDocument = this.editor.document;
const schema = modelDocument.schema;
const modelSelection = modelDocument.selection;
const dataController = this.editor.data;
// Clone current selection to use it as a probe. We must leave default selection as it is so it can return
// to its current state after undo.
const probe = ModelSelection.createFromSelection( modelSelection );
dataController.modifySelection( probe, { direction: forward ? 'forward' : 'backward' } );
const objectElement = forward ? probe.focus.nodeBefore : probe.focus.nodeAfter;
if ( objectElement instanceof ModelElement && schema.objects.has( objectElement.name ) ) {
return objectElement;
}
return null;
}
}