From c93d6d57b28696f6e124bad432d4f7ef414d1de4 Mon Sep 17 00:00:00 2001
From: Alysson Souza <alysson87@gmail.com>
Date: Fri, 7 Mar 2008 05:34:01 +0000
Subject: [PATCH] Fixed #688, related to "Replace All" always being case
 sensitive

Originally committed to SVN as r1952.
---
 aegisub/dialog_search_replace.cpp | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/aegisub/dialog_search_replace.cpp b/aegisub/dialog_search_replace.cpp
index 7410778fb..cdbaf7737 100644
--- a/aegisub/dialog_search_replace.cpp
+++ b/aegisub/dialog_search_replace.cpp
@@ -477,12 +477,24 @@ void SearchReplaceEngine::ReplaceAll() {
 				count += reps;
 			}
 		}
-
 		// Normal replace
 		else {
-			if (Text->Contains(LookFor)) {
-				count += Text->Replace(LookFor,ReplaceWith);
-				replaced = true;
+			if (!Search.matchCase) {
+				wxString Left, Right;
+				int pos;
+				while(Text->Lower().Contains(LookFor.Lower())) {
+					pos = Text->Lower().Find(LookFor.Lower());
+					Left = pos ? Text->Left(pos) : _T("");
+					Right = Text->Mid(pos+LookFor.Len());
+					*Text = Left + ReplaceWith + Right;
+					count++;
+				}
+			}
+			else {
+				if(Text->Contains(LookFor)) {
+					count += Text->Replace(LookFor, ReplaceWith);
+					replaced = true;
+				}
 			}
 		}
 
-- 
GitLab