[gedit-plugins] Fix issues with find/replace in selections



commit 30ede3f5966a87b7cc3591dc3ea856855abf953a
Author: Jesse van den Kieboom <jesse icecrew nl>
Date:   Sun Apr 11 22:27:18 2010 +0200

    Fix issues with find/replace in selections

 plugins/commander/modules/find/finder.py |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/plugins/commander/modules/find/finder.py b/plugins/commander/modules/find/finder.py
index eb732b9..3abc16b 100644
--- a/plugins/commander/modules/find/finder.py
+++ b/plugins/commander/modules/find/finder.py
@@ -71,15 +71,19 @@ class Finder:
 		ret = self.do_find(bounds)
 		
 		# Check if we need to wrap around if nothing is found
-		startiter = buf.get_iter_at_mark(self.search_start_mark)
+		if self.search_start_mark:
+			startiter = buf.get_iter_at_mark(self.search_start_mark)
+		else:
+			startiter = None
+
 		startbound = buf.get_iter_at_mark(self.search_boundaries.start)
 	
-		if not ret and not self.from_start and not startiter.equal(startbound):
+		if not ret and not self.from_start and (startiter and not startiter.equal(startbound)):
 			self.from_start = True
 
 			# Try from beginning
 			bounds[0] = buf.get_start_iter()
-			bounds[1] = buf.get_iter_at_mark(self.search_start_mark)
+			bounds[1] = startiter
 			
 			# Make sure to just stop at the start of the previous
 			self.search_boundaries.end = self.search_start_mark
@@ -131,6 +135,9 @@ class Finder:
 			# end, and then continue to start from the beginning of the buffer if needed
 			bounds = list(buf.get_bounds())
 			self.search_start_mark = buf.create_mark(None, buf.get_iter_at_mark(buf.get_insert()), True)
+			selection = False
+		else:
+			selection = True
 		
 		bounds[0].order(bounds[1])
 
@@ -139,7 +146,10 @@ class Finder:
 		self.search_boundaries.end = self._create_or_move(Finder.FIND_ENDMARK, bounds[1], False)
 		
 		# Set the result marks so the next find will start at the correct location
-		piter = buf.get_iter_at_mark(buf.get_insert())
+		if selection:
+			piter = bounds[0]
+		else:
+			piter = buf.get_iter_at_mark(buf.get_insert())
 		
 		self.find_result.start = self._create_or_move(Finder.FIND_RESULT_STARTMARK, piter, True)
 		self.find_result.end = self._create_or_move(Finder.FIND_RESULT_ENDMARK, piter, False)
@@ -270,4 +280,4 @@ class Finder:
 			buf.end_user_action()
 
 		self.cancel()
-		yield commands.result.DONE
\ No newline at end of file
+		yield commands.result.DONE



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]