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. (#17067)

More broadly fixes #17039

Summary of the issue:
In PR #16745, code was added to detect the caret at end of lines in Mozilla-compatible edit areas, so as to not report the next line when on the final insertion point of the line before.
Although this works great in Firefox and other Gecko-based apps, it does not work at all in Chromium due to Chromium not correctly
implementing IAccessibleText::textAtOffset with IA2_OFFSET_CARET.
More importantly, this is a very costly check in VS code, which has a noticeable performance hit when arrowing up and down large files (issue #17039), for no gain.
PR #17051 successfully fixed the performance hit in VS code by disabling caret at end of line detection just for VS Code. But it was pointed out that there are several VS Code variants including VS Code.dev which require this also.

Description of user facing changes
NVDA is no longer as sluggish when arrowing up and down large fles in VS code and otherChromium-based applications.

Description of development approach
Remoe the VSCodeditor and VSCodeEditorTextInfo classes from the VS ode appModule introduced in pr VS Code is no longer as sluggish when arrowing up and down through large files #17051.
Add Editor and EditorTextInfo classes to NVDAObjects.IAccessible.chromium which are used in Chromium where ever NVDAObject.IAccessible.ia2Web.Editor is used. These classes disable caret at end of line detection for any chromium edit area.
  • Loading branch information
michaelDCurran authored Aug 28, 2024
1 parent 91220d0 commit 992453c
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 992453c

Please sign in to comment.