﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
13284	Cannot drag'n'drop widget if a text caret is placed just after widget instance	Pawel Pecio	Szymon Cofalik	"User is unable to drag and drop widget instance using its handler if a text caret is placed just after the widget (example: some text [Inlinewidget]| rest of the text).
On mouse down click there is an exception:
{{{
Uncaught IndexSizeError: Failed to execute 'extend' on 'Selection': 1 is larger than the given node's length.
}}}

Bug was reported only for Chrome browsers (all the latest versions).

Steps to reproduce:
1. On CKEditor widgets demo page go to the mathematical formulas demo.
2. Select a formula widget instance by click
3. Type right arrow key once to unfocus the widget instance, text caret should appear just after the widget instance
4. Try to drag the widget using drag handler, the exception should be thrown

I've found that the bug is connected with ""bookmarks"". The ""source"" of the problem is {{{finalizeNativeDrop}}} function when {{{saveSnapshot}}} event is triggered. One of its handler(s) uses bookmarks and call {{{moveNativeSelectionToBookmark}}} function. Stack trace reports call from {{{instanceReady}}} handler in selection component. There are following code: 
{{{
			editor.on( 'beforeUndoImage', beforeData );
			editor.on( 'afterUndoImage', afterData );
			editor.on( 'beforeGetData', beforeData, null, null, 0 );
			editor.on( 'getData', afterData );

(... and in afterData function ...)
			if ( fillingChar ) {
				fillingChar.setText( fillingCharBefore );

				if ( selectionBookmark ) {
					moveNativeSelectionToBookmark( editor.document.$, selectionBookmark );
					selectionBookmark = null;
				}
			}

}}}

By unknown reason (for me), selectionBookmark is an empty textnode with offset property set to 1. This causes an exception in 
{{{
sel.extend( bm[ 1 ].node, bm[ 1 ].offset ); 
}}} 
which cannot move selection to position 1 when the node length is 0. "	Bug	closed	Normal	CKEditor 4.5.4	Core : Selection	4.4.6	fixed	Blink Webkit	
