def test_setEndpoint(self): obj = BasicTextProvider(text="abcdef") ti1 = obj.makeTextInfo(Offsets(0, 2)) ti2 = obj.makeTextInfo(Offsets(3, 5)) ti1.end = ti2.end self.assertEqual((ti1._startOffset, ti1._endOffset), (0, 5)) ti1.start = ti2.start self.assertEqual((ti1._startOffset, ti1._endOffset), (3, 5)) ti1.end = ti2.start self.assertEqual((ti1._startOffset, ti1._endOffset), (3, 3)) ti1.start = ti2.end self.assertEqual((ti1._startOffset, ti1._endOffset), (5, 5))
def test_mixedSurrogatePairsNonSurrogatesAndSingleSurrogatesForward(self): """ Tests surrogate pairs, non surrogates as well as single surrogate characters (i.e. incomplete pairs) """ obj = BasicTextProvider(text=u"a\ud83e\ud83e\udd26\udd26b") ti = obj.makeTextInfo(Offsets(0, 0)) ti.expand(textInfos.UNIT_CHARACTER) # Range at a self.assertEqual(ti.offsets, (0, 1)) # One offset ti.move(textInfos.UNIT_CHARACTER, 1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 🠀 self.assertEqual( ti.offsets, (1, 2)) # Leading surrogate without a trailing surrogate ti.move(textInfos.UNIT_CHARACTER, 1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 🤦 self.assertEqual(ti.offsets, (2, 4)) # Two offsets ti.move(textInfos.UNIT_CHARACTER, 1) ti.expand(textInfos.UNIT_CHARACTER) # Range at self.assertEqual( ti.offsets, (4, 5)) # Trailing surrogate without a leading surrogate. ti.move(textInfos.UNIT_CHARACTER, 1) ti.expand(textInfos.UNIT_CHARACTER) # Range at c self.assertEqual(ti.offsets, (5, 6)) # One offset
def test_TextInfoEndpoint_equal(self): obj = BasicTextProvider(text="abcdef") ti = obj.makeTextInfo(Offsets(1, 1)) self.assertTrue(ti.start == ti.end) self.assertFalse(ti.start != ti.end) self.assertFalse(ti.start < ti.end) self.assertTrue(ti.start <= ti.end) self.assertTrue(ti.start >= ti.end) self.assertFalse(ti.start > ti.end)
def test_mixedSurrogatePairsAndNonSurrogatesBackward(self): obj = BasicTextProvider(text=u"a\ud83e\udd26b") # a🤦b ti = obj.makeTextInfo(Offsets(3, 3)) ti.expand(textInfos.UNIT_CHARACTER) # Range at c self.assertEqual(ti.offsets, (3, 4)) # One offset ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 🤦 self.assertEqual(ti.offsets, (1, 3)) # Two offsets ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at a self.assertEqual(ti.offsets, (0, 1)) # One offset
def test_nonSurrogateBackward(self): obj = BasicTextProvider(text="abc") ti = obj.makeTextInfo(Offsets(2, 2)) ti.expand(textInfos.UNIT_CHARACTER) # Range at c self.assertEqual(ti.offsets, (2, 3)) # One offset ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at b self.assertEqual(ti.offsets, (1, 2)) # One offset ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at a self.assertEqual(ti.offsets, (0, 1)) # One offset
def test_surrogatePairsBackward(self): obj = BasicTextProvider(text=u"\U0001f926\U0001f60a\U0001f44d") # 🤦😊👍 ti = obj.makeTextInfo(Offsets(5, 5)) ti.expand(textInfos.UNIT_CHARACTER) # Range at 👍 self.assertEqual(ti.offsets, (4, 6)) # Two offsets ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 😊 self.assertEqual(ti.offsets, (2, 4)) # Two offsets ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 🤦 self.assertEqual(ti.offsets, (0, 2)) # Two offsets
def moveToBookmark(position): obj = api.getFocusObject() treeInterceptor = obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor ) and not treeInterceptor.passThrough: obj = treeInterceptor bookmark = Offsets(position, position) info = obj.makeTextInfo(bookmark) obj._set_selection(info) speech.cancelSpeech() info.move(textInfos.UNIT_LINE, 1, endPoint="end") speech.speakTextInfo(info, reason=controlTypes.OutputReason.CARET)
def test_surrogatePairsForward(self): obj = BasicTextProvider( text=u"\ud83e\udd26\ud83d\ude0a\ud83d\udc4d") # 🤦😊👍 ti = obj.makeTextInfo(Offsets(0, 0)) ti.expand(textInfos.UNIT_CHARACTER) # Range at 🤦 self.assertEqual(ti.offsets, (0, 2)) # Two offsets ti.move(textInfos.UNIT_CHARACTER, 1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 😊 self.assertEqual(ti.offsets, (2, 4)) # Two offsets ti.move(textInfos.UNIT_CHARACTER, 1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 👍 self.assertEqual(ti.offsets, (4, 6)) # Two offsets
def test_TextInfoEndpoint_largerAndSmaller(self): obj = BasicTextProvider(text="abcdef") ti = obj.makeTextInfo(Offsets(0, 2)) smaller = ti.start larger = ti.end self.assertTrue(smaller < larger) self.assertFalse(larger < smaller) self.assertTrue(smaller <= larger) self.assertFalse(larger <= smaller) self.assertFalse(smaller >= larger) self.assertTrue(larger >= smaller) self.assertFalse(smaller > larger) self.assertTrue(larger > smaller) self.assertTrue(smaller != larger) self.assertTrue(larger != smaller)
def test_mixedSurrogatePairsNonSurrogatesAndSingleSurrogatesBackward(self): obj = BasicTextProvider(text=u"a\ud83e\U0001f926\udd26b") ti = obj.makeTextInfo(Offsets(5, 5)) ti.expand(textInfos.UNIT_CHARACTER) # Range at c self.assertEqual(ti.offsets, (5, 6)) # One offset ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at self.assertEqual(ti.offsets, (4, 5)) # Trailing surrogate without a leading surrogate. ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 🤦 self.assertEqual(ti.offsets, (2, 4)) # Two offsets ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at 🠀 self.assertEqual(ti.offsets, (1, 2)) # Leading surrogate without a trailing surrogate ti.move(textInfos.UNIT_CHARACTER, -1) ti.expand(textInfos.UNIT_CHARACTER) # Range at a self.assertEqual(ti.offsets, (0, 1)) # One offset
def script_selectPreviousBookmark(self, gesture): obj = api.getFocusObject() appName=appModuleHandler.getAppNameFromProcessID(obj.processID,True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj=treeInterceptor else: gesture.send() return bookmarks = getSavedBookmarks() if bookmarks == {}: ui.message( # Translators: message presented when trying to select a bookmark, but none is found. _("No bookmarks found")) return curPos = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark.startOffset prevPos = None for pos in sorted(bookmarks, reverse=True): if pos < curPos: prevPos = pos break if prevPos is not None: info = obj.makeTextInfo(Offsets(prevPos, prevPos)) info.updateSelection() review.handleCaretMove(info) if willSayAllResume(gesture): info.move(textInfos.UNIT_LINE,1,endPoint="end") #speech.speakTextInfo(info,reason=controlTypes.REASON_CARET) else: ui.message( # Translators: message presented when a bookmark is selected. _("Position: character %d") % prevPos) return ui.message( # Translators: message presented when the previous bookmark is not found. _("Previous bookmark not found"))
def makeTextInfo(self, position): if position in (textInfos.POSITION_CARET, textInfos.POSITION_SELECTION): start, end = self.selectionOffsets position = Offsets(start, end) return super(BasicTextProvider, self).makeTextInfo(position)