Skip to content

Handle error when creating TextInfo from alleged caret object#17212

Merged
SaschaCowley merged 2 commits into
nvaccess:masterfrom
michaelweghorn:michaelweghorn/fix_pinyin_ime_exception
Sep 25, 2024
Merged

Handle error when creating TextInfo from alleged caret object#17212
SaschaCowley merged 2 commits into
nvaccess:masterfrom
michaelweghorn:michaelweghorn/fix_pinyin_ime_exception

Conversation

@michaelweghorn

@michaelweghorn michaelweghorn commented Sep 24, 2024

Copy link
Copy Markdown
Contributor

Link to issue number:

Partially fixes #17198

Summary of the issue:

When using the Microsoft Pinyin Input Method for Chinese and enabling the Pinyin compatibility option to use the previous version, typing in LibreOffice (e.g. Writer or Calc) while an IME popup was showing triggered an error, with this traceback:

ERROR - eventHandler.executeEvent (10:45:49.378) - MainThread (7416):
error executing event: caret on <NVDAObjects.Dynamic_SymphonyParagraphSymphonyTextEditableTextWithAutoSelectDetectionIAccessible object at 0x0B918DF0> with extra args of {}
Traceback (most recent call last):
  File "eventHandler.py", line 353, in executeEvent
    _EventExecuter(eventName, obj, kwargs)
  File "eventHandler.py", line 119, in __init__
    self.next()
  File "eventHandler.py", line 128, in next
    return func(*args, **self.kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "compoundDocuments.py", line 548, in event_caret
    caret = self.makeTextInfo(textInfos.POSITION_CARET)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "documentBase.py", line 76, in makeTextInfo
    return self.TextInfo(self, position)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "compoundDocuments.py", line 287, in __init__
    self._start = self._end = self._startObj.makeTextInfo(position)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "documentBase.py", line 76, in makeTextInfo
    return self.TextInfo(self, position)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "textInfos\offsets.py", line 505, in __init__
    self._startOffset = self._endOffset = self._getCaretOffset()
                                          ^^^^^^^^^^^^^^^^^^^^^^
  File "textInfos\offsets.py", line 267, in _getCaretOffset
    raise NotImplementedError
NotImplementedError

This was caused by the attempt to create a text info for an object from the IME popup that's not actually part of the LibreOffice accessibility tree, and that doesn't provide any means to get the current caret position.

This is due to CompoundDocument._get_caretObject returning the last queued focus object, which isn't necessarily the object that the caret change event has actually been sent for, and might be an object that doesn't support reporting of a caret positiion altogether.

Description of user facing changes

When using the Microsoft Pinyin Input Method for Chinese and enabling the Pinyin compatibility option to use the previous version, typing in LibreOffice Writer (and potentially other applications) while an IME popup is showing no longer triggers an error.

Description of development approach

Handle the NotImplementedError error that may get thrown in CompoundDocument.event_caret.

Testing strategy:

  1. set up the Microsoft Pinyin Input Method for Chinese and enable the Pinyin compatibility option as described in issue During testing of LibreOffice 24.8.1.2 with NVDA alpha-34118, an error occurs when filling out the form using Microsoft Pinyin #17198
  2. start LibreOffice Writer
  3. start typing, e.g. just type "e" multiple times
  4. Notice the IME popup showing without triggering an error

Known issues with pull request:

None, but note that other than Writer, the case of using Calc still shows more issues, s. #17198 (comment) , i.e. this is only a partial fix for the use case described in that ticket.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@coderabbitai summary

 ### Link to issue number:

Fixes nvaccess#17198

 ### Summary of the issue:

When using the Microsoft Pinyin Input Method for Chinese and enabling
the Pinyin compatibility option to use the previous version, typing in
LibreOffice (e.g. Writer or Calc) while an IME popup was showing
triggered an error, with this traceback:

    ERROR - eventHandler.executeEvent (10:45:49.378) - MainThread (7416):
    error executing event: caret on <NVDAObjects.Dynamic_SymphonyParagraphSymphonyTextEditableTextWithAutoSelectDetectionIAccessible object at 0x0B918DF0> with extra args of {}
    Traceback (most recent call last):
      File "eventHandler.py", line 353, in executeEvent
        _EventExecuter(eventName, obj, kwargs)
      File "eventHandler.py", line 119, in __init__
        self.next()
      File "eventHandler.py", line 128, in next
        return func(*args, **self.kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "compoundDocuments.py", line 548, in event_caret
        caret = self.makeTextInfo(textInfos.POSITION_CARET)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "documentBase.py", line 76, in makeTextInfo
        return self.TextInfo(self, position)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "compoundDocuments.py", line 287, in __init__
        self._start = self._end = self._startObj.makeTextInfo(position)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "documentBase.py", line 76, in makeTextInfo
        return self.TextInfo(self, position)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "textInfos\offsets.py", line 505, in __init__
        self._startOffset = self._endOffset = self._getCaretOffset()
                                              ^^^^^^^^^^^^^^^^^^^^^^
      File "textInfos\offsets.py", line 267, in _getCaretOffset
        raise NotImplementedError
    NotImplementedError

This was caused by the attempt to create a text info
for an object from the IME popup that's not actually part
of the LibreOffice accessibility tree, and that doesn't provide
any means to get the current caret position.

This is due to `CompoundDocument._get_caretObject`
returning the last queued focus object, which isn't necessarily
the object that the caret change event has actually been sent for,
and might be an object that doesn't support reporting of a caret positiion
altogether.

 ### Description of user facing changes

When using the Microsoft Pinyin Input Method for Chinese and enabling
the Pinyin compatibility option to use the previous version, typing in
LibreOffice (and potentially other applications) while an IME popup is
showing no longer triggers an error.

 ### Description of development approach

Handle the NotImplementedError error that may get thrown
in CompoundDocument.event_caret.

 ### Testing strategy:

1. set up the Microsoft Pinyin Input Method for Chinese and enable
   the Pinyin compatibility option as described in issue nvaccess#17198
2. start LibreOffice Writer
3. start typing, e.g. just type "e" multiple times
4. Notice the IME popup showing without triggering
   an error

 ### Known issues with pull request:

None.

 ### Code Review Checklist:

- [x] Documentation:
  - Change log entry
  - User Documentation
  - Developer / Technical Documentation
  - Context sensitive help for GUI changes
- [x] Testing:
  - Unit tests
  - System (end to end) tests
  - Manual testing
- [x] UX of all users considered:
  - Speech
  - Braille
  - Low Vision
  - Different web browsers
  - Localization in other languages / culture than English
- [x] API is compatible with existing add-ons.
- [x] Security precautions taken.
@michaelweghorn

Copy link
Copy Markdown
Contributor Author

Quoting from #17198 (comment) :

I was first working on a fix in the LibreOffice-specific app module, and am attaching the local commit I had for reference:
0001-soffice-Don-t-create-TextInfo-for-unrelated-focus-ob.patch.txt

However, thinking about it some more, my current understanding is that this is conceptually not a LibreOffice-specific problem, therefore I've implemented a different approach and submitted that in the PR.

If my understanding is wrong and/or this should better be fixed elsewhere, please let me know.

@michaelweghorn michaelweghorn marked this pull request as ready for review September 24, 2024 10:32
@michaelweghorn michaelweghorn requested a review from a team as a code owner September 24, 2024 10:32
* Explicitly mention Writer, there are still more errors with Calc
  with the old Microsoft Pinyin version,
  see nvaccess#17198 (comment)
* Move entry to the "Bug Fixes" section. This is not a new feature.
@SaschaCowley SaschaCowley merged commit eacde5e into nvaccess:master Sep 25, 2024
@github-actions github-actions Bot added this to the 2025.1 milestone Sep 25, 2024
@michaelweghorn michaelweghorn deleted the michaelweghorn/fix_pinyin_ime_exception branch September 25, 2024 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

During testing of LibreOffice 24.8.1.2 with NVDA alpha-34118, an error occurs when filling out the form using Microsoft Pinyin

2 participants