Repository: nvaccess/nvda

Issue:
Bug with NVDA+shift+f3
<!-- Please read the text in this edit field before filling it in.
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/wiki/Github-issue-template-explanation-and-examples
Please also note that the NVDA project has a Citizen and Contributor Code of Conduct which can be found at https://github.com/nvaccess/nvda/blob/master/CODE_OF_CONDUCT.MD. NV Access expects that all contributors and other community members read and abide by the rules set out in this document while participating or contributing to this project. This includes creating or commenting on issues and pull requests. 
-->

### Steps to reproduce:
1. Make sure you didn't type anything in the NVDA+f edit field.
2. Go to a document that you need text found for
3. Go to the end of the document
4. Press NVDA+shift+f3
5. Type the word
6. NVDA will say text not found. But when you press NVDA+shift+f3 again NVDA will be able to find the word you're looking for.
### Actual behavior:
When steps 4 and 5 are complete NVDA doesn't try to find previous result, it tries to go to the next result which fails because the currsor is at the end of the document.
### Expected behavior:
When steps 4 and 5 are applied NVDA should be able to find last occurrance
### System configuration
#### NVDA installed/portable/running from source:
Installed
#### NVDA version:
2020.3
#### Windows version:
2004
#### Name and version of other software in use when reproducing the issue:

#### Other information about your system:

### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
2020.2, issue was there
#### If addons are disabled, is your problem still occuring?

#### Did you try to run the COM registry fixing tool in NVDA menu / tools?

Bug with NVDA+shift+f3
<!-- Please read the text in this edit field before filling it in.
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/wiki/Github-issue-template-explanation-and-examples
Please also note that the NVDA project has a Citizen and Contributor Code of Conduct which can be found at https://github.com/nvaccess/nvda/blob/master/CODE_OF_CONDUCT.MD. NV Access expects that all contributors and other community members read and abide by the rules set out in this document while participating or contributing to this project. This includes creating or commenting on issues and pull requests. 
-->

### Steps to reproduce:
1. Make sure you didn't type anything in the NVDA+f edit field.
2. Go to a document that you need text found for
3. Go to the end of the document
4. Press NVDA+shift+f3
5. Type the word
6. NVDA will say text not found. But when you press NVDA+shift+f3 again NVDA will be able to find the word you're looking for.
### Actual behavior:
When steps 4 and 5 are complete NVDA doesn't try to find previous result, it tries to go to the next result which fails because the currsor is at the end of the document.
### Expected behavior:
When steps 4 and 5 are applied NVDA should be able to find last occurrance
### System configuration
#### NVDA installed/portable/running from source:
Installed
#### NVDA version:
2020.3
#### Windows version:
2004
#### Name and version of other software in use when reproducing the issue:

#### Other information about your system:

### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
2020.2, issue was there
#### If addons are disabled, is your problem still occuring?

#### Did you try to run the COM registry fixing tool in NVDA menu / tools?



Discussion:

Resolving patch:
diff --git a/source/cursorManager.py b/source/cursorManager.py
--- a/source/cursorManager.py
+++ b/source/cursorManager.py
@@ -33,11 +33,12 @@ class FindDialog(wx.Dialog):
 	"""A dialog used to specify text to find in a cursor manager.
 	"""
 
-	def __init__(self, parent, cursorManager, text, caseSensitivity):
+	def __init__(self, parent, cursorManager, text, caseSensitivity, reverse=False):
 		# Translators: Title of a dialog to find text.
 		super(FindDialog, self).__init__(parent, wx.ID_ANY, _("Find"))
 		# Have a copy of the active cursor manager, as this is needed later for finding text.
 		self.activeCursorManager = cursorManager
+		self.reverse = reverse
 		mainSizer = wx.BoxSizer(wx.VERTICAL)
 		sHelper = guiHelper.BoxSizerHelper(self, orientation=wx.VERTICAL)
 		# Translators: Dialog text for NvDA's find command.
@@ -61,7 +62,13 @@ def onOk(self, evt):
 		caseSensitive = self.caseSensitiveCheckBox.GetValue()
 		# We must use core.callLater rather than wx.CallLater to ensure that the callback runs within NVDA's core pump.
 		# If it didn't, and it directly or indirectly called wx.Yield, it could start executing NVDA's core pump from within the yield, causing recursion.
-		core.callLater(100, self.activeCursorManager.doFindText, text, caseSensitive=caseSensitive)
+		core.callLater(
+			100,
+			self.activeCursorManager.doFindText,
+			text,
+			caseSensitive=caseSensitive,
+			reverse=self.reverse
+		)
 		self.Destroy()
 
 	def onCancel(self, evt):
@@ -164,11 +171,11 @@ def doFindText(self, text, reverse=False, caseSensitive=False, willSayAllResume=
 		CursorManager._lastFindText=text
 		CursorManager._lastCaseSensitivity=caseSensitive
 
-	def script_find(self,gesture):
+	def script_find(self, gesture, reverse=False):
 		# #8566: We need this to be a modal dialog, but it mustn't block this script.
 		def run():
 			gui.mainFrame.prePopup()
-			d = FindDialog(gui.mainFrame, self, self._lastFindText, self._lastCaseSensitivity)
+			d = FindDialog(gui.mainFrame, self, self._lastFindText, self._lastCaseSensitivity, reverse)
 			d.ShowModal()
 			gui.mainFrame.postPopup()
 		wx.CallAfter(run)
@@ -203,7 +210,7 @@ def script_findNext(self,gesture):
 	)
 	def script_findPrevious(self,gesture):
 		if not self._lastFindText:
-			self.script_find(gesture)
+			self.script_find(gesture, reverse=True)
 			return
 		self.doFindText(
 			self._lastFindText,


Test patch: