summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/adapad.adb35
-rw-r--r--to_do.txt2
2 files changed, 22 insertions, 15 deletions
diff --git a/src/adapad.adb b/src/adapad.adb
index 78b0684..fb34196 100644
--- a/src/adapad.adb
+++ b/src/adapad.adb
@@ -388,25 +388,32 @@ package body Adapad is
(Item, Replace_With : in String;
Match_Case, Replace_All : in Boolean)
is
- Current_Position, Found_At : Natural;
- Times_Replaced : Natural := 0;
+ use type FLTK.Dialogs.Choice;
+ User_Response : FLTK.Dialogs.Choice;
+ Found_At : Natural;
+ Current_Position, Times_Replaced : Natural := 0;
begin
Replace.Hide;
- if Replace_All then
- Editor.Set_Insert_Position (0);
- end if;
-
- loop
- Current_Position := Editor.Get_Insert_Position;
- exit when not Buffer.Search_Forward (Current_Position, Item, Found_At, Match_Case);
+ while Buffer.Search_Forward (Current_Position, Item, Found_At, Match_Case) loop
Buffer.Set_Selection (Found_At, Found_At + Item'Length);
- Buffer.Remove_Selected_Text;
- Buffer.Insert_Text (Found_At, Replace_With);
- Editor.Set_Insert_Position (Found_At + Replace_With'Length);
+ Editor.Set_Insert_Position (Found_At);
Editor.Show_Insert_Position;
- Times_Replaced := Times_Replaced + 1;
- exit when not Replace_All and Times_Replaced > 0;
+ if not Replace_All then
+ User_Response := FLTK.Dialogs.Three_Way_Choice
+ ("Replace?", "No", "Yes", "Cancel");
+ else
+ User_Response := FLTK.Dialogs.Second;
+ end if;
+ exit when User_Response = FLTK.Dialogs.Third;
+ if User_Response = FLTK.Dialogs.Second then
+ Buffer.Remove_Selected_Text;
+ Buffer.Insert_Text (Found_At, Replace_With);
+ Current_Position := Found_At + Replace_With'Length;
+ Times_Replaced := Times_Replaced + 1;
+ else
+ Current_Position := Found_At + Item'Length;
+ end if;
end loop;
if Times_Replaced > 0 then
diff --git a/to_do.txt b/to_do.txt
index e9934f4..9c8f205 100644
--- a/to_do.txt
+++ b/to_do.txt
@@ -3,7 +3,7 @@
To Do:
- change build to be dynamically linked
-- improve replace, undo/redo, jump to
+- improve undo/redo, jump to
- suppress unnecessary left/right scrollbar
- clean up menu widget code, adapad menu and callback code
- introduce maybe type to eliminate out parameters in search_forward/search_backward