Browse Source

Fixed SD2-646: Highlighting bug for multiline comments

Fixed SD2-820: SplashScreen.SetCommandLineArgs not defensive

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1429 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
e9ff406a9e
  1. 1
      src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj
  2. 28
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs
  3. 118
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SpanStack.cs
  4. 4
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineSegment.cs
  5. 1
      src/Main/StartUp/Project/Dialogs/SplashScreen.cs

1
src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj

@ -198,6 +198,7 @@
<EmbeddedResource Include="Resources\Boo.xshd" /> <EmbeddedResource Include="Resources\Boo.xshd" />
<Compile Include="Src\Gui\DrawableLine.cs" /> <Compile Include="Src\Gui\DrawableLine.cs" />
<Compile Include="Src\Gui\ToolTipRequestEventArgs.cs" /> <Compile Include="Src\Gui\ToolTipRequestEventArgs.cs" />
<Compile Include="Src\Document\HighlightingStrategy\SpanStack.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project> </Project>

28
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs

@ -251,7 +251,7 @@ namespace ICSharpCode.TextEditor.Document
LineSegment currentLine; LineSegment currentLine;
// Span stack state variable // Span stack state variable
Stack<Span> currentSpanStack; SpanStack currentSpanStack;
public void MarkTokens(IDocument document) public void MarkTokens(IDocument document)
{ {
@ -267,14 +267,14 @@ namespace ICSharpCode.TextEditor.Document
break; // then the last line is not in the collection :) break; // then the last line is not in the collection :)
} }
currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? new Stack<Span>(previousLine.HighlightSpanStack.ToArray()) : null); currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? previousLine.HighlightSpanStack.Clone() : null);
if (currentSpanStack != null) { if (currentSpanStack != null) {
while (currentSpanStack.Count > 0 && ((Span)currentSpanStack.Peek()).StopEOL) while (!currentSpanStack.IsEmpty && ((Span)currentSpanStack.Peek()).StopEOL)
{ {
currentSpanStack.Pop(); currentSpanStack.Pop();
} }
if (currentSpanStack.Count == 0) currentSpanStack = null; if (currentSpanStack.IsEmpty) currentSpanStack = null;
} }
currentLine = (LineSegment)document.LineSegmentCollection[lineNumber]; currentLine = (LineSegment)document.LineSegmentCollection[lineNumber];
@ -289,7 +289,7 @@ namespace ICSharpCode.TextEditor.Document
currentLine.Words.Clear(); currentLine.Words.Clear();
} }
currentLine.Words = words; currentLine.Words = words;
currentLine.HighlightSpanStack = (currentSpanStack==null || currentSpanStack.Count==0) ? null : currentSpanStack; currentLine.HighlightSpanStack = (currentSpanStack==null || currentSpanStack.IsEmpty) ? null : currentSpanStack;
++lineNumber; ++lineNumber;
} }
@ -303,12 +303,12 @@ namespace ICSharpCode.TextEditor.Document
bool processNextLine = false; bool processNextLine = false;
LineSegment previousLine = (lineNumber > 0 ? document.GetLineSegment(lineNumber - 1) : null); LineSegment previousLine = (lineNumber > 0 ? document.GetLineSegment(lineNumber - 1) : null);
currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? new Stack<Span>(previousLine.HighlightSpanStack.ToArray()) : null); currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? previousLine.HighlightSpanStack.Clone() : null);
if (currentSpanStack != null) { if (currentSpanStack != null) {
while (currentSpanStack.Count > 0 && currentSpanStack.Peek().StopEOL) { while (!currentSpanStack.IsEmpty && currentSpanStack.Peek().StopEOL) {
currentSpanStack.Pop(); currentSpanStack.Pop();
} }
if (currentSpanStack.Count == 0) { if (currentSpanStack.IsEmpty) {
currentSpanStack = null; currentSpanStack = null;
} }
} }
@ -321,7 +321,7 @@ namespace ICSharpCode.TextEditor.Document
List<TextWord> words = ParseLine(document); List<TextWord> words = ParseLine(document);
if (currentSpanStack != null && currentSpanStack.Count == 0) { if (currentSpanStack != null && currentSpanStack.IsEmpty) {
currentSpanStack = null; currentSpanStack = null;
} }
@ -348,8 +348,8 @@ namespace ICSharpCode.TextEditor.Document
} }
} }
} else { } else {
IEnumerator<Span> e1 = currentSpanStack.GetEnumerator(); SpanStack.Enumerator e1 = currentSpanStack.GetEnumerator();
IEnumerator<Span> e2 = currentLine.HighlightSpanStack.GetEnumerator(); SpanStack.Enumerator e2 = currentLine.HighlightSpanStack.GetEnumerator();
bool done = false; bool done = false;
while (!done) { while (!done) {
bool blockSpanIn1 = false; bool blockSpanIn1 = false;
@ -391,7 +391,7 @@ namespace ICSharpCode.TextEditor.Document
//// Alex: remove old words //// Alex: remove old words
if (currentLine.Words!=null) currentLine.Words.Clear(); if (currentLine.Words!=null) currentLine.Words.Clear();
currentLine.Words = words; currentLine.Words = words;
currentLine.HighlightSpanStack = (currentSpanStack != null && currentSpanStack.Count > 0) ? currentSpanStack : null; currentLine.HighlightSpanStack = (currentSpanStack != null && !currentSpanStack.IsEmpty) ? currentSpanStack : null;
return processNextLine; return processNextLine;
} }
@ -451,7 +451,7 @@ namespace ICSharpCode.TextEditor.Document
void UpdateSpanStateVariables() void UpdateSpanStateVariables()
{ {
inSpan = (currentSpanStack != null && currentSpanStack.Count > 0); inSpan = (currentSpanStack != null && !currentSpanStack.IsEmpty);
activeSpan = inSpan ? (Span)currentSpanStack.Peek() : null; activeSpan = inSpan ? (Span)currentSpanStack.Peek() : null;
activeRuleSet = GetRuleSet(activeSpan); activeRuleSet = GetRuleSet(activeSpan);
} }
@ -613,7 +613,7 @@ namespace ICSharpCode.TextEditor.Document
i += regex.Length - 1; i += regex.Length - 1;
if (currentSpanStack == null) { if (currentSpanStack == null) {
currentSpanStack = new Stack<Span>(); currentSpanStack = new SpanStack();
} }
currentSpanStack.Push(span); currentSpanStack.Push(span);
span.IgnoreCase = activeRuleSet.IgnoreCase; span.IgnoreCase = activeRuleSet.IgnoreCase;

118
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SpanStack.cs

@ -0,0 +1,118 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
namespace ICSharpCode.TextEditor.Document
{
/// <summary>
/// A stack of Span instances. Works like Stack&lt;Span&gt;, but can be cloned quickly
/// because it is implemented as linked list.
/// </summary>
public sealed class SpanStack : ICloneable, IEnumerable<Span>
{
internal sealed class StackNode
{
public readonly StackNode Previous;
public readonly Span Data;
public StackNode(StackNode previous, Span data)
{
this.Previous = previous;
this.Data = data;
}
}
StackNode top = null;
public Span Pop()
{
Span s = top.Data;
top = top.Previous;
return s;
}
public Span Peek()
{
return top.Data;
}
public void Push(Span s)
{
top = new StackNode(top, s);
}
public bool IsEmpty {
get {
return top == null;
}
}
public SpanStack Clone()
{
SpanStack n = new SpanStack();
n.top = this.top;
return n;
}
object ICloneable.Clone()
{
return this.Clone();
}
public Enumerator GetEnumerator()
{
return new Enumerator(new StackNode(top, null));
}
IEnumerator<Span> IEnumerable<Span>.GetEnumerator()
{
return this.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public sealed class Enumerator : IEnumerator<Span>
{
StackNode c;
internal Enumerator(StackNode node)
{
c = node;
}
public Span Current {
get {
return c.Data;
}
}
object System.Collections.IEnumerator.Current {
get {
return c.Data;
}
}
public void Dispose()
{
c = null;
}
public bool MoveNext()
{
c = c.Previous;
return c != null;
}
public void Reset()
{
throw new NotSupportedException();
}
}
}
}

4
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineSegment.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.TextEditor.Document
int delimiterLength; int delimiterLength;
List<TextWord> words = null; List<TextWord> words = null;
Stack<Span> highlightSpanStack = null; SpanStack highlightSpanStack = null;
public TextWord GetWord(int column) public TextWord GetWord(int column)
{ {
@ -83,7 +83,7 @@ namespace ICSharpCode.TextEditor.Document
return new HighlightColor(Color.Black, false, false); return new HighlightColor(Color.Black, false, false);
} }
public Stack<Span> HighlightSpanStack { public SpanStack HighlightSpanStack {
get { get {
return highlightSpanStack; return highlightSpanStack;
} }

1
src/Main/StartUp/Project/Dialogs/SplashScreen.cs

@ -90,6 +90,7 @@ namespace ICSharpCode.SharpDevelop
parameterList.Clear(); parameterList.Clear();
foreach (string arg in args) { foreach (string arg in args) {
if (arg.Length == 0) continue;
if (arg[0] == '-' || arg[0] == '/') { if (arg[0] == '-' || arg[0] == '/') {
int markerLength = 1; int markerLength = 1;

Loading…
Cancel
Save