@@ -222,52 +222,39 @@ void textArea_Drop(object sender, DragEventArgs e)
222222 DragDropEffects effect = GetEffect ( e ) ;
223223 e . Effects = effect ;
224224 if ( effect != DragDropEffects . None ) {
225- string text = e . Data . GetData ( DataFormats . UnicodeText , true ) as string ;
226- if ( text != null ) {
227- int start = textArea . Caret . Offset ;
228- if ( mode == SelectionMode . Drag && textArea . Selection . Contains ( start ) ) {
229- Debug . WriteLine ( "Drop: did not drop: drop target is inside selection" ) ;
230- e . Effects = DragDropEffects . None ;
231- } else {
232- Debug . WriteLine ( "Drop: insert at " + start ) ;
233-
234- bool rectangular = e . Data . GetDataPresent ( RectangleSelection . RectangularSelectionDataType ) ;
235-
236- string newLine = TextUtilities . GetNewLineFromDocument ( textArea . Document , textArea . Caret . Line ) ;
237- text = TextUtilities . NormalizeNewLines ( text , newLine ) ;
238-
239- string pasteFormat ;
240- // fill the suggested DataFormat used for the paste action:
241- if ( rectangular )
242- pasteFormat = RectangleSelection . RectangularSelectionDataType ;
243- else
244- pasteFormat = DataFormats . UnicodeText ;
245-
246- var pastingEventArgs = new DataObjectPastingEventArgs ( e . Data , true , pasteFormat ) ;
247- textArea . RaiseEvent ( pastingEventArgs ) ;
248- if ( pastingEventArgs . CommandCancelled )
249- return ;
250-
251- // DataObject.PastingEvent handlers might have changed the format to apply.
252- rectangular = pastingEventArgs . FormatToApply == RectangleSelection . RectangularSelectionDataType ;
253-
254- // Mark the undo group with the currentDragDescriptor, if the drag
255- // is originating from the same control. This allows combining
256- // the undo groups when text is moved.
257- textArea . Document . UndoStack . StartUndoGroup ( this . currentDragDescriptor ) ;
258- try {
259- if ( rectangular && RectangleSelection . PerformRectangularPaste ( textArea , textArea . Caret . Position , text , true ) ) {
260-
261- } else {
262- textArea . Document . Insert ( start , text ) ;
263- textArea . Selection = Selection . Create ( textArea , start , start + text . Length ) ;
264- }
265- } finally {
266- textArea . Document . UndoStack . EndUndoGroup ( ) ;
225+ int start = textArea . Caret . Offset ;
226+ if ( mode == SelectionMode . Drag && textArea . Selection . Contains ( start ) ) {
227+ Debug . WriteLine ( "Drop: did not drop: drop target is inside selection" ) ;
228+ e . Effects = DragDropEffects . None ;
229+ } else {
230+ Debug . WriteLine ( "Drop: insert at " + start ) ;
231+
232+ var pastingEventArgs = new DataObjectPastingEventArgs ( e . Data , true , DataFormats . UnicodeText ) ;
233+ textArea . RaiseEvent ( pastingEventArgs ) ;
234+ if ( pastingEventArgs . CommandCancelled )
235+ return ;
236+
237+ string text = EditingCommandHandler . GetTextToPaste ( pastingEventArgs , textArea ) ;
238+ if ( text == null )
239+ return ;
240+ bool rectangular = pastingEventArgs . DataObject . GetDataPresent ( RectangleSelection . RectangularSelectionDataType ) ;
241+
242+ // Mark the undo group with the currentDragDescriptor, if the drag
243+ // is originating from the same control. This allows combining
244+ // the undo groups when text is moved.
245+ textArea . Document . UndoStack . StartUndoGroup ( this . currentDragDescriptor ) ;
246+ try {
247+ if ( rectangular && RectangleSelection . PerformRectangularPaste ( textArea , textArea . Caret . Position , text , true ) ) {
248+
249+ } else {
250+ textArea . Document . Insert ( start , text ) ;
251+ textArea . Selection = Selection . Create ( textArea , start , start + text . Length ) ;
267252 }
253+ } finally {
254+ textArea . Document . UndoStack . EndUndoGroup ( ) ;
268255 }
269- e . Handled = true ;
270256 }
257+ e . Handled = true ;
271258 }
272259 } catch ( Exception ex ) {
273260 OnDragException ( ex ) ;
0 commit comments