Author: mkrueger
Date: 2008-02-13 22:51:57 -0500 (Wed, 13 Feb 2008)
New Revision: 95607

Modified:
   trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
   trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
   trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/ISegment.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSegment.cs
   trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Segment.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextMarker.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
Log:
* Mono.TextEditor/ISegment.cs, Mono.TextEditor/DefaultEditActions.cs,
  Mono.TextEditor/TextViewMargin.cs, Mono.TextEditor/Document.cs,
  Mono.TextEditor/TextEditorData.cs, Mono.TextEditor/TextMarker.cs,
  Mono.TextEditor/TextEditor.cs, Mono.TextEditor/Segment.cs,
  Mono.TextEditor/LineSegment.cs,
  Mono.TextEditor.Highlighting/SyntaxModeService.cs: Refactored much.
  Tab stops should now work. I've changed the update behaviour a bit
  - so expect some drawing issues (something updated too late or not
  updated at all).  Drawing itself should go faster, but I don't have
  hard data here.

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-14 
03:48:32 UTC (rev 95606)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-14 
03:51:57 UTC (rev 95607)
@@ -1,5 +1,17 @@
 2008-02-14  Mike Krüger <[EMAIL PROTECTED]> 
 
+       * Mono.TextEditor/ISegment.cs, Mono.TextEditor/DefaultEditActions.cs,
+         Mono.TextEditor/TextViewMargin.cs, Mono.TextEditor/Document.cs,
+         Mono.TextEditor/TextEditorData.cs, Mono.TextEditor/TextMarker.cs,
+         Mono.TextEditor/TextEditor.cs, Mono.TextEditor/Segment.cs,
+         Mono.TextEditor/LineSegment.cs,
+         Mono.TextEditor.Highlighting/SyntaxModeService.cs: Refactored much. 
Tab
+         stops should now work. I've changed the update behaviour a bit - so
+         expect some drawing issues (something updated too late or not updated 
at
+         all).  Drawing itself should go faster, but I don't have hard data 
here.
+
+2008-02-14  Mike Krüger <[EMAIL PROTECTED]> 
+
        * Mono.TextEditor/TextViewMargin.cs, Mono.TextEditor/TextEditor.cs: 
Fixed
          mouse selection to the left bug.
 

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
     2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
     2008-02-14 03:51:57 UTC (rev 95607)
@@ -261,9 +261,7 @@
        {
                public override void Run (TextEditorData data)
                {
-                       DocumentLocation newLocation = new DocumentLocation (0, 
0);
-                       if (newLocation != data.Caret.Location) 
-                               data.Caret.Location = newLocation;
+                       data.Caret.Location = new DocumentLocation (0, 0);
                }
        }
        
@@ -587,7 +585,7 @@
                        }
                        
                        if (data.IsSomethingSelected) {
-                               DeleteAction.DeleteSelection (data);
+                               data.DeleteSelectedText ();
                        }
                        
                        data.Document.Buffer.Insert (data.Caret.Offset, new 
StringBuilder (TextEditorOptions.Options.IndentationString));
@@ -612,6 +610,7 @@
                                }
                        }*/
                        data.Document.Buffer.Insert (data.Caret.Offset, 
newLine);
+                       data.Document.CommitLineToEndUpdate (data.Caret.Line);
                        data.Caret.Column = 0;
                        data.Caret.Line++;
                }
@@ -628,7 +627,7 @@
                public override void Run (TextEditorData data)
                {
                        if (data.IsSomethingSelected) {
-                               DeleteAction.DeleteSelection (data);
+                               data.DeleteSelectedText ();
                                return;
                        }
                        if (data.Caret.Offset == 0)
@@ -638,6 +637,7 @@
                                LineSegment lineAbove = 
data.Document.Splitter.Get (data.Caret.Line - 1);
                                data.Caret.Location = new DocumentLocation 
(data.Caret.Line - 1, lineAbove.EditableLength);
                                data.Document.Buffer.Remove 
(lineAbove.EndOffset - lineAbove.DelimiterLength, lineAbove.DelimiterLength);
+                               data.Document.CommitLineToEndUpdate 
(data.Caret.Line);
                        } else {
                                RemoveCharBeforCaret (data);
                        }
