|
25 | 25 | import speech |
26 | 26 | import api |
27 | 27 | import braille |
| 28 | +import inputCore |
28 | 29 | import languageHandler |
29 | 30 | import vision |
30 | 31 |
|
@@ -318,6 +319,43 @@ def _get_locationText(self): |
318 | 319 | class SymphonyDocument(CompoundDocument): |
319 | 320 | TextInfo = SymphonyDocumentTextInfo |
320 | 321 |
|
| 322 | + # override base class implementation because that one assumes |
| 323 | + # that the text retrieved from the text info for the text unit |
| 324 | + # is the same as the text that actually gets removed, which at |
| 325 | + # least isn't true for Writer paragraphs when removing a word |
| 326 | + # followed by whitespace using Ctrl+Backspace |
| 327 | + def _backspaceScriptHelper(self, unit: str, gesture: inputCore.InputGesture): |
| 328 | + try: |
| 329 | + oldInfo = self.makeTextInfo(textInfos.POSITION_CARET) |
| 330 | + if not isinstance(oldInfo, SymphonyDocumentTextInfo): |
| 331 | + super()._backspaceScriptHelper(unit, gesture) |
| 332 | + return |
| 333 | + ia2TextObj = oldInfo._start.obj.IAccessibleTextObject |
| 334 | + oldCaretOffset = ia2TextObj.caretOffset |
| 335 | + oldText = ia2TextObj.text(0, ia2TextObj.nCharacters) |
| 336 | + except NotImplementedError: |
| 337 | + gesture.send() |
| 338 | + return |
| 339 | + |
| 340 | + gesture.send() |
| 341 | + |
| 342 | + newInfo = self.makeTextInfo(textInfos.POSITION_CARET) |
| 343 | + ia2TextObj = newInfo._start.obj.IAccessibleTextObject |
| 344 | + newCaretOffset = ia2TextObj.caretOffset |
| 345 | + newText = ia2TextObj.text(0, ia2TextObj.nCharacters) |
| 346 | + |
| 347 | + # double-check check that text between previous and current |
| 348 | + # caret position was deleted and announce it |
| 349 | + deletedText = oldText[newCaretOffset:oldCaretOffset] |
| 350 | + if newText == oldText[0:newCaretOffset] + oldText[oldCaretOffset:]: |
| 351 | + if len(deletedText) > 1: |
| 352 | + speech.speakMessage(deletedText) |
| 353 | + else: |
| 354 | + speech.speakSpelling(deletedText) |
| 355 | + self._caretScriptPostMovedHelper(None, gesture, newInfo) |
| 356 | + else: |
| 357 | + log.warning('Backspace did not remove text as expected.') |
| 358 | + |
321 | 359 |
|
322 | 360 | class AppModule(appModuleHandler.AppModule): |
323 | 361 |
|
|
0 commit comments