Repository: nvaccess/nvda

Issue:
Braille back translation with Polish Grade 1 table less correct than before with latest  Alpha.
Regression from #12742 cc @leonardder 
### Steps to reproduce:
1. With a braille display connected switch input table to Polish grade 1.
2. Start notepad and using braille keyboard enter: 3456-1-12-46-14
3. Inspect the entered text.
### Actual behavior:
NVDA translates this input to 1bC

### Expected behavior:
The preferred behavior would be to get 12C since number sign (dots 3456) has to be explicitly cancelled in the Polish notation by specifying small letter indicator (dot 6) or capital letter indicator (dots 46). This however never worked as expected so at least getting the pre #12742 behavior i.e. number sign is not cancelled and NVDA reports 'unsupported input' when entering cap letter indicator would be nice.
As it is each number need to be preceded by number sign which is pretty incorrect.

### System configuration
#### NVDA installed/portable/running from source:
Tried with both portable installed and portable
#### NVDA version:
NVDA version alpha-23598,a4524704

#### Windows version:
N'/A
#### Name and version of other software in use when reproducing the issue:
Notepad
#### 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.
Versions before #12742 never worked fully as expected but the results were much better.
#### If add-ons are disabled, is your problem still occurring?
Yes
#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Not tried but likely  not relevant.


The log with Braille input enabled in advanced is as follows (its a little bit messy since FS braille display driver logs a lot  of details irrelevant here at debug level)