@@ -646,17 +646,10 @@
        
        public class DeleteAction : EditAction
        {
-               public static void DeleteSelection (TextEditorData data)
-               {
-                       ISegment selection = data.SelectionRange;
-                       data.Caret.Offset = selection.Offset;
-                       data.Document.Buffer.Remove (selection.Offset, 
selection.Length);
-                       data.ClearSelection ();
-               }
                public override void Run (TextEditorData data)
                {
                        if (data.IsSomethingSelected) {
-                               DeleteSelection (data);
+                               data.DeleteSelectedText ();
                                return;
                        }
                        if (data.Caret.Offset >= data.Document.Buffer.Length)
@@ -668,12 +661,11 @@
                                        if (line.EndOffset == 
data.Document.Buffer.Length)
                                                line.DelimiterLength = 0;
                                }
-                               data.Document.RequestUpdate (new 
LineToEndUpdate (data.Caret.Line));
+                               data.Document.CommitLineToEndUpdate 
(data.Caret.Line);
                        } else {
                                data.Document.Buffer.Remove (data.Caret.Offset, 
1); 
-                               data.Document.RequestUpdate (new LineUpdate 
(data.Caret.Line));
+                               data.Document.CommitLineUpdate 
(data.Caret.Line);
                        }
-                       data.Document.CommitDocumentUpdate ();
                }
        }
        
@@ -894,13 +886,14 @@
                {
                        if (clipboard.WaitIsTextAvailable ()) {
                                if (data.IsSomethingSelected) {
-                                       DeleteAction.DeleteSelection (data);
+                                       data.DeleteSelectedText ();
                                }
                                StringBuilder sb = new StringBuilder 
(clipboard.WaitForText ());
                                data.Document.Buffer.Insert (data.Caret.Offset, 
sb);
                                int oldLine = data.Caret.Line;
                                data.Caret.Offset += sb.Length;
                                data.Document.RequestUpdate (oldLine != 
data.Caret.Line ? (DocumentUpdateRequest)new LineToEndUpdate (oldLine) : 
(DocumentUpdateRequest)new LineUpdate (oldLine));
+                               data.Document.CommitDocumentUpdate ();
                        }
                }
                public static void PasteFromPrimary (TextEditorData data)

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs   
    2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs   
    2008-02-14 03:51:57 UTC (rev 95607)
@@ -447,7 +447,7 @@
                
                public void RequestUpdate (DocumentUpdateRequest request)
                {
-//                     System.Console.WriteLine(request);
+                       //System.Console.WriteLine(request);
                        updateRequests.Add (request);
                }
                
@@ -458,6 +458,30 @@
                        updateRequests.Clear ();
                }
                
+               public void CommitLineToEndUpdate (int line)
+               {
+                       RequestUpdate (new LineToEndUpdate (line));
+                       CommitDocumentUpdate ();
+               }
+                               
+               public void CommitLineUpdate (int line)
+               {
+                       RequestUpdate (new LineUpdate (line));
+                       CommitDocumentUpdate ();
+               }
+                                       
+               public void CommitUpdateAll ()
+               {
+                       RequestUpdate (new UpdateAll ());
+                       CommitDocumentUpdate ();
+               }
+                                               
+               public void CommitMultipleLineUpdate (int start, int end)
+               {
+                       RequestUpdate (new MultipleLineUpdate (start, end));
+                       CommitDocumentUpdate ();
+               }
+               
                public event EventHandler DocumentUpdated;
        }
 }

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/ISegment.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/ISegment.cs   
    2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/ISegment.cs   
    2008-02-14 03:51:57 UTC (rev 95607)
@@ -44,6 +44,8 @@
                int EndOffset {
                        get;
                }
+               
+               bool Contains (int offset);
        }
 }      
 

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSegment.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSegment.cs
    2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSegment.cs
    2008-02-14 03:51:57 UTC (rev 95607)
@@ -155,6 +155,11 @@
                        }
                }
                
+               public bool Contains (int offset)
+               {
+                       return Offset <= offset && offset < EndOffset;
+               }
+               
                public override string ToString ()
                {
                        return String.Format ("[LineSegment: Offset={0}, 
Length={1}, DelimiterLength={2}, StartSpan={3}]", this.Offset, this.Length, 
this.DelimiterLength, StartSpan == null ? "null" : StartSpan.Length.ToString());

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Segment.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Segment.cs    
    2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Segment.cs    
    2008-02-14 03:51:57 UTC (rev 95607)
@@ -68,6 +68,11 @@
                        this.length = length;
                }
                
+               public bool Contains (int offset)
+               {
+                       return Offset <= offset && offset < EndOffset;
+               }
+               
                public override string ToString ()
                {
                        return String.Format ("[Segment: Offset={0}, 
Length={1}]", this.offset, this.length);

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs 
    2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs 
    2008-02-14 03:51:57 UTC (rev 95607)
@@ -120,14 +120,9 @@
                                        this.textEditorData.VAdjustment.Value = 
System.Math.Ceiling (this.textEditorData.VAdjustment.Value);
                                        return;
                                }
-//                             int reminder  = 
(int)this.textEditorData.VAdjustment.Value % LineHeight;
-//                             if (reminder != 0) {
-//                                     this.textEditorData.VAdjustment.Value 
-= reminder;
-//                                     return;
-//                             }
                                int delta = 
(int)(this.textEditorData.VAdjustment.Value - this.oldVadjustment);
                                oldVadjustment = 
this.textEditorData.VAdjustment.Value;
-                               if (delta >= Allocation.Height - 
this.LineHeight || this.textViewMargin.inSelectionDrag) {
+                               if (delta >= Allocation.Height - 
this.LineHeight * 2 || this.TextViewMargin.inSelectionDrag) {
                                        this.QueueDraw ();
                                        return;
                                }
@@ -278,22 +273,7 @@
                                oldSelection = selection;
                                this.RedrawLines (System.Math.Min (from, to), 
System.Math.Max (from, to));
                        };
-                       Document.Splitter.LinesInserted  += delegate (object 
sender, LineEventArgs e) {
-                               int lineNumber = 
Document.Splitter.GetLineNumberForOffset (e.Line.Offset);
-                               RedrawFromLine (lineNumber);
-                       };
-                       Document.Splitter.LinesRemoved  += delegate (object 
sender, LineEventArgs e) {
-                               int lineNumber = 
Document.Splitter.GetLineNumberForOffset (e.Line.Offset);
-                               RedrawFromLine (lineNumber);
-                       };
-//                     Document.Splitter.LineLenghtChanged += delegate (object 
sender, LineEventArgs e) {
-//                             int lineNumber = 
Document.Splitter.GetLineNumberForOffset (e.Line.Offset);
-//                             this.RedrawLine (lineNumber);
-//                             if (longestLine == null || longestLine.Length < 
e.Line.Length || longestLine == e.Line) {
-//                                     longestLine = e.Line;
-//                                     this.SetAdjustments ();
-//                             }
-//                     };
+                       
                        Document.DocumentUpdated += delegate {
                                try {
                                        foreach (DocumentUpdateRequest request 
in Document.UpdateRequests) {
@@ -637,7 +617,6 @@
                {
                        if (Caret.Line < 0 || Caret.Line >= 
Document.Splitter.LineCount)
                                return;
-                       
                        int yMargin = 2 * this.LineHeight;
                        int xMargin = 10 * this.textViewMargin.charWidth;
                        int caretPosition = Document.LogicalToVisualLine 
(Caret.Line) * this.LineHeight;
@@ -698,8 +677,6 @@
                        }
                        int startY = startLine * this.LineHeight - reminder;
                        int curY = startY;
-                       //System.Console.WriteLine("Redraw #" + (endLine - 
startLine));
-                       //System.Console.WriteLine("Redraw line:" + startLine + 
" to " + endLine);
                        for (int visualLineNumber = startLine; visualLineNumber 
<= endLine; visualLineNumber++) {
                                int curX = 0;
                                int logicalLineNumber = 
Document.VisualToLogicalLine (visualLineNumber + firstLine);
@@ -707,11 +684,15 @@
                                        if (margin.IsVisible) {
                                                margin.XOffset = curX;
                                                curX += margin.Width;
-                                               if (curX > area.X || 
margin.Width < 0)
+                                               if (curX > area.X || 
margin.Width < 0) {
+                                                       DateTime now = 
DateTime.Now;
                                                        margin.Draw (win, area, 
logicalLineNumber, margin.XOffset, curY);
+                                               }
                                        }
                                }
                                curY += LineHeight;
+                               if (curY > area.Bottom)
+                                       break;
                        }
                }
                

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
 2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
 2008-02-14 03:51:57 UTC (rev 95607)
@@ -192,10 +192,16 @@
                        if (!IsSomethingSelected)
                                return;
                        ISegment selection = SelectionRange;
+                       bool needUpdate = this.selectionStart.Segment != 
this.selectionEnd.Segment;
                        if (Caret.Offset > selection.Offset)
                                Caret.Offset -= selection.Length;
+                       
                        Document.Buffer.Remove (selection.Offset, 
selection.Length);
+                       if (needUpdate)
+                               Document.RequestUpdate (new LineToEndUpdate 
(Document.Splitter.GetLineNumberForOffset (selection.Offset)));
                        ClearSelection();
+                       if (needUpdate)
+                               Document.CommitDocumentUpdate ();
                }
                
                public event EventHandler SelectionChanged;

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextMarker.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextMarker.cs 
    2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextMarker.cs 
    2008-02-14 03:51:57 UTC (rev 95607)
