Repository: nvaccess/nvda

Issue:
System focus does not move to edit field when "Automatic focus mode for caret movement" is enabled.
<!-- 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: Enable the option "Automatic focus mode for caret movement" in the browse mode settings of NVDA.
2: Go to a website with edit fields.
3: Use the arrow keys to go to an edit field.

### Actual behavior:
Focus mode is turned on, but system focus is not moved to the edit field. Because of this it is not possible to type in the edit field. To be able to type text anyway, you must switch to browse mode and then press enter or space. Then focus mode is turned on again and the system focus is moved to the edit field.

### Expected behavior:
When you get to an edit field with the arrow keys, NVDA switches to focus mode and the system focus moves to the edit field.

### System configuration
#### NVDA installed/portable/running from source:
Installed
#### NVDA version:
2020.3beta3
#### Windows version:
Windows 10 1909 (64-bit) build 18363.1082
#### Name and version of other software in use when reproducing the issue:
Microsoft Edge 85.0.564.51 and Firefox 80.0.1
#### 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.
In previous versions of NVDA this works as expected, the problem is caused by changes in NVDA2020.3.
#### If addons are disabled, is your problem still occuring?
Yes
#### Did you try to run the COM registry fixing tool in NVDA menu / tools?
No


Discussion:
I have similar problems with combo boxes.
This is a duplicate of #11654 @feerrenrut @michaelDCurran Are you planning to fix this for 2020.3? If not I'm afraid we should reconsider making focus focusable elements disabled by default as experience with it disabled and "Automatic focus mode for caret movements" enabled is sub optimal to put it politely. Also cc @jcsteh and @leonardder  who have worked on focus focusable elements in the past.
Hi.

I can confirm this issue. One would argue that this is a specific use case, and that, rather than disabling it by default altogether, this bug should be looked into further, as it is present when it's enabled.
Yes, I've been having odd things happening on web sites since using the new 
beta 3 as well, but not actually managed to figure out a one thing that 
creates the issue, its as if you need to visit some parts twice to make them 
work right.
 Sorry cannot be more specific.
 Brian

bglists@blueyonder.co.uk
Sent via blueyonder.
Please address personal E-mail to:-
briang1@blueyonder.co.uk, putting 'Brian Gaff'
in the display name field.
Newsgroup monitored: alt.comp.blind-users
----- Original Message ----- 
From: "Artin Dekker" <notifications@github.com>
To: "nvaccess/nvda" <nvda@noreply.github.com>
Cc: "Subscribed" <subscribed@noreply.github.com>
Sent: Friday, September 25, 2020 8:01 AM
Subject: Re: [nvaccess/nvda] System focus does not move to edit field when 
"Automatic focus mode for caret movement" is enabled. (#11663)


>I have similar problems with combo boxes.
>
> -- 
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on GitHub:
> https://github.com/nvaccess/nvda/issues/11663#issuecomment-698759959 


Is there a step sequence that is always reproducible and that isn't 
hidden behind a login?

You can use page of this issue as an example:
1. In the browse mode  settings ensure that "Automatic focus mode for caret movement" is enabled and "Automatically set system focus to focusable elements" is  disabled.
2. Move to the comment edit field with letter e.
3. move with arrows to the field until focus mode activates automatically.
4. Try to type into the field.

Yes, I can reproduce this now. Investigating the cause.
@fisher729 @artindk Could you please confirm that this issue is no longer reproducible with [this build](https://ci.appveyor.com/api/buildjobs/33iveog3w1298s22/artifacts/output%2Fnvda_snapshot_pr11665-21047%2C854b0137.exe)?
I have tested several website with the build and it now seems to work as expected.
Thanks, with latest snapshot sites works correctly. I was pleased to be involved in improving the future version of NVDA.

Resolving patch:
diff --git a/source/browseMode.py b/source/browseMode.py
--- a/source/browseMode.py
+++ b/source/browseMode.py
@@ -1,8 +1,7 @@
-#browseMode.py
-#A part of NonVisual Desktop Access (NVDA)
-#Copyright (C) 2007-2018 NV Access Limited, Babbage B.V.
-#This file is covered by the GNU General Public License.
-#See the file COPYING for more details.
+# A part of NonVisual Desktop Access (NVDA)
+# Copyright (C) 2007-2020 NV Access Limited, Babbage B.V., James Teh, Leonard de Ruijter
+# This file is covered by the GNU General Public License.
+# See the file COPYING for more details.
 
 import itertools
 import collections
@@ -1323,18 +1322,24 @@ def _set_selection(self, info, reason=controlTypes.REASON_CARET):
 			if not obj:
 				log.debugWarning("Invalid NVDAObjectAtStart")
 				return
-			followBrowseModeFocus= config.conf["virtualBuffers"]["autoFocusFocusableElements"]
 			if obj==self.rootNVDAObject:
 				return
-			if followBrowseModeFocus:
-				if focusObj and not eventHandler.isPendingEvents("gainFocus") and focusObj!=self.rootNVDAObject and focusObj != api.getFocusObject() and self._shouldSetFocusToObj(focusObj):
-					focusObj.setFocus()
 			obj.scrollIntoView()
 			if self.programmaticScrollMayFireEvent:
 				self._lastProgrammaticScrollTime = time.time()
-		self.passThrough=self.shouldPassThrough(focusObj,reason=reason)
-		# Queue the reporting of pass through mode so that it will be spoken after the actual content.
-		queueHandler.queueFunction(queueHandler.eventQueue, reportPassThrough, self)
+		if focusObj:
+			self.passThrough = self.shouldPassThrough(focusObj, reason=reason)
+			if (
+				not eventHandler.isPendingEvents("gainFocus")
+				and focusObj != self.rootNVDAObject
+				and focusObj != api.getFocusObject()
+				and self._shouldSetFocusToObj(focusObj)
+			):
+				followBrowseModeFocus = config.conf["virtualBuffers"]["autoFocusFocusableElements"]
+				if followBrowseModeFocus or self.passThrough:
+					focusObj.setFocus()
+			# Queue the reporting of pass through mode so that it will be spoken after the actual content.
+			queueHandler.queueFunction(queueHandler.eventQueue, reportPassThrough, self)
 
 	def _shouldSetFocusToObj(self, obj):
 		"""Determine whether an object should receive focus.


Test patch: