This repository was archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathumarkup.pas
130 lines (101 loc) · 3.01 KB
/
umarkup.pas
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
unit uMarkup;
{$mode objfpc}{$H+}
{$modeswitch advancedrecords}
interface
uses
Classes, SysUtils, SynEditMarkupHighAll, SynEditMiscClasses, uTokens, uContainers;
type
{ TMarkupRecord }
TMarkupRecord = record
StartPoint, EndPoint: TTokenPoint;
Message: string;
class operator =(i1, i2: TMarkupRecord): boolean;
end;
type TMarkupList = specialize TGenericList<TMarkupRecord>;
type
{ TMarkup }
TMarkup = class(TSynEditMarkupHighlightMatches)
private
UpdatingLine: integer;
ErrorMarks: TMarkupList;
public
constructor Create(ASynEdit : TSynEditBase);
procedure ClearMarks;
procedure AddMark(Start, Finish: TTokenPoint; const Message: string);
function GetTextForMarkup(const Location: TPoint): string;
procedure BeginUpdates;
function FinishedUpdates: boolean;
end;
function MarkupRecord(const StartPoint, EndPoint: TTokenPoint; const Message: string): TMarkupRecord;
implementation
function PointBetween(const Point: TPoint; const P1, P2: TTokenPoint): boolean;
begin
Result := (Point.Y >= P1.Y) and (Point.Y <= P2.Y) and
((Point.X >= P1.X) or (Point.Y > P1.Y)) and
((Point.X <= P2.X) or (Point.Y < P2.Y));
end;
function MarkupRecord(const StartPoint, EndPoint: TTokenPoint; const Message: string): TMarkupRecord;
begin
Result.StartPoint := StartPoint;
Result.EndPoint := EndPoint;
Result.Message := Message;
end;
{ TMarkupRecord }
class operator TMarkupRecord. = (i1, i2: TMarkupRecord): boolean;
begin
Result := i1 = i2;
end;
constructor TMarkup.Create(ASynEdit : TSynEditBase);
begin
inherited Create(ASynEdit);
UpdatingLine := -1;
ErrorMarks := TMarkupList.Create;
end;
procedure TMarkup.ClearMarks;
begin
Matches.Count := 0;
end;
procedure TMarkup.AddMark(Start, Finish: TTokenPoint; const Message: string);
var StartPt, EndPt: TPoint;
begin
{ TODO : ? }
//if not Assigned(FMatches) then Exit;
StartPt := Point(Start.X, Start.Y + 1);
if Finish.X - Start.X = 0 then
Finish.X := Finish.X + 1;
EndPt := Point(Finish.X, Finish.Y + 1);
Matches.StartPoint[Matches.Count] := StartPt;
Matches.EndPoint[Matches.Count - 1]:= EndPt;
ErrorMarks.Add(MarkupRecord(Start, Finish, Message));
end;
function TMarkup.GetTextForMarkup(const Location: TPoint): string;
var Mark: TMarkupRecord;
Found: boolean;
m: string;
begin
Found := False;
m := '';
ErrorMarks.PrepareIterator;
while ErrorMarks.GetNextItem(Mark) and not Found do
begin
Found := PointBetween(Location, Mark.StartPoint, Mark.EndPoint);
if Found then m:= Mark.Message;
end;
Result := m;
end;
procedure TMarkup.BeginUpdates;
begin
ErrorMarks.Clear;
end;
function TMarkup.FinishedUpdates: boolean;
var Idx: integer;
begin
Result := False;
if UpdatingLine < 0 then Exit;
for Idx := UpdatingLine to Lines.Count - 1 do
begin
end;
InvalidateSynLines(0,Lines.Count - 1);
UpdatingLine := -1;
end;
end.