@@ -36,6 +36,12 @@
                int endColumn;
                LineSegment line;
                
+               public string Url {
+                       get {
+                               return url;
+                       }
+               }
+               
                public UrlMarker (LineSegment line, string url, string style, 
int startColumn, int endColumn)
                {
                        this.line        = line;

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
 2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
 2008-02-14 03:51:57 UTC (rev 95607)
@@ -28,6 +28,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Text;
 
 using Mono.TextEditor.Highlighting;
 
@@ -240,6 +241,7 @@
                        int index = line.Offset + line.EditableLength - offset;
                        int selectionStart = TextEditorData.SelectionStart != 
null ? TextEditorData.SelectionStart.Segment.Offset + 
TextEditorData.SelectionStart.Column : -1;
                        int selectionEnd = TextEditorData.SelectionEnd != null 
? TextEditorData.SelectionEnd.Segment.Offset + 
TextEditorData.SelectionEnd.Column : -1;
+                       int visibleColumn = 0;
                        if (selectionStart > selectionEnd) {
                                int tmp = selectionEnd;
                                selectionEnd = selectionStart;
@@ -263,19 +265,19 @@
 //                             Console.WriteLine ("#" + chunks.Length);
                        foreach (Chunk chunk in chunks) {
                                if (chunk.Offset >= selectionStart && 
chunk.EndOffset <= selectionEnd) {
-                                       DrawTextWithHighlightedWs (win, true, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (chunk));
+                                       DrawTextWithHighlightedWs (win, true, 
chunk.Style, ref visibleColumn, ref xPos, y, chunk.Offset, chunk.EndOffset);
                                } else if (chunk.Offset >= selectionStart && 
chunk.Offset < selectionEnd && chunk.EndOffset > selectionEnd) {
-                                       DrawTextWithHighlightedWs (win, true, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (chunk.Offset, selectionEnd 
- chunk.Offset));
-                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (selectionEnd, 
chunk.EndOffset - selectionEnd));
+                                       DrawTextWithHighlightedWs (win, true, 
chunk.Style, ref visibleColumn, ref xPos, y, chunk.Offset, selectionEnd);
+                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref visibleColumn, ref xPos, y, selectionEnd, chunk.EndOffset);
                                } else if (chunk.Offset < selectionStart && 
chunk.EndOffset > selectionStart && chunk.EndOffset <= selectionEnd) {
-                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (chunk.Offset, 
selectionStart - chunk.Offset));
-                                       DrawTextWithHighlightedWs (win, true, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (selectionStart, 
chunk.EndOffset - selectionStart));
+                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref visibleColumn, ref xPos, y, chunk.Offset, selectionStart);
+                                       DrawTextWithHighlightedWs (win, true, 
chunk.Style, ref visibleColumn, ref xPos, y, selectionStart, chunk.EndOffset);
                                } else if (chunk.Offset < selectionStart && 
chunk.EndOffset > selectionEnd) {
-                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (chunk.Offset, 
selectionStart - chunk.Offset));
-                                       DrawTextWithHighlightedWs (win, true, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (selectionStart, 
selectionEnd - selectionStart));
-                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (selectionEnd, 
chunk.EndOffset - selectionEnd));
+                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref visibleColumn, ref xPos, y, chunk.Offset, selectionStart);
+                                       DrawTextWithHighlightedWs (win, true, 
chunk.Style, ref visibleColumn, ref xPos, y, selectionStart, selectionEnd);
+                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref visibleColumn, ref xPos, y, selectionEnd, chunk.EndOffset);
                                } else 
