Skip to content

Commit d7c3f94

Browse files
authored
Merge 9d2e583 into 841925b
2 parents 841925b + 9d2e583 commit d7c3f94

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

source/NVDAObjects/JAB/__init__.py

Lines changed: 28 additions & 6 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: re.match) -> str:
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

104-
def _processHtml(text):
108+
def _processHtml(text: str) -> str:
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,15 @@ 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 (
344+
self.role not in [
345+
controlTypes.Role.TOGGLEBUTTON, controlTypes.Role.CHECKBOX,
346+
controlTypes.Role.MENU, controlTypes.Role.MENUITEM,
347+
controlTypes.Role.RADIOBUTTON, controlTypes.Role.BUTTON
348+
]
349+
and self._JABAccContextInfo.accessibleValue
350+
and not self._JABAccContextInfo.accessibleText
351+
):
337352
return self.jabContext.getCurrentAccessibleValueFromContext()
338353

339354
def _get_description(self):
@@ -372,7 +387,14 @@ def _get_positionInfo(self):
372387
return info
373388

374389
parent=self.parent
375-
if isinstance(parent,JAB) and self.role in (controlTypes.Role.TREEVIEWITEM,controlTypes.Role.LISTITEM):
390+
if (
391+
isinstance(parent, JAB)
392+
and self.role in (
393+
controlTypes.Role.TREEVIEWITEM,
394+
controlTypes.Role.LISTITEM,
395+
controlTypes.Role.TAB
396+
)
397+
):
376398
index=self._JABAccContextInfo.indexInParent+1
377399
childCount=parent._JABAccContextInfo.childrenCount
378400
info['indexInGroup']=index
@@ -389,7 +411,7 @@ def _get_activeChild(self):
389411
def _get_parent(self):
390412
if not hasattr(self,'_parent'):
391413
jabContext=self.jabContext.getAccessibleParentFromContext()
392-
if jabContext:
414+
if jabContext and self.indexInParent is not None:
393415
self._parent=JAB(jabContext=jabContext)
394416
else:
395417
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)