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

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

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

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

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

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

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

Loading…
Cancel
Save