-                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref xPos, y, Document.Buffer.GetTextAt (chunk));
+                                       DrawTextWithHighlightedWs (win, false, 
chunk.Style, ref visibleColumn, ref xPos, y, chunk.Offset, chunk.EndOffset);
                        }
                        if (line.Markers != null) {
                                foreach (TextMarker marker in line.Markers) {
@@ -284,54 +286,84 @@
                        }
                        
                        int caretOffset = Caret.Offset;
-                       if (offset <= caretOffset && caretOffset < offset + 
length) {
-                               int caretX = GetWidth 
(Document.Buffer.GetTextAt (offset, caretOffset - offset));
-                               DrawCaret (win, xStart + caretX, y);
+                       if (caretOffset == offset + length) 
+                               DrawCaret (win, xPos, y);
+               }
+               
+               StringBuilder wordBuilder = new StringBuilder ();
+               void OutputWordBuilder (Gdk.Drawable win, bool selected, 
ChunkStyle style, ref int visibleColumn, ref int xPos, int y)
+               {
+                       if (selected) {
+                               DrawText (win, ColorStyle.SelectedFg, 
ColorStyle.SelectedBg, ref xPos, y);
+                       } else {
+                               DrawText (win, style.Color, 
ColorStyle.Background, ref xPos, y);
                        }
+                       visibleColumn += wordBuilder.Length;
+                       wordBuilder.Length = 0;
                }
                
-               void DrawTextWithHighlightedWs (Gdk.Drawable win, bool 
selected, ChunkStyle style, ref int xPos, int y, string text)
+               void DrawTextWithHighlightedWs (Gdk.Drawable win, bool 
selected, ChunkStyle style, ref int visibleColumn, ref int xPos, int y, int 
startOffset, int endOffset)
                {
-                       string[] spaces = text.Split (' ');
-                       for (int i = 0; i < spaces.Length; i++) {
-                               string[] tabs = spaces[i].Split ('\t');
-                               
-                               for (int j = 0; j < tabs.Length; j++) {
-                                       gc.RgbFgColor = selected ? 
ColorStyle.SelectedFg : style.Color;
-                                       if (style.Bold)
-                                               layout.FontDescription.Weight = 
Pango.Weight.Bold; 
-                                       if (style.Italic)
-                                               layout.FontDescription.Style  = 
Pango.Style.Italic; 
-                                       DrawText (win, ref xPos, y, tabs[j]);
-                                       if (style.Bold)
-                                               layout.FontDescription.Weight = 
Pango.Weight.Normal; 
-                                       if (style.Italic)
-                                               layout.FontDescription.Style  = 
Pango.Style.Normal; 
-                                       if (j + 1 < tabs.Length) {
-                                               if 
(TextEditorOptions.Options.ShowTabs) { 
-                                                       DrawTabMarker (win, 
selected, ref xPos, y);
-                                               } else {
-                                                       DrawText (win, ref 
xPos, y, new string (' ', TextEditorOptions.Options.TabSize));
-                                               }
-                                       }
+                       int caretOffset = Caret.Offset;
+                       int drawCaretAt = -1;
+                       wordBuilder.Length = 0;
+                       if (style.Bold)
+                               layout.FontDescription.Weight = 
Pango.Weight.Bold;
+                       if (style.Italic)
+                               layout.FontDescription.Style = 
Pango.Style.Italic;
+                       for (int offset = startOffset; offset < endOffset; 
offset++) {
+                               char ch = Document.Buffer.GetCharAt (offset);
+                               if (ch == ' ') {
+                                       OutputWordBuilder (win, selected, 
style, ref visibleColumn, ref xPos, y);
+                                       DrawRectangleWithRuler (win, 
this.XOffset, new Gdk.Rectangle (xPos, y, charWidth, LineHeight), selected ? 
ColorStyle.SelectedBg : ColorStyle.Background);
+                                       
+                                       if 
(TextEditorOptions.Options.ShowSpaces) 
+                                               DrawSpaceMarker (win, selected, 
xPos, y);
+                                       if (offset == caretOffset) 
+                                               DrawCaret (win, xPos, y);
+                                       xPos += this.charWidth;
+                                       visibleColumn++;
+                               } else if (ch == '\t') {
+                                       OutputWordBuilder (win, selected, 
style, ref visibleColumn, ref xPos, y);
+                                       
+                                       int newColumn = visibleColumn + 
TextEditorOptions.Options.TabSize;
+                                       newColumn = (newColumn / 
TextEditorOptions.Options.TabSize) * TextEditorOptions.Options.TabSize;
+                                       int delta = (newColumn - visibleColumn) 
* this.charWidth;
+                                       visibleColumn = newColumn;
+                                       
+                                       DrawRectangleWithRuler (win, 
this.XOffset, new Gdk.Rectangle (xPos, y, delta, LineHeight), selected ? 
ColorStyle.SelectedBg : ColorStyle.Background);
+                                       if (TextEditorOptions.Options.ShowTabs) 
+                                               DrawTabMarker (win, selected, 
xPos, y);
+                                       if (offset == caretOffset) 
+                                               DrawCaret (win, xPos, y);
+                                       xPos += delta;
+                               } else {
+                                       if (offset == caretOffset) 
+                                               drawCaretAt = xPos + 
wordBuilder.Length * this.charWidth;
+                                       wordBuilder.Append (ch);
                                }
-                               
-                               if (i + 1 < spaces.Length) {
-                                       if 
(TextEditorOptions.Options.ShowSpaces) { 
-                                               DrawSpaceMarker (win, selected, 
ref xPos, y);
-                                       } else {
-                                               DrawText (win, ref xPos, y, " 
");
-                                       }
-                               }
                        }
+                       OutputWordBuilder (win, selected, style, ref 
visibleColumn, ref xPos, y);
+                       
+                       if (style.Bold)
+                               layout.FontDescription.Weight = 
Pango.Weight.Normal;
+                       if (style.Italic)
+                               layout.FontDescription.Style = 
Pango.Style.Normal;
+                       
+                       if (drawCaretAt >= 0)
+                               DrawCaret (win, drawCaretAt , y);
                }
                
-               void DrawText (Gdk.Drawable win, ref int xPos, int y, string 
text)
+               void DrawText (Gdk.Drawable win, Gdk.Color foreColor, Gdk.Color 
backgroundColor, ref int xPos, int y)
                {
-                       layout.SetText (text);
-                       win.DrawLayout (gc, xPos, y, layout);
+                       layout.SetText (wordBuilder.ToString ());
+                       
                        int width, height;
                        layout.GetPixelSize (out width, out height);
+                       DrawRectangleWithRuler (win, this.XOffset, new 
Gdk.Rectangle (xPos, y, width, height), backgroundColor);
+                       
+                       gc.RgbFgColor = foreColor;
+                       win.DrawLayout (gc, xPos, y, layout);
                        xPos += width;
                }
                
@@ -341,18 +373,16 @@
                        win.DrawLayout (gc, xPos, y, eolMarker);
                }
                
-               void DrawSpaceMarker (Gdk.Drawable win, bool selected, ref int 
xPos, int y)
+               void DrawSpaceMarker (Gdk.Drawable win, bool selected, int 
xPos, int y)
                {
                        gc.RgbFgColor = selected ? ColorStyle.SelectedFg : 
ColorStyle.WhitespaceMarker;
                        win.DrawLayout (gc, xPos, y, spaceMarker);
-                       xPos += charWidth;
                }
                
-               void DrawTabMarker (Gdk.Drawable win, bool selected, ref int 
xPos, int y)
+               void DrawTabMarker (Gdk.Drawable win, bool selected, int xPos, 
int y)
                {
                        gc.RgbFgColor = selected ? ColorStyle.SelectedFg : 
ColorStyle.WhitespaceMarker;
                        win.DrawLayout (gc, xPos, y, tabMarker);
-                       xPos += charWidth * TextEditorOptions.Options.TabSize;
                }
                
                void DrawInvalidLineMarker (Gdk.Drawable win, int x, int y)
@@ -433,10 +463,13 @@
                                        SelectionMoveLeft.StartSelection 
(TextEditorData);
                                }
                                Caret.PreserveSelection = true;
+                               Caret.AutoScrollToCaret = false;
 //                             int oldLine = Caret.Line;
                                Caret.Location = VisualToDocumentLocation (x, 
y);
                                Caret.PreserveSelection = false;
+                               Caret.AutoScrollToCaret = true;
                                SelectionMoveLeft.EndSelection (TextEditorData);
+                               this.textEditor.ScrollToCaret ();
                                this.caretBlink = false;
 //                             textEditor.RedrawLines (System.Math.Min 
(oldLine, Caret.Line), System.Math.Max (oldLine, Caret.Line));
                        }
