blob: 65a1f99269324279ff96c096e348ab861eec5865 (
plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
with FLTK.Text_Buffers;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
use type FLTK.Text_Buffers.Modification;
use type FLTK.Text_Buffers.Position;
with Ada.Text_IO;
package body Change_Vectors is
procedure Push
(This : in out Change_Vector;
Item : in Change)
is
procedure App (Ch : in out Change) is
begin
Ch.Length := Ch.Length + 1;
Append (Ch.Text, Item.Text);
end App;
procedure Pre (Ch : in out Change) is
begin
Ch.Length := Ch.Length + 1;
Ch.Text := Item.Text & Ch.Text;
Ch.Place := Ch.Place - 1;
end Pre;
begin
if Item.Action = FLTK.Text_Buffers.Insert then
if This.Near > 0 and then
This.List.Element (This.Near).Action = FLTK.Text_Buffers.Insert and then
Integer (This.List.Element (This.Near).Place) + This.List.Element (This.Near).Length = Integer (Item.Place) and then
Item.Length = 1 and then
(Element (This.List.Element (This.Near).Text, This.List.Element (This.Near).Length) /= ' ' or else
Element (Item.Text, (1)) = ' ') then
This.List.Update_Element (This.Near, App'Access);
else
This.Near := This.Near + 1;
This.List.Insert (This.Near, Item);
end if;
elsif Item.Action = FLTK.Text_Buffers.Delete then
if This.Near > 0 then
if This.List.Element (This.Near).Action = FLTK.Text_Buffers.Delete and then
This.List.Element (This.Near).Place = Item.Place and then Item.Length = 1 then
This.List.Update_Element (This.Near, App'Access);
elsif This.List.Element (This.Near).Action = FLTK.Text_Buffers.Delete and then
This.List.Element (This.Near).Place = Item.Place + 1 and then Item.Length = 1 then
This.List.Update_Element (This.Near, Pre'Access);
else
This.Near := This.Near + 1;
This.List.Insert (This.Near, Item);
end if;
end if;
end if;
This.Far := This.Near;
while Integer (This.List.Length) > This.Far loop
This.List.Delete_Last;
end loop;
end Push;
function Pop
(This : in out Change_Vector)
return Boolean is
begin
if This.Near > 0 then
This.Near := This.Near - 1;
return True;
else
return False;
end if;
end Pop;
procedure Pop
(This : in out Change_Vector) is
begin
if This.Near > 0 then
This.Near := This.Near - 1;
end if;
end Pop;
function Peek
(This : in Change_Vector;
Item : out Change)
return Boolean is
begin
if This.Near > 0 then
Item := This.List.Element (This.Near);
return True;
else
return False;
end if;
end Peek;
procedure Peek
(This : in Change_Vector;
Item : out Change) is
begin
if This.Near > 0 then
Item := This.List.Element (This.Near);
end if;
end Peek;
function Re_Push
(This : in out Change_Vector)
return Boolean is
begin
if This.Near < This.Far then
This.Near := This.Near + 1;
return True;
else
return False;
end if;
end Re_Push;
procedure Re_Push
(This : in out Change_Vector) is
begin
if This.Near < This.Far then
This.Near := This.Near + 1;
end if;
end Re_Push;
function At_Start
(This : in Change_Vector)
return Boolean is
begin
return This.Near = 0;
end At_Start;
function At_End
(This : in Change_Vector)
return Boolean is
begin
return This.Near >= This.Far;
end At_End;
end Change_Vectors;
|