-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditRangeProvider.cs
38 lines (33 loc) · 1.02 KB
/
EditRangeProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Windows.Media;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using DiffPatch;
namespace PatchReviewer
{
public class EditRangeProvider : LineRangeHighlighter, IReadOnlySectionProvider
{
public EditRangeProvider(TextEditor textEditor) : base(textEditor) {
Brush = new SolidColorBrush(Colors.Gray);
Brush.Freeze();
}
public bool CanInsert(int offset) {
return startAnchor == null || offset >= startAnchor.Offset && offset <= endAnchor.Offset;
}
public IEnumerable<ISegment> GetDeletableSegments(ISegment segment) {
if (startAnchor == null) {
yield return segment;
yield break;
}
if (segment.EndOffset <= startAnchor.Offset || segment.Offset >= endAnchor.Offset)
yield break;
var range = new LineRange {
start = Math.Max(segment.Offset, startAnchor.Offset),
end = Math.Min(segment.EndOffset, endAnchor.Offset)
};
yield return range.SimpleSegment();
}
}
}