@@ -446,12 +479,24 @@
                {
                        if (line.EditableLength == 0)
                                return 0;
-                       string text = this.Document.Buffer.GetTextAt 
(line.Offset, System.Math.Min (column, line.EditableLength));
-                       text = text.Replace ("\t", new string (' ', 
TextEditorOptions.Options.TabSize));
-                       layout.SetText (text);
-                       int width, height;
-                       layout.GetPixelSize (out width, out height);
-                       return width;
+                       
+                       int lineXPos  = 0;
+                       
+                       int visibleColumn = 0;
+                       for (int c = 0; c < column; c++) {
+                               int delta;
+                               if (this.Document.Buffer.GetCharAt (line.Offset 
+ column) == '\t') {
+                                       int newColumn = visibleColumn + 
TextEditorOptions.Options.TabSize;
+                                       newColumn = (newColumn / 
TextEditorOptions.Options.TabSize) * TextEditorOptions.Options.TabSize;
+                                       delta = (newColumn - visibleColumn) * 
this.charWidth;
+                                       visibleColumn = newColumn;
+                               } else {
+                                       delta = this.charWidth;
+                                       visibleColumn++;
+                               }
+                               lineXPos += delta;
+                       }
+                       return lineXPos;
                }
                int rulerX = 0;
                
