summaryrefslogtreecommitdiff
path: root/src/change_vectors.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/change_vectors.adb')
-rw-r--r--src/change_vectors.adb165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/change_vectors.adb b/src/change_vectors.adb
new file mode 100644
index 0000000..65a1f99
--- /dev/null
+++ b/src/change_vectors.adb
@@ -0,0 +1,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;
+