Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMike Krüger <mikkrg@microsoft.com>2019-03-07 12:54:02 +0300
committerMike Krüger <mikkrg@microsoft.com>2019-03-08 15:00:40 +0300
commit3f19472059da83c064784187806638535069317e (patch)
tree28637a1a6dda2496eb68681c90e6e9f98e8aa94e /main
parent9c4983949175f412c32ea90b939fede8d648e9e6 (diff)
[TextEditor] Fixed pango layout cache.
Diffstat (limited to 'main')
-rw-r--r--main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs45
-rw-r--r--main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs4
2 files changed, 32 insertions, 17 deletions
diff --git a/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs b/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs
index 6cb5586a22..cd3e89f8f0 100644
--- a/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs
+++ b/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs
@@ -1020,7 +1020,7 @@ namespace Mono.TextEditor
}
}
- public bool Equals (DocumentLine line, int offset, int length, int selectionStart, int selectionEnd)
+ public bool Equals (DocumentLine line, string lineText, int length, HighlightedLine cachedLine, int selectionStart, int selectionEnd)
{
int selStart = 0, selEnd = 0;
if (selectionEnd >= 0) {
@@ -1029,7 +1029,17 @@ namespace Mono.TextEditor
}
if (selStart != this.SelectionStart || selEnd != this.SelectionEnd || Length != length || MarkerLength != doc.GetMarkers (line).Count ())
return false;
- return doc.Version.MoveOffsetTo (version, offset) == Offset;
+
+ if (cachedLine.Segments.Count != Layout.Chunks.Count)
+ return false;
+ for (int i = 0; i < cachedLine.Segments.Count; i++) {
+ var seg1 = cachedLine.Segments [i];
+ var seg2 = Layout.Chunks [i];
+ if (seg1.Length != seg2.Length || seg1.ColorStyleKey != seg2.ColorStyleKey) {
+ return false;
+ }
+ }
+ return lineText == Layout.Text;
}
public override bool Equals (object obj)
@@ -1060,10 +1070,24 @@ namespace Mono.TextEditor
bool containsPreedit = textEditor.ContainsPreedit (offset, length);
LayoutDescriptor descriptor;
int lineNumber = line.LineNumber;
+ var lineOffset = line.Offset;
+
+ var cachedChunks = GetCachedChunks (Document, line, offset, length);
+ var textBuilder = StringBuilderCache.Allocate ();
+ foreach (var chunk in cachedChunks.Item1) {
+ try {
+ textBuilder.Append (Document.GetTextAt (lineOffset + chunk.Offset, chunk.Length));
+ } catch (Exception e) {
+ LoggingService.LogInternalError ("Error while getting chunk " + chunk, e);
+ }
+ }
+ string lineText = StringBuilderCache.ReturnAndFree (textBuilder);
+
if (!containsPreedit && layoutDict.TryGetValue (lineNumber, out descriptor)) {
- if (descriptor.Equals (line, offset, length, selectionStart, selectionEnd) && descriptor?.Layout?.Layout != null) {
+ if (descriptor.Equals (line, lineText, length, cachedChunks.Item3, selectionStart, selectionEnd) && descriptor.Layout?.Layout != null) {
return descriptor.Layout;
}
+
descriptor.Dispose ();
layoutDict.Remove (lineNumber);
}
@@ -1082,9 +1106,6 @@ namespace Mono.TextEditor
wrapper.Layout.Wrap = Pango.WrapMode.WordChar;
wrapper.Layout.Width = (int)((textEditor.Allocation.Width - XOffset - TextStartPosition) * Pango.Scale.PangoScale);
}
- StringBuilder textBuilder = StringBuilderCache.Allocate ();
- var cachedChunks = GetCachedChunks (Document, line, offset, length);
- var lineOffset = line.Offset;
var chunks = new List<ColoredSegment> (cachedChunks.Item1.Select (c => new ColoredSegment (c.Offset + lineOffset, c.Length, c.ScopeStack)));;
var markers = TextDocument.OrderTextSegmentMarkersByInsertion (Document.GetVisibleTextSegmentMarkersAt (line)).ToList ();
foreach (var marker in markers) {
@@ -1095,14 +1116,6 @@ namespace Mono.TextEditor
}
wrapper.HighlightedLine = cachedChunks.Item3;
wrapper.Chunks = chunks;
- foreach (var chunk in chunks) {
- try {
- textBuilder.Append (Document.GetTextAt (chunk));
- } catch {
- Console.WriteLine (chunk);
- }
- }
- string lineText = StringBuilderCache.ReturnAndFree (textBuilder);
uint preeditLength = 0;
if (containsPreedit) {
@@ -1567,11 +1580,13 @@ namespace Mono.TextEditor
internal HighlightedLine HighlightedLine { get; set; }
+ string text;
public string Text {
get {
- return Layout.Text;
+ return text;
}
set {
+ text = value;
Layout.SetText (value);
}
}
diff --git a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs
index c3f89ade36..ca41496a6a 100644
--- a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs
+++ b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs
@@ -135,9 +135,9 @@ namespace Mono.TextEditor
void SyntaxMode_HighlightingStateChanged (object sender, MonoDevelop.Ide.Editor.LineEventArgs e)
{
if (e == MonoDevelop.Ide.Editor.LineEventArgs.AllLines) {
- CommitUpdateAll (true);
+ CommitUpdateAll (false);
} else {
- CommitMultipleLineUpdate (e.Line.LineNumber, e.Line.LineNumber, true);
+ CommitMultipleLineUpdate (e.Line.LineNumber, e.Line.LineNumber, false);
}
}