```
IO - speech.speech.speak (13:30:52.429) - MainThread (3288):
Speaking ['Log fragment start position marked, press again to copy to clipboard']
IO - braille.BrailleBuffer.update (13:30:52.429) - MainThread (3288):
Braille regions text: ['Log fragment start position marked, press again to copy to clipboard']
IO - braille.BrailleHandler.update (13:30:52.429) - MainThread (3288):
Braille window dots: 46 123 135 1245 - 124 1235 1 1245 134 15 1345 2345 - 234 2345 1 1235 2345 - 1234 135 234 24 2345 24 135 1345 - 134 1 1235 13 15 145 2 - 1234 1235 15
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:52.429) - braille._BgThread (4124):
Got packet of type b'\x01' with args: b'\x00' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:54.849) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b' ' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:54.859) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'8' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:54.869) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'<' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:54.979) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b',' b'\x00' b'\x00'
IO - inputCore.InputManager.executeGesture (13:30:54.979) - braille._BgThread (4124):
Input: br(freedomScientific.Focus40):dot3+dot4+dot5+dot6
DEBUG - brailleInput.BrailleInputHandler.input (13:30:54.989) - MainThread (3288):
Braille input received: 0X3c
DEBUG - brailleInput.BrailleInputHandler.input (13:30:54.989) - MainThread (3288):
Inserting 0X3c at position 0 in bufferBraille
DEBUG - brailleInput.BrailleInputHandler.input (13:30:54.989) - MainThread (3288):
useContractedForCurrentFocus = False, input is end of word = False
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:54.989) - MainThread (3288):
bufferText after translation = , newText = 
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:54.989) - MainThread (3288):
Translate returning False
IO - braille.BrailleBuffer.update (13:30:54.989) - MainThread (3288):
Braille regions text: ['Bez tytułu — Notatnik ', 'mln edt ', '⣏⠼ ⣹ ']
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:54.989) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x04' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:55.019) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x00' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:55.319) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x01' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:55.449) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x00' b'\x00' b'\x00'
IO - inputCore.InputManager.executeGesture (13:30:55.449) - braille._BgThread (4124):
Input: br(freedomScientific.Focus40):dot1
DEBUG - brailleInput.BrailleInputHandler.input (13:30:55.459) - MainThread (3288):
Braille input received: 0X01
DEBUG - brailleInput.BrailleInputHandler.input (13:30:55.459) - MainThread (3288):
Inserting 0X01 at position 1 in bufferBraille
DEBUG - brailleInput.BrailleInputHandler.input (13:30:55.459) - MainThread (3288):
useContractedForCurrentFocus = False, input is end of word = False
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:55.459) - MainThread (3288):
bufferText after translation = 1, newText = 1
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:55.459) - MainThread (3288):
currentModifiers = set(), currentFocusIsTextObj = True
DEBUG - brailleInput.BrailleInputHandler.sendChars (13:30:55.459) - MainThread (3288):
Sending characters: 1
IO - inputCore.InputManager.executeGesture (13:30:55.459) - winInputHook (4516):
Input: kb(desktop):1
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:55.459) - MainThread (3288):
Clearing previous word from buffer
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:55.459) - MainThread (3288):
Translate returning True
DEBUG - brailleInput.BrailleInputHandler.input (13:30:55.459) - MainThread (3288):
Added 1 to cellsWithText, now {1}
IO - braille.BrailleBuffer.update (13:30:55.469) - MainThread (3288):
Braille regions text: ['Bez tytułu — Notatnik ', 'mln edt ', '1 ']
IO - braille.BrailleHandler.update (13:30:55.469) - MainThread (3288):
Braille window dots: 3456 1 -
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:55.469) - braille._BgThread (4124):
Got packet of type b'\x01' with args: b'\x00' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:55.709) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x03' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:55.829) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x00' b'\x00' b'\x00'
IO - inputCore.InputManager.executeGesture (13:30:55.829) - braille._BgThread (4124):
Input: br(freedomScientific.Focus40):dot1+dot2
DEBUG - brailleInput.BrailleInputHandler.input (13:30:55.849) - MainThread (3288):
Braille input received: 0X03
DEBUG - brailleInput.BrailleInputHandler.input (13:30:55.849) - MainThread (3288):
Inserting 0X03 at position 0 in bufferBraille
DEBUG - brailleInput.BrailleInputHandler.input (13:30:55.849) - MainThread (3288):
useContractedForCurrentFocus = False, input is end of word = False
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:55.849) - MainThread (3288):
bufferText after translation = b, newText = b
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:55.849) - MainThread (3288):
currentModifiers = set(), currentFocusIsTextObj = True
DEBUG - brailleInput.BrailleInputHandler.sendChars (13:30:55.849) - MainThread (3288):
Sending characters: b
IO - inputCore.InputManager.executeGesture (13:30:55.849) - winInputHook (4516):
Input: kb(desktop):b
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:55.849) - MainThread (3288):
Clearing previous word from buffer
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:55.849) - MainThread (3288):
Translate returning True
DEBUG - brailleInput.BrailleInputHandler.input (13:30:55.849) - MainThread (3288):
Added 0 to cellsWithText, now {0}
IO - braille.BrailleBuffer.update (13:30:55.859) - MainThread (3288):
Braille regions text: ['Bez tytułu — Notatnik ', 'mln edt ', '1b ']
IO - braille.BrailleHandler.update (13:30:55.859) - MainThread (3288):
Braille window dots: 3456 1 12 -
IO - braille.BrailleHandler.update (13:30:55.859) - MainThread (3288):
Braille window dots: 3456 1 12 -
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:55.859) - braille._BgThread (4124):
Got packet of type b'\x01' with args: b'\x00' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:55.869) - braille._BgThread (4124):
Got packet of type b'\x01' with args: b'\x00' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:56.840) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b' ' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:56.880) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'(' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:56.980) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x00' b'\x00' b'\x00'
IO - inputCore.InputManager.executeGesture (13:30:56.980) - braille._BgThread (4124):
Input: br(freedomScientific.Focus40):dot4+dot6
DEBUG - brailleInput.BrailleInputHandler.input (13:30:57.000) - MainThread (3288):
Braille input received: 0X28
DEBUG - brailleInput.BrailleInputHandler.input (13:30:57.000) - MainThread (3288):
Inserting 0X28 at position 0 in bufferBraille
DEBUG - brailleInput.BrailleInputHandler.input (13:30:57.000) - MainThread (3288):
useContractedForCurrentFocus = False, input is end of word = False
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:57.000) - MainThread (3288):
bufferText after translation = , newText = 
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:57.000) - MainThread (3288):
Translate returning False
IO - braille.BrailleBuffer.update (13:30:57.000) - MainThread (3288):
Braille regions text: ['Bez tytułu — Notatnik ', 'mln edt ', '1b⣏⠨ ⣹ ']
IO - braille.BrailleHandler.update (13:30:57.000) - MainThread (3288):
Braille window dots: 3456 1 12 123478 46 - 145678 -
IO - braille.BrailleHandler.update (13:30:57.000) - MainThread (3288):
Braille window dots: 3456 1 12 123478 46 - 145678 -
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:57.000) - braille._BgThread (4124):
Got packet of type b'\x01' with args: b'\x00' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:57.000) - braille._BgThread (4124):
Got packet of type b'\x01' with args: b'\x00' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:57.410) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x08' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:57.420) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\t' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:57.530) - braille._BgThread (4124):
Got packet of type b'\x03' with args: b'\x00' b'\x00' b'\x00'
IO - inputCore.InputManager.executeGesture (13:30:57.530) - braille._BgThread (4124):
Input: br(freedomScientific.Focus40):dot1+dot4
DEBUG - brailleInput.BrailleInputHandler.input (13:30:57.550) - MainThread (3288):
Braille input received: 0X09
DEBUG - brailleInput.BrailleInputHandler.input (13:30:57.550) - MainThread (3288):
Inserting 0X09 at position 1 in bufferBraille
DEBUG - brailleInput.BrailleInputHandler.input (13:30:57.550) - MainThread (3288):
useContractedForCurrentFocus = False, input is end of word = False
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:57.550) - MainThread (3288):
bufferText after translation = C, newText = C
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:57.550) - MainThread (3288):
currentModifiers = set(), currentFocusIsTextObj = True
DEBUG - brailleInput.BrailleInputHandler.sendChars (13:30:57.550) - MainThread (3288):
Sending characters: C
IO - inputCore.InputManager.executeGesture (13:30:57.550) - winInputHook (4516):
Input: kb(desktop):C
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:57.550) - MainThread (3288):
Clearing previous word from buffer
DEBUG - brailleInput.BrailleInputHandler._translate (13:30:57.550) - MainThread (3288):
Translate returning True
DEBUG - brailleInput.BrailleInputHandler.input (13:30:57.550) - MainThread (3288):
Added 1 to cellsWithText, now {1}
IO - braille.BrailleBuffer.update (13:30:57.560) - MainThread (3288):
Braille regions text: ['Bez tytułu — Notatnik ', 'mln edt ', '1bC ']
IO - braille.BrailleHandler.update (13:30:57.560) - MainThread (3288):
Braille window dots: 3456 1 12 46 14 -
IO - braille.BrailleHandler.update (13:30:57.560) - MainThread (3288):
Braille window dots: 3456 1 12 46 14 -
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:57.560) - braille._BgThread (4124):
Got packet of type b'\x01' with args: b'\x00' b'\x00' b'\x00'
DEBUG - brailleDisplayDrivers.freedomScientific.BrailleDisplayDriver._onReceive (13:30:57.570) - braille._BgThread (4124):
Got packet of type b'\x01' with args: b'\x00' b'\x00' b'\x00'
IO - inputCore.InputManager.executeGesture (13:31:00.080) - winInputHook (4516):
Input: kb(desktop):shift+control+NVDA+f1

```