@@ -476,12 +521,14 @@
                        gc.RgbFgColor = color;
                        if (TextEditorOptions.Options.ShowRuler) {
                                int divider = System.Math.Max (area.Left, 
System.Math.Min (x + rulerX, area.Right));
-                               win.DrawRectangle (gc, true, new Rectangle 
(area.X, area.Y, divider - area.X, area.Height));
-                               gc.RgbFgColor = DimColor (color);
-                               win.DrawRectangle (gc, true, new Rectangle 
(divider, area.Y, area.Right - divider, area.Height));
-                       } else {
-                               win.DrawRectangle (gc, true, area);
+                               if (divider < area.Right) {
+                                       win.DrawRectangle (gc, true, new 
Rectangle (area.X, area.Y, divider - area.X, area.Height));
+                                       gc.RgbFgColor = DimColor (color);
+                                       win.DrawRectangle (gc, true, new 
Rectangle (divider, area.Y, area.Right - divider, area.Height));
+                                       return;
+                               }
                        }
+                       win.DrawRectangle (gc, true, area);
                }
                
                public override void Draw (Gdk.Drawable win, Gdk.Rectangle 
area, int lineNr, int x, int y)
@@ -490,82 +537,16 @@
                        
                        LineSegment line = lineNr < Document.Splitter.LineCount 
? Document.Splitter.Get (lineNr) : null;
                        int xStart = System.Math.Max (area.X, XOffset);
-                       gc.ClipRectangle = new Gdk.Rectangle (xStart, 
-                                                             y, 
-                                                             area.Right - 
xStart,
-                                                             LineHeight);
+                       gc.ClipRectangle = new Gdk.Rectangle (xStart, y, 
area.Right - xStart, LineHeight);
                
                        Gdk.Rectangle lineArea = new Gdk.Rectangle (XOffset, y, 
textEditor.Allocation.Width - XOffset, LineHeight);
-                       bool isSelected = false;
-                       bool drawDefaultBg = true;
-                       bool eolSelected = false;
-                       Gdk.Color defaultStateType = lineNr == Caret.Line && 
TextEditorOptions.Options.HighlightCaretLine ? this.ColorStyle.LineMarker : 
this.ColorStyle.Background;
-                       
-                       if (line != null && TextEditorData.SelectionStart != 
null && TextEditorData.SelectionEnd != null) {
-                               SelectionMarker start;
-                               SelectionMarker end;
-                               
-                               if 
(TextEditorData.SelectionStart.Segment.Offset < 
TextEditorData.SelectionEnd.Segment.EndOffset) {
-                                       start = TextEditorData.SelectionStart;
-                                       end   = TextEditorData.SelectionEnd;
-                               } else {
-                                       start = TextEditorData.SelectionEnd;
-                                       end   = TextEditorData.SelectionStart;
-                               }
-                               isSelected = start.Segment.Offset < line.Offset 
&& line.Offset + line.EditableLength < end.Segment.EndOffset;
-                               int selectionColumnStart = -1;
-                               int selectionColumnEnd   = -1;
-                               if (line == end.Segment) {
-                                       selectionColumnStart = 0;
-                                       selectionColumnEnd   = end.Column; 
-                               } 
-                               if (line == start.Segment) {
-                                       selectionColumnStart = start.Column; 
-                               } 
-                               if (selectionColumnStart >= 0) {
-                                       if (selectionColumnStart >= 0 && 
selectionColumnEnd >= 0 && selectionColumnEnd < selectionColumnStart) {
-                                               int tmp = selectionColumnStart;
-                                               selectionColumnStart = 
selectionColumnEnd;
-                                               selectionColumnEnd = tmp;
-                                       }
-                                       
-                                       // draw space before selection
-                                       int visualXStart = ColumnToVisualX 
(line, selectionColumnStart) - (int)TextEditorData.HAdjustment.Value;
-                                       lineArea = new Gdk.Rectangle (x, y, 
visualXStart, LineHeight);
-                                       DrawRectangleWithRuler (win, x, 
lineArea, defaultStateType);
-                                       
-                                       // draw selection (if selection is in 
the middle)
-                                       if (selectionColumnEnd >= 0) {
-                                               int visualXEnd = 
ColumnToVisualX (line, selectionColumnEnd) - 
(int)TextEditorData.HAdjustment.Value;
-                                               int reminder =  System.Math.Max 
(0, -visualXStart); 
-                                               if (visualXEnd - visualXStart > 
reminder) {
-                                                       lineArea = new 
Gdk.Rectangle (x + visualXStart + reminder, y, visualXEnd - visualXStart - 
reminder, LineHeight);
-                                                       DrawRectangleWithRuler 
(win, x, lineArea, ColorStyle.SelectedBg);
-                                               }
-                                       }
-                                       
-                                       // draw remaining line (unselected, if 
in middle, otherwise rest of line is selected)
-                                       lineArea = new Gdk.Rectangle 
(System.Math.Max (x, lineArea.Right), y, area.Width - System.Math.Max (x, 
lineArea.Right), LineHeight);
-                                       DrawRectangleWithRuler (win, x, 
lineArea, selectionColumnEnd >= 0 ? defaultStateType : 
this.ColorStyle.SelectedBg);
-                                       eolSelected = true;
-                                       drawDefaultBg = false;
-                               }
-                       }
                        int width, height;
                        
