Skip to content

Commit

Permalink
In braille, extraneous spaces are no longer displayed between or afte…
Browse files Browse the repository at this point in the history
…r indicators for controls and formatting.

Fixes #5043.
  • Loading branch information
jcsteh committed Jul 14, 2015
2 parents 15c8bd2 + f975175 commit 4a7a8bf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
69 changes: 43 additions & 26 deletions source/braille.py
Expand Up @@ -743,17 +743,14 @@ def _getTypeformFromFormatField(self, field):
typeform |= louis.underline
return typeform

def _addFieldText(self, text):
# Separate this field text from the rest of the text.
def _addFieldText(self, text, contentPos):
if self.rawText:
text = " %s " % text
else:
text += " "
# Separate this field text from the rest of the text.
text = " " + text
self.rawText += text
textLen = len(text)
self.rawTextTypeforms.extend((louis.plain_text,) * textLen)
# Map this field text to the start of the field's content.
self._rawToContentPos.extend((self._currentContentPos,) * textLen)
self._rawToContentPos.extend((contentPos,) * textLen)

def _addTextWithFields(self, info, formatConfig, isSelection=False):
shouldMoveCursorToFirstContent = not isSelection and self.cursorPos is not None
Expand All @@ -763,6 +760,12 @@ def _addTextWithFields(self, info, formatConfig, isSelection=False):
if isinstance(command, basestring):
if not command:
continue
if self._endsWithField:
# The last item added was a field,
# so add a space before the content.
self.rawText += " "
self.rawTextTypeforms.append(louis.plain_text)
self._rawToContentPos.append(self._currentContentPos)
if isSelection and self._selectionStart is None:
# This is where the content begins.
self._selectionStart = len(self.rawText)
Expand All @@ -772,13 +775,15 @@ def _addTextWithFields(self, info, formatConfig, isSelection=False):
self.cursorPos = len(self.rawText)
shouldMoveCursorToFirstContent = False
self.rawText += command
self.rawTextTypeforms.extend((typeform,) * len(command))
endPos = self._currentContentPos + len(command)
commandLen = len(command)
self.rawTextTypeforms.extend((typeform,) * commandLen)
endPos = self._currentContentPos + commandLen
self._rawToContentPos.extend(xrange(self._currentContentPos, endPos))
self._currentContentPos = endPos
if isSelection:
# The last time this is set will be the end of the content.
self._selectionEnd = len(self.rawText)
self._endsWithField = False
elif isinstance(command, textInfos.FieldCommand):
cmd = command.command
field = command.field
Expand All @@ -787,13 +792,14 @@ def _addTextWithFields(self, info, formatConfig, isSelection=False):
text = getFormatFieldBraille(field)
if not text:
continue
self._addFieldText(text)
# Map this field text to the start of the field's content.
self._addFieldText(text, self._currentContentPos)
elif cmd == "controlStart":
# Place this field on a stack so we can access it for controlEnd.
if self._skipFieldsNotAtStartOfNode and not field.get("_startOfNode"):
text = None
else:
text = info.getControlFieldBraille(field, ctrlFields, True, formatConfig)
# Place this field on a stack so we can access it for controlEnd.
ctrlFields.append(field)
if not text:
continue
Expand All @@ -804,23 +810,21 @@ def _addTextWithFields(self, info, formatConfig, isSelection=False):
if fieldStart > 0:
# There'll be a space before the field text.
fieldStart += 1
if shouldMoveCursorToFirstContent:
shouldMoveCursorToFirstContent = False
self.cursorPos = fieldStart
elif isSelection and self._selectionStart is None:
if isSelection and self._selectionStart is None:
self._selectionStart = fieldStart
self._addFieldText(text)
elif shouldMoveCursorToFirstContent:
self.cursorPos = fieldStart
shouldMoveCursorToFirstContent = False
# Map this field text to the start of the field's content.
self._addFieldText(text, self._currentContentPos)
elif cmd == "controlEnd":
field = ctrlFields.pop()
text = info.getControlFieldBraille(field, ctrlFields, False, formatConfig)
if not text:
continue
# Separate this field text from the rest of the text.
self.rawText += " %s " % text
textLen = len(text)
self.rawTextTypeforms.extend((louis.plain_text,) * textLen)
# Map this field text to the end of the field's content.
self._rawToContentPos.extend((self._currentContentPos - 1,) * textLen)
self._addFieldText(text, self._currentContentPos - 1)
self._endsWithField = True
if isSelection and self._selectionStart is None:
# There is no selection. This is a cursor.
self.cursorPos = len(self.rawText)
Expand Down Expand Up @@ -857,6 +861,7 @@ def update(self):
self._currentContentPos = 0
self._selectionStart = self._selectionEnd = None
self._skipFieldsNotAtStartOfNode = False
self._endsWithField = False

# Not all text APIs support offsets, so we can't always get the offset of the selection relative to the start of the reading unit.
# Therefore, grab the reading unit in three parts.
Expand All @@ -871,12 +876,24 @@ def update(self):
chunk.setEndPoint(readingInfo, "endToEnd")
chunk.setEndPoint(sel, "startToEnd")
self._addTextWithFields(chunk, formatConfig)
# Strip line ending characters, but add a space in case the cursor is at the end of the reading unit.
self.rawText = self.rawText.rstrip("\r\n\0\v\f") + " "
self._rawToContentPos.append(self._currentContentPos)
# Strip line ending characters.
self.rawText = self.rawText.rstrip("\r\n\0\v\f")
rawTextLen = len(self.rawText)
del self.rawTextTypeforms[rawTextLen - 1:]
self.rawTextTypeforms.append(louis.plain_text)
if rawTextLen < len(self._rawToContentPos):
# The stripped text is shorter than the original.
self._currentContentPos = self._rawToContentPos[rawTextLen]
del self.rawTextTypeforms[rawTextLen:]
# Trimming _rawToContentPos doesn't matter,
# because we'll only ever ask for indexes valid in rawText.
#del self._rawToContentPos[rawTextLen:]
if rawTextLen == 0 or not self._endsWithField:
# There is no text left after stripping line ending characters,
# or the last item added can be navigated with a cursor.
# Add a space in case the cursor is at the end of the reading unit.
self.rawText += " "
rawTextLen += 1
self.rawTextTypeforms.append(louis.plain_text)
self._rawToContentPos.append(self._currentContentPos)
if self.cursorPos is not None and self.cursorPos >= rawTextLen:
self.cursorPos = rawTextLen - 1

Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.t2t
Expand Up @@ -22,6 +22,7 @@
- Typed text is no longer garbled when using certain applications such as Microsoft Outlook with a braille display. (#2953)
- In browse mode in Internet Explorer and other MSHTML controls, the correct content is now reported when an element appears or changes and is immediately focused. (#5040)
- In browse mode in Microsoft Word, single letter navigation now updates the braille display and the review cursor as expected. (#4968)
- In braille, extraneous spaces are no longer displayed between or after indicators for controls and formatting. (#5043)


= 2015.2 =
Expand Down

0 comments on commit 4a7a8bf

Please sign in to comment.