Discussion:
Ugh! This means that entering numbers in literary braille is severely broken now anyway.

I'll have a look later this week.

Resolving patch:
diff --git a/source/brailleInput.py b/source/brailleInput.py
--- a/source/brailleInput.py
+++ b/source/brailleInput.py
@@ -44,10 +44,6 @@
 UNICODE_BRAILLE_PROTECTED = u"⣿" # All dots down
 
 
-def _isDebugForBrailleInput():
-	return config.conf["debugLog"]["brailleInput"]
-
-
 class BrailleInputHandler(AutoPropertyObject):
 	"""Handles braille input.
 	"""
@@ -122,21 +118,7 @@ def _get_currentFocusIsTextObj(self):
 	useContractedForCurrentFocus: bool
 
 	def _get_useContractedForCurrentFocus(self):
-		return self._table.contracted and not self.inputKeysUsingEmulation
-
-	# Provided by auto property: L{_get_inputKeysUsingEmulation}
-	inputKeysUsingEmulation: bool
-
-	def _get_inputKeysUsingEmulation(self):
-		"""
-		Returns whether keyboard gesture emulation should be used to input keyboard keys.
-		If this is C{False}, L{sendChars} is used.
-		This should only apply when:
-			* No modifiers are pressed
-			* We are in a text field
-		"""
-		return not self.currentFocusIsTextObj or self.currentModifiers
-
+		return self._table.contracted and self.currentFocusIsTextObj and not self.currentModifiers
 
 	def _translate(self, endWord: bool) -> bool:
 		"""Translate buffered braille up to the cursor.
@@ -152,51 +134,39 @@ def _translate(self, endWord: bool) -> bool:
 		pos = self.untranslatedStart + self.untranslatedCursorPos
 		data = u"".join([chr(cell | LOUIS_DOTS_IO_START) for cell in self.bufferBraille[:pos]])
 		mode = louis.dotsIO | louis.noUndefinedDots
-		if self.inputKeysUsingEmulation and self._table.contracted:
+		if (not self.currentFocusIsTextObj or self.currentModifiers) and self._table.contracted:
 			mode |=  louis.partialTrans
 		self.bufferText = louis.backTranslate(
 			[os.path.join(brailleTables.TABLES_DIR, self._table.fileName),
 			"braille-patterns.cti"],
 			data, mode=mode)[0]
 		newText = self.bufferText[oldTextLen:]
-		if _isDebugForBrailleInput():
-			log.debug(f"bufferText after translation = {self.bufferText}, newText = {newText}")
 		if newText:
 			# New text was generated by the cells just entered.
 			if self.useContractedForCurrentFocus or self.currentModifiers:
 				# For contracted braille, an entire word is sent at once.
 				# Don't speak characters as this is sent.
 				# Also, suppress typed characters when emulating a command gesture.
-				if _isDebugForBrailleInput():
-					log.debug("Suppressing typed characters for contracted input")
 				speech._suppressSpeakTypedCharacters(len(newText))
 			else:
 				self._uncontSentTime = time.time()
 			self.untranslatedStart = pos
 			self.untranslatedCursorPos = 0
-			if _isDebugForBrailleInput():
-				log.debug(
-					f"currentModifiers = {self.currentModifiers}, currentFocusIsTextObj = {self.currentFocusIsTextObj}"
-				)
-			if self.inputKeysUsingEmulation:
+			if self.currentModifiers or not self.currentFocusIsTextObj:
 				if len(newText)>1:
 					# Emulation of multiple characters at once is unsupported
 					# Clear newText, so this function returns C{False} if not at end of word
-					if _isDebugForBrailleInput():
-						log.debug(f"Clearing newText, was {newText}")
 					newText = u""
 				else:
 					self.emulateKey(newText)
 			else:
 				self.sendChars(newText)
 
-		if endWord or (newText and (self.currentModifiers or not self.useContractedForCurrentFocus)):
+		if endWord or (newText and (not self.currentFocusIsTextObj or self.currentModifiers)):
 			# We only need to buffer one word.
 			# Clear the previous word (anything before the cursor) from the buffer.
-			if _isDebugForBrailleInput():
-				log.debug(f"Clearing previous word from buffer")
 			del self.bufferBraille[:pos]
-			self.bufferText = ""
+			self.bufferText = u""
 			self.cellsWithText.clear()
 			self.currentModifiers.clear()
 			self.untranslatedStart = 0
@@ -204,12 +174,8 @@ def _translate(self, endWord: bool) -> bool:
 
 		if newText or endWord:
 			self._updateUntranslated()
-			if _isDebugForBrailleInput():
-				log.debug("Translate returning True")
 			return True
 
-		if _isDebugForBrailleInput():
-			log.debug("Translate returning False")
 		return False
 
 	def _translateForReportContractedCell(self, pos):
@@ -271,12 +237,8 @@ def _reportUntranslated(self, pos):
 	def input(self, dots: int):
 		"""Handle one cell of braille input.
 		"""
-		if _isDebugForBrailleInput():
-			log.debug(f"Braille input received: 0X{dots:02x}")
 		# Insert the newly entered cell into the buffer at the cursor position.
 		pos = self.untranslatedStart + self.untranslatedCursorPos
-		if _isDebugForBrailleInput():
-			log.debug(f"Inserting 0X{dots:02x} at position {pos} in bufferBraille")
 		self.bufferBraille.insert(pos, dots)
 		self.untranslatedCursorPos += 1
 		# Space ends the word.
@@ -287,17 +249,10 @@ def input(self, dots: int):
 		# This is because later cells can change characters produced by previous cells.
 		# For example, in English grade 2, "tg" produces just "tg",
 		# but "tgr" produces "together".
-		if _isDebugForBrailleInput():
-			log.debug(
-				f"useContractedForCurrentFocus = {self.useContractedForCurrentFocus}, "
-				f"input is end of word = {endWord}"
-			)
 		if not self.useContractedForCurrentFocus or endWord:
 			if self._translate(endWord):
 				if not endWord:
 					self.cellsWithText.add(pos)
-					if _isDebugForBrailleInput():
-						log.debug(f"Added {pos} to cellsWithText, now {self.cellsWithText}")
 			elif self.bufferText and not self.useContractedForCurrentFocus:
 				# Translators: Reported when translation didn't succeed due to unsupported input.
 				speech.speakMessage(_("Unsupported input"))
@@ -419,8 +374,6 @@ def emulateKey(self, key: str, withModifiers: bool = True):
 		@param withModifiers: Whether this key emulation should include the modifiers that are held virtually.
 			Note that this method does not take care of clearing L{self.currentModifiers}.
 		"""