-                       if (drawDefaultBg) {
-                               eolSelected = isSelected;
-                               DrawRectangleWithRuler (win, x, lineArea, 
isSelected ? this.ColorStyle.SelectedBg : defaultStateType);
-                       }
-                       
-                       if (TextEditorOptions.Options.ShowRuler) {
-                               gc.RgbFgColor = ColorStyle.Ruler;
-                               win.DrawLine (gc, x + rulerX, y, x + rulerX, y 
+ LineHeight); 
-                       }
-                       
                        if (line == null) {
-                               if (TextEditorOptions.Options.ShowInvalidLines)
+                               if (TextEditorOptions.Options.ShowInvalidLines) 
{
+                                       DrawRectangleWithRuler (win, x, 
lineArea, this.ColorStyle.Background);
                                        DrawInvalidLineMarker (win, x, y);
+                               }
                                return;
                        }
                        
@@ -619,8 +600,20 @@
                        // Draw remaining line
                        if (line.EndOffset - offset > 0)
                                DrawLineText (win, line, offset, line.Offset + 
line.EditableLength - offset, ref xPos, y);
-                       if (TextEditorOptions.Options.ShowEolMarkers) 
-                               DrawEolMarker (win, eolSelected, ref xPos, y);
+                       
+                       bool isEolSelected = TextEditorData.IsSomethingSelected 
&& TextEditorData.SelectionRange.Contains (line.Offset + line.EditableLength);
+                       if (TextEditorOptions.Options.ShowEolMarkers) // TODO: 
EOL selected
+                               DrawEolMarker (win, isEolSelected, ref xPos, y);
+                       
+                       lineArea.X     = xPos;
+                       lineArea.Width = textEditor.Allocation.Width - xPos;
+                       DrawRectangleWithRuler (win, x, lineArea, isEolSelected 
? this.ColorStyle.SelectedBg : this.ColorStyle.Background);
+                       
+                       if (TextEditorOptions.Options.ShowRuler) {
+                               gc.RgbFgColor = ColorStyle.Ruler;
+                               win.DrawLine (gc, x + rulerX, y, x + rulerX, y 
+ LineHeight); 
+                       }
+                       
                        if (caretOffset == line.Offset + line.EditableLength)
                                DrawCaret (win, xPos, y);
                }
@@ -636,13 +629,18 @@
                        LineSegment line = Document.Splitter.Get (lineNumber);
                        int lineXPos  = 0;
                        int column;
+                       int  visibleColumn = 0;
                        int visualXPos = x + 
(int)TextEditorData.HAdjustment.Value;
                        for (column = 0; column < line.EditableLength; 
column++) {
                                int delta;
                                if (this.Document.Buffer.GetCharAt (line.Offset 
+ column) == '\t') {
-                                       delta = 
TextEditorOptions.Options.TabSize * this.charWidth;
+                                       int newColumn = visibleColumn + 
TextEditorOptions.Options.TabSize;
+                                       newColumn = (newColumn / 
TextEditorOptions.Options.TabSize) * TextEditorOptions.Options.TabSize;
+                                       delta = (newColumn - visibleColumn) * 
this.charWidth;
+                                       visibleColumn = newColumn;
                                } else {
                                        delta = this.charWidth;
+                                       visibleColumn++;
                                }
                                int nextXPosition = lineXPos + delta;
                                if (nextXPosition >= visualXPos) {

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
 2008-02-14 03:48:32 UTC (rev 95606)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
 2008-02-14 03:51:57 UTC (rev 95607)
@@ -190,7 +190,6 @@
                                        rule = mode.GetRule (spanStack.Peek 
().Rule) ?? mode;
                                }
                                ScanSpans (doc, rule, spanStack, line.Offset, 
line.Offset + line.EditableLength);
-                               System.Console.WriteLine(spanStack.Count);
                                while (spanStack.Count > 0 && spanStack.Peek 
().StopAtEol)
                                        spanStack.Pop ();
                        } while (iter.MoveNext ());

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to