IJPL-208474 Don't post accessible caret events when the document changes

A large number of accessible caret events in a row after document changes, for example, when pasting a few hundred lines of code, causes a runtime crash on macOS.
These events were added more as a workaround for certain cases like deleting text or adding indentation, which don't generate caret events by themselves but still need to be tracked by the accessibility zoom. However, in recent macOS versions, it looks like they are not needed anymore and the zoom properly handles ACCESSIBLE_TEXT changed events in these cases.


(cherry picked from commit 26312cc99af1e6a8f226576be1c044a321f594bd)

IJ-CR-176485

GitOrigin-RevId: 32bf1644008e7e067eeb6f34b4f4cd490754c1c8
This commit is contained in:
Dmitry Drobotov
2025-09-19 14:02:55 +02:00
committed by intellij-monorepo-bot
parent 9935f1c971
commit e20812f272
2 changed files with 10 additions and 5 deletions

View File

@@ -1185,9 +1185,6 @@ public final class EditorComponentImpl extends JTextComponent implements Scrolla
final Integer pos = event.getOffset();
if (ApplicationManager.getApplication().isDispatchThread()) {
firePropertyChange(ACCESSIBLE_TEXT_PROPERTY, null, pos);
// Fire caret changed event when the document changes because caretPositionChanged might not be called in some cases
// (e.g., when deleting text or adding/removing tab indentation, see CaretListener#caretPositionChanged).
firePropertyChange(ACCESSIBLE_CARET_PROPERTY, null, pos);
if (SystemInfo.isMac) {
// For MacOSX we also need to fire a JTextComponent event to anyone listening
// to our Document, since *that* rather than the accessible property
@@ -1197,7 +1194,6 @@ public final class EditorComponentImpl extends JTextComponent implements Scrolla
} else {
ApplicationManager.getApplication().invokeLater(() -> {
firePropertyChange(ACCESSIBLE_TEXT_PROPERTY, null, pos);
firePropertyChange(ACCESSIBLE_CARET_PROPERTY, null, pos);
fireJTextComponentDocumentChange(event);
});
}

View File

@@ -5,6 +5,15 @@ import com.intellij.openapi.fileTypes.PlainTextFileType
import javax.accessibility.AccessibleContext
class AccessibleCaretTest : AbstractEditorTest() {
fun `test accessible caret property change on left and right arrow press`() {
val accessibleCaret = initEditor(3)
left()
assertEquals(2, accessibleCaret.position)
right()
assertEquals(3, accessibleCaret.position)
}
fun `test accessible caret property change on backspace`() {
val accessibleCaret = initEditor(3)
@@ -31,7 +40,7 @@ class AccessibleCaretTest : AbstractEditorTest() {
initText("12345")
editor.caretModel.moveToOffset(caretPosition.position)
editor.contentComponent.accessibleContext.addPropertyChangeListener { evt ->
if (evt.propertyName == AccessibleContext.ACCESSIBLE_CARET_PROPERTY) {
if (evt.propertyName == AccessibleContext.ACCESSIBLE_CARET_PROPERTY || evt.propertyName == AccessibleContext.ACCESSIBLE_TEXT_PROPERTY) {
caretPosition.position = evt.newValue as Int
}
}