diff --git a/source/NVDAObjects/IAccessible/chromium.py b/source/NVDAObjects/IAccessible/chromium.py index 8b868760958..32ee8dd014a 100644 --- a/source/NVDAObjects/IAccessible/chromium.py +++ b/source/NVDAObjects/IAccessible/chromium.py @@ -166,6 +166,25 @@ def _get_role(self) -> controlTypes.Role: return controlTypes.Role.FIGURE +class EditorTextInfo(ia2Web.MozillaCompoundTextInfo): + """The TextInfo for edit areas such as edit fields and documents in Chromium.""" + + def _isCaretAtEndOfLine(self, caretObj: IAccessible) -> bool: + # Detecting if the caret is at the end of the line in Chromium is not currently possible + # as Chromium's IAccessibleText::textAtOffset with IA2_OFFSET_CARET returns the first character of the next line, + # which is what we are trying to avoid in the first place. + # #17039: In some scenarios such as in large files in VS Code, + # this call is extreamly costly for no actual bennifit right now, + # so we are disabling it for Chromium. + return False + + +class Editor(ia2Web.Editor): + """The NVDAObject for edit areas such as edit fields and documents in Chromium.""" + + TextInfo = EditorTextInfo + + def findExtraOverlayClasses(obj, clsList): """Determine the most appropriate class(es) for Chromium objects. This works similarly to L{NVDAObjects.NVDAObject.findOverlayClasses} except that it never calls any other findOverlayClasses method. @@ -188,3 +207,5 @@ def findExtraOverlayClasses(obj, clsList): clsList, documentClass=Document, ) + if ia2Web.Editor in clsList: + clsList.insert(0, Editor) diff --git a/source/appModules/code.py b/source/appModules/code.py index 3d7d3f8b19f..facaeb60a1e 100644 --- a/source/appModules/code.py +++ b/source/appModules/code.py @@ -7,32 +7,16 @@ import appModuleHandler import controlTypes -from NVDAObjects.IAccessible.ia2Web import Editor from NVDAObjects.IAccessible.chromium import Document -from NVDAObjects.IAccessible.ia2TextMozilla import MozillaCompoundTextInfo from NVDAObjects import NVDAObject, NVDAObjectTextInfo -class VSCodeEditorTextInfo(MozillaCompoundTextInfo): - def _isCaretAtEndOfLine(self, caretObj) -> bool: - # #17039: IAccessibleText::textAtOffset with IA2_OFFSET_CARET is way too costly in VSCode. - # And doesn't actually work correctly in Chromium yet anyway. - # So it is best not to try detecting for now. - return False - - -class VSCodeEditor(Editor): - TextInfo = VSCodeEditorTextInfo - - class VSCodeDocument(Document): """The only content in the root document node of Visual Studio code is the application object. Creating a tree interceptor on this object causes a major slow down of Code. Therefore, forcefully block tree interceptor creation. """ - textInfo = VSCodeEditorTextInfo - _get_treeInterceptorClass = NVDAObject._get_treeInterceptorClass @@ -40,8 +24,6 @@ class AppModule(appModuleHandler.AppModule): def chooseNVDAObjectOverlayClasses(self, obj, clsList): if Document in clsList and obj.IA2Attributes.get("tag") == "#document": clsList.insert(0, VSCodeDocument) - elif Editor in clsList: - clsList.insert(0, VSCodeEditor) def event_NVDAObject_init(self, obj: NVDAObject): # This is a specific fix for Visual Studio Code,