-		if _isDebugForBrailleInput():
-			log.debug(f"Emulating {key}")
 		if withModifiers:
 			# The emulated key should be the last item in the identifier string.
 			keys = list(self.currentModifiers)
@@ -431,19 +384,13 @@ def emulateKey(self, key: str, withModifiers: bool = True):
 		try:
 			inputCore.manager.emulateGesture(keyboardHandler.KeyboardInputGesture.fromName(gesture))
 		except:
-			if _isDebugForBrailleInput():
-				log.debugWarning(
-					f"Unable to emulate {gesture}, falling back to sending unicode characters",
-					exc_info=True
-				)
+			log.debugWarning("Unable to emulate %r, falling back to sending unicode characters"%gesture, exc_info=True)
 			self.sendChars(key)
 
 	def sendChars(self, chars: str):
 		"""Sends the provided unicode characters to the system.
 		@param chars: The characters to send to the system.
 		"""
-		if _isDebugForBrailleInput():
-			log.debug(f"Sending characters: {chars}")
 		inputs = []
 		chars = ''.join(
 			ch if ord(ch) <= 0xffff else ''.join(
diff --git a/source/config/configSpec.py b/source/config/configSpec.py
--- a/source/config/configSpec.py
+++ b/source/config/configSpec.py
@@ -262,7 +262,6 @@
 	speechManager = boolean(default=false)
 	synthDriver = boolean(default=false)
 	nvwave = boolean(default=false)
-	brailleInput = boolean(default=false)
 
 [uwpOcr]
 	language = string(default="")
diff --git a/source/gui/settingsDialogs.py b/source/gui/settingsDialogs.py
--- a/source/gui/settingsDialogs.py
+++ b/source/gui/settingsDialogs.py
@@ -2818,7 +2818,6 @@ def __init__(self, parent):
 			"speechManager",
 			"synthDriver",
 			"nvwave",
-			"brailleInput",
 		]
 		# Translators: This is the label for a list in the
 		#  Advanced settings panel


Test patch: