diff options
author | Jed Barber <jjbarber@y7mail.com> | 2017-05-24 00:11:29 +1000 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2017-05-24 00:11:29 +1000 |
commit | e13794b5de63e7fb085dff6e495130e541a3a19e (patch) | |
tree | 6e05fd61efd65a91bff7b101c725171277e8d4fb | |
parent | 404ef8737ec179ef006e769893e20a20ae6088d9 (diff) |
Cleaned up Change_Vector code
-rw-r--r-- | src/change_vectors.adb | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/src/change_vectors.adb b/src/change_vectors.adb index 65a1f99..79456c7 100644 --- a/src/change_vectors.adb +++ b/src/change_vectors.adb @@ -12,29 +12,69 @@ with Ada.Text_IO; package body Change_Vectors is + function Continues_Insert + (Orig, Cont : in Change) + return Boolean is + begin + return + Orig.Action = FLTK.Text_Buffers.Insert and then + Integer (Orig.Place) + Orig.Length = Integer (Cont.Place) and then + Cont.Length = 1 and then + (Element (Orig.Text, Orig.Length) /= ' ' or else Element (Cont.Text, 1) = ' '); + end Continues_Insert; + + + + + function Continues_Delete + (Orig, Cont : in Change) + return Boolean is + begin + return + Orig.Action = FLTK.Text_Buffers.Delete and then + Orig.Place = Cont.Place and then + Cont.Length = 1; + end Continues_Delete; + + + + + function Continues_Backspace + (Orig, Cont : in Change) + return Boolean is + begin + return + Orig.Action = FLTK.Text_Buffers.Delete and then + Orig.Place = Cont.Place + 1 and then + Cont.Length = 1; + end Continues_Backspace; + + + + 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 + if This.Near > 0 and then + Continues_Insert (This.List.Element (This.Near), Item) + then This.List.Update_Element (This.Near, App'Access); else This.Near := This.Near + 1; @@ -42,11 +82,12 @@ package body Change_Vectors is 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 + if Continues_Delete (This.List.Element (This.Near), Item) + 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 + elsif + Continues_Backspace (This.List.Element (This.Near), Item) + then This.List.Update_Element (This.Near, Pre'Access); else This.Near := This.Near + 1; |