Browse Source

Fixed bug in HighlightedLine.ToHtml that could cause text in front of the selection to be copied to the clipboard.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5386 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
a48804720d
  1. 46
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Highlighting/HtmlClipboardTests.cs
  2. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj
  3. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs
  4. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Snippets/InsertionContext.cs
  5. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/RopeNode.cs

46
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Highlighting/HtmlClipboardTests.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows;
using ICSharpCode.AvalonEdit.Document;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Highlighting
{
[TestFixture]
public class HtmlClipboardTests
{
TextDocument document;
DocumentHighlighter highlighter;
public HtmlClipboardTests()
{
document = new TextDocument("using System.Text;\n\tstring text = SomeMethod();");
highlighter = new DocumentHighlighter(document, HighlightingManager.Instance.GetDefinition("C#").MainRuleSet);
}
[Test]
public void FullDocumentTest()
{
var segment = new TextSegment { StartOffset = 0, Length = document.TextLength };
string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, new HtmlOptions());
Assert.AreEqual("<span style=\"color: #008000; font-weight: bold; \">using</span>&nbsp;" +
"System<span style=\"color: #006400; \">.</span>Text;<br>" + Environment.NewLine +
"&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #ff0000; \">string</span>&nbsp;" +
"text =&nbsp;<span style=\"color: #191970; font-weight: bold; \">SomeMethod</span>();", html);
}
[Test]
public void PartOfHighlightedWordTest()
{
var segment = new TextSegment { StartOffset = 1, Length = 3 };
string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, new HtmlOptions());
Assert.AreEqual("<span style=\"color: #008000; font-weight: bold; \">sin</span>", html);
}
}
}

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj

@ -76,6 +76,7 @@ @@ -76,6 +76,7 @@
<Compile Include="Document\TextUtilitiesTests.cs" />
<Compile Include="Editing\ChangeDocumentTests.cs" />
<Compile Include="Editing\TextSegmentReadOnlySectionTests.cs" />
<Compile Include="Highlighting\HtmlClipboardTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Document\CollapsingTests.cs" />
<Compile Include="Document\HeightTests.cs" />
@ -97,6 +98,7 @@ @@ -97,6 +98,7 @@
<ItemGroup>
<Folder Include="Document" />
<Folder Include="Editing" />
<Folder Include="Highlighting" />
<Folder Include="Utils" />
<Folder Include="XmlParser" />
</ItemGroup>

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs

@ -128,7 +128,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -128,7 +128,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
if (newOffset > startOffset) {
HtmlClipboard.EscapeHtml(b, document.GetText(textOffset, newOffset - textOffset), options);
}
textOffset = newOffset;
textOffset = Math.Max(textOffset, newOffset);
if (e.IsEnd) {
b.Append("</span>");
} else {

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Snippets/InsertionContext.cs

@ -93,6 +93,8 @@ namespace ICSharpCode.AvalonEdit.Snippets @@ -93,6 +93,8 @@ namespace ICSharpCode.AvalonEdit.Snippets
/// <summary>
/// Inserts text at the insertion position and advances the insertion position.
/// This method will add the current indentation to every line in <paramref name="text"/> and will
/// replace newlines with the expected newline for the document.
/// </summary>
public void InsertText(string text)
{

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/RopeNode.cs

@ -63,7 +63,7 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -63,7 +63,7 @@ namespace ICSharpCode.AvalonEdit.Utils
// this is an additional invariant that forces the tree to combine small leafs to prevent excessive memory usage:
Debug.Assert(length > NodeSize);
// note that the this invariant ensures that all nodes except for the empty rope's single node have at least length 1
// note that this invariant ensures that all nodes except for the empty rope's single node have at least length 1
if (isShared)
Debug.Assert(left.isShared && right.isShared);

Loading…
Cancel
Save