Skip to content

Commit

Permalink
Chromium: disable caret at end of line detection as Chromium does not…
Browse files Browse the repository at this point in the history
… yet implement what we need, and it is costly for no gain.
  • Loading branch information
michaelDCurran committed Aug 27, 2024
1 parent 69b9ce4 commit 5373ae4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
21 changes: 21 additions & 0 deletions source/NVDAObjects/IAccessible/chromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -188,3 +207,5 @@ def findExtraOverlayClasses(obj, clsList):
clsList,
documentClass=Document,
)
if ia2Web.Editor in clsList:
clsList.insert(0, Editor)
18 changes: 0 additions & 18 deletions source/appModules/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,23 @@

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


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,
Expand Down

0 comments on commit 5373ae4

Please sign in to comment.