This is a migrated thread and some comments may be shown as answers.

[Solved] Problems pasting code from Visual Studio

3 Answers 167 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Mark Davis
Top achievements
Rank 1
Mark Davis asked on 14 Jun 2008, 12:52 AM
When a selected section of C# code is copied from the Visual Studio IDE, then pasted into the RADEditor, each line is wrapped in a <P> element causing excessive line spacing and all the indentation is lost. StripFormattingOptions is set to "None".

Any idea how I can improve this experience?

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 16 Jun 2008, 05:07 PM
Hi Mark,

The observed behavior is due to Visual Studio, which converts the C# code to HTML markup and exports it to the Clipboard and after that to the editor. Very often, the produced by Visual Studio content has wrong DOM child relation which causes additional problems.

You can easily verify that the observed behavior is not related to RadEditor by setting the StripFormattingOptions to None. In this mode the editor does not strip any tags and formatting and keeps the content as it is supplied by the clipboard.

Could you please open a support ticket and send us a concreted C# file for test? We will copy / paste its content in the editor and if possible we will provide a solution.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark Davis
Top achievements
Rank 1
answered on 17 Jun 2008, 12:36 AM
 I've tried setting StripFormattingOptions to None, but the same behavior occurs. In fact, if I paste some VS C# code into the editor that is used for this Forums post, the same behavior will show - all the indentation is lost and there is a line's worth of space between each line. E.g.

if (RadEditor.Enabled)

{

// Remove CodeSnippet tags when editing

sb.Append(htmlBody);

}


In the above pasting, the comment should appear on the same line as the opening brace, the 4th line should be indented and there should not be so much white space between each line.
The text looks ok when pasted in Notepad or Outlook - am I missing something here?

0
Tervel
Telerik team
answered on 19 Jun 2008, 10:52 AM
Hello Mark,

We already answered in a separate email, but I am providing our answer here for convenience of other users:

=========================================================================

These are two separate problems – the first one is about excessive spacing, the second one is about missing indentation.


The first problem (excessive spacing) can be handled easily. However, let me explain quickly where both problems come from. The editor (or more precisely – the browser) is a clipboard consumer. It identifies to Visual Studio that it is able to use HTML, but of course has no control over the way VS creates this HTML. So, Visual Studio exports the selection using P tags – this is purely a VS matter, and the editor can do nothing much about it – it correctly pastes the Ps. However, by default when no styling is applied P tags have extra margin.

This can easily be handled by modifying the editor’s content area css file and setting it with the ContentAreaCssFile property.


What you should do is add a global P style in the file that removes margins, e.g.

P
{
   margin:0;
}

Please have a look at this demo for extra information:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Editor/Examples/SettingContentAreaDefaults/DefaultCS.aspx


Regarding the second problem – indentation removed when pasting. Unfortunately it is again related to the way VS exports the HTML. It simply strips away the indentation – looking at the raw HTML code it can be seen that the TAB elements, which are used to tabulate code in VS are just completely gone – as if they were never exported at all. Since the editor does not receive any information on where tabs should be, there does not seem to be any way to restore the original tabs.


=========================================================================

Some additional information: Yes, it is possible to access the clipboard content and obtain it as simple text - however this is only possible in IE6, as well as IE7 with user security approval. It is not possible with any other browser, so developing a crossbrowser solution using just this approach is impossible. We will look further whether a combination of options can do the trick in a "cross-browser fashion".


Best regards,
Tervel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Editor
Asked by
Mark Davis
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Mark Davis
Top achievements
Rank 1
Tervel
Telerik team
Share this question
or