Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable caret at end of line detection in Chromium #17067

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
seanbudd marked this conversation as resolved.
Show resolved Hide resolved


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