Skip to content

Commit f452fb1

Browse files
authored
Merge fc4b6eb into 841925b
2 parents 841925b + fc4b6eb commit f452fb1

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

source/NVDAObjects/JAB/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,17 @@
9797
}
9898

9999

100+
re_simpleXmlTag = re.compile(r"(\<[^>]+\>)+")
100101

101-
re_simpleXmlTag=re.compile(r"\<[^>]+\>")
102102

103+
def _subHtmlTag(match):
104+
startIndex, endIndex = match.span()
105+
return "" if startIndex == 0 or match.string[startIndex - 1].isspace() \
106+
or endIndex == len(match.string) or match.string[endIndex].isspace() else " "
103107

104108
def _processHtml(text):
105109
""" Strips HTML tags from text if it is HTML """
106-
return re_simpleXmlTag.sub(" ", text) if text.startswith("<html>") else text
110+
return re_simpleXmlTag.sub(_subHtmlTag, text) if text.startswith("<html>") else text
107111

108112

109113
class JABTextInfo(textInfos.offsets.OffsetsTextInfo):
@@ -320,6 +324,9 @@ def _get_states(self):
320324
for state in stateStrings:
321325
if state in JABStatesToNVDAStates:
322326
stateSet.add(JABStatesToNVDAStates[state])
327+
if self.role is controlTypes.Role.TOGGLEBUTTON and controlTypes.State.CHECKED in stateSet:
328+
stateSet.discard(controlTypes.State.CHECKED)
329+
stateSet.add(controlTypes.State.PRESSED)
323330
if "editable" not in stateStrings and self._JABAccContextInfo.accessibleText:
324331
stateSet.add(controlTypes.State.READONLY)
325332
if "visible" not in stateStrings:
@@ -333,7 +340,12 @@ def _get_states(self):
333340
return stateSet
334341

335342
def _get_value(self):
336-
if self.role not in [controlTypes.Role.CHECKBOX,controlTypes.Role.MENU,controlTypes.Role.MENUITEM,controlTypes.Role.RADIOBUTTON,controlTypes.Role.BUTTON] and self._JABAccContextInfo.accessibleValue and not self._JABAccContextInfo.accessibleText:
343+
if self.role not in [
344+
controlTypes.Role.TOGGLEBUTTON, controlTypes.Role.CHECKBOX,
345+
controlTypes.Role.MENU, controlTypes.Role.MENUITEM,
346+
controlTypes.Role.RADIOBUTTON, controlTypes.Role.BUTTON] \
347+
and self._JABAccContextInfo.accessibleValue \
348+
and not self._JABAccContextInfo.accessibleText:
337349
return self.jabContext.getCurrentAccessibleValueFromContext()
338350

339351
def _get_description(self):
@@ -372,7 +384,8 @@ def _get_positionInfo(self):
372384
return info
373385

374386
parent=self.parent
375-
if isinstance(parent,JAB) and self.role in (controlTypes.Role.TREEVIEWITEM,controlTypes.Role.LISTITEM):
387+
if isinstance(parent, JAB) and self.role in (
388+
controlTypes.Role.TREEVIEWITEM, controlTypes.Role.LISTITEM, controlTypes.Role.TAB):
376389
index=self._JABAccContextInfo.indexInParent+1
377390
childCount=parent._JABAccContextInfo.childrenCount
378391
info['indexInGroup']=index
@@ -389,7 +402,7 @@ def _get_activeChild(self):
389402
def _get_parent(self):
390403
if not hasattr(self,'_parent'):
391404
jabContext=self.jabContext.getAccessibleParentFromContext()
392-
if jabContext:
405+
if jabContext and self.indexInParent is not None:
393406
self._parent=JAB(jabContext=jabContext)
394407
else:
395408
self._parent=super(JAB,self).parent

tests/unit/test_javaAccessBridge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test_regexNotModified(self):
2525
self.assertEqual(regexStr, JAB._processHtml(regexStr))
2626

2727
def test_htmlStringHasTagsRemoved(self):
28-
htmlStr = "<html><body><p>Some <b>bold</b> text.</p></body></html>"
29-
expected = " Some bold text. "
28+
htmlStr = "<html><body><p>Some <b>bold</b> <i>text</i>.</p></body></html>"
29+
expected = "Some bold text ."
3030
self.assertEqual(expected, JAB._processHtml(htmlStr))
3131

3232

0 commit comments

Comments
 (0)