diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2012-03-11 14:57:55 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2012-03-11 14:57:55 +0400 |
commit | bbbc8f633bb06c7aa8d7c2fc0a21dced0bc8e4af (patch) | |
tree | 22419cad31721557eadb1ef6ce9e6352b9d36b91 /main/src/addins/VersionControl | |
parent | 6710760b13c9d5f2d85c31027e020188898a68bf (diff) |
[TextEditor] Replaced ISegment with TextSegment struct.
This has following benefits:
* Segments are now treated like locations.
* No null checks required anymore/structs are often more efficient.
* Struct is safe to document changes. The editor should become more
thread safer. Old segments may got changed from other treads (lines
for example) invalidating segments from other threads.
* No more default 'Segment' class (was a bad idea anyway) + avoided
name clash with Gdk.Segment.
Diffstat (limited to 'main/src/addins/VersionControl')
2 files changed, 21 insertions, 26 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs index 4ddcc1ea57..d2b25de4de 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs @@ -274,12 +274,12 @@ namespace MonoDevelop.VersionControl.Views diffCache.Clear (); } - static List<ISegment> BreakTextInWords (TextEditor editor, int start, int count) + static List<TextSegment> BreakTextInWords (TextEditor editor, int start, int count) { return TextBreaker.BreakLinesIntoWords(editor, start, count); } - List<Cairo.Rectangle> CalculateChunkPath (TextEditor editor, List<Hunk> diff, List<ISegment> words, bool useRemove) + List<Cairo.Rectangle> CalculateChunkPath (TextEditor editor, List<Hunk> diff, List<TextSegment> words, bool useRemove) { List<Cairo.Rectangle> result = new List<Cairo.Rectangle> (); int startOffset = -1; diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/MergeWidget.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/MergeWidget.cs index fc73d51fd9..030665b1ec 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/MergeWidget.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/MergeWidget.cs @@ -133,27 +133,27 @@ namespace MonoDevelop.VersionControl.Views int dividerOffset = doc.SearchForward ("=======", mergeStart).First (); LineSegment divider = doc.GetLineByOffset (dividerOffset); - int endOffset = doc.SearchForward (">>>>>>>", dividerOffset).First (); + int endOffset = doc.SearchForward (">>>>>>>", dividerOffset).First (); LineSegment end = doc.GetLineByOffset (endOffset); - yield return new Conflict (new Mono.TextEditor.Segment (start.EndOffset, divider.Offset - start.EndOffset), - new Mono.TextEditor.Segment (divider.EndOffset, end.Offset - divider.EndOffset), - new Mono.TextEditor.Segment (start), - new Mono.TextEditor.Segment (divider), - new Mono.TextEditor.Segment (end)); + yield return new Conflict (new TextSegment (start.EndOffset, divider.Offset - start.EndOffset), + new TextSegment (divider.EndOffset, end.Offset - divider.EndOffset), + start, + divider, + end); } } class Conflict { - public readonly Mono.TextEditor.Segment MySegment; - public readonly Mono.TextEditor.Segment TheirSegment; + public TextSegment MySegment; + public TextSegment TheirSegment; - public readonly Mono.TextEditor.Segment StartSegment; - public readonly Mono.TextEditor.Segment DividerSegment; - public readonly Mono.TextEditor.Segment EndSegment; + public TextSegment StartSegment; + public TextSegment DividerSegment; + public TextSegment EndSegment; - public Conflict (Mono.TextEditor.Segment mySegment, Mono.TextEditor.Segment theirSegment, Mono.TextEditor.Segment startSegment, Mono.TextEditor.Segment dividerSegment, Mono.TextEditor.Segment endSegment) + public Conflict (TextSegment mySegment, TextSegment theirSegment, TextSegment startSegment, TextSegment dividerSegment, TextSegment endSegment) { this.MySegment = mySegment; this.TheirSegment = theirSegment; @@ -235,21 +235,16 @@ namespace MonoDevelop.VersionControl.Views UpdateDiff (); } - IEnumerable<ISegment> GetAllConflictingSegments () - { - foreach (var conflict in currentConflicts) { - yield return conflict.StartSegment; - yield return conflict.DividerSegment; - yield return conflict.EndSegment; - yield return conflict.MySegment; - yield return conflict.TheirSegment; - } - } - void UpdateConflictsOnTextReplace (object sender, DocumentChangeEventArgs e) { this.UpdateDiff (); - Mono.TextEditor.TextDocument.UpdateSegments (GetAllConflictingSegments (), e); + foreach (var conflict in currentConflicts) { + conflict.StartSegment = conflict.StartSegment.AdjustSegment (e); + conflict.DividerSegment = conflict.DividerSegment.AdjustSegment (e); + conflict.EndSegment = conflict.EndSegment.AdjustSegment (e); + conflict.MySegment = conflict.MySegment.AdjustSegment (e); + conflict.TheirSegment = conflict.TheirSegment.AdjustSegment (e); + } } } }
\ No newline at end of file |