ax: fix VoiceOver cursor sync and word double-read
Bug 1 (VO cursor not following Emacs cursor): - Remove FocusedUIElementChangedNotification on emacsView (was a no-op: VO re-queried the same element) - For Emacs-initiated char/word moves, keep natural next/previous direction instead of forcing discontiguous; SelectedTextChanged with direction=next advances VO browse cursor sequentially - Only force discontiguous for line-boundary crossings and large jumps Bug 2 (word double-read with punctuation): - Root cause was FocusedUIElementChanged causing VO re-anchor speech on top of the explicit word announcement - Removing FocusedUIElementChanged eliminates the duplicate speech - Add emacsInitiated parameter to postFocusedCursorNotification; omit AXTextSelectionGranularity for Emacs-initiated moves so VO does not auto-speak (only explicit announcements provide speech) - isWordMove now triggers on emacsInitiated flag (Emacs-initiated word moves always get explicit announcement)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
From c777281b5f05b463ec4bb8bdcb71bdcf400a10c6 Mon Sep 17 00:00:00 2001
|
||||
From 825b4ff19bbaab392aa11fcd3ce41bfef248eb7b Mon Sep 17 00:00:00 2001
|
||||
From: Martin Sukany <martin@sukany.cz>
|
||||
Date: Sat, 28 Feb 2026 14:46:25 +0100
|
||||
Subject: [PATCH 7/8] ns: announce overlay completion candidates for VoiceOver
|
||||
@@ -22,7 +22,7 @@ race where an AX query consumes the change before notification.
|
||||
2 files changed, 289 insertions(+), 42 deletions(-)
|
||||
|
||||
diff --git a/src/nsterm.h b/src/nsterm.h
|
||||
index 5746e9e..21a93bc 100644
|
||||
index 5746e9e9bd..21a93bc799 100644
|
||||
--- a/src/nsterm.h
|
||||
+++ b/src/nsterm.h
|
||||
@@ -510,6 +510,7 @@ typedef struct ns_ax_visible_run
|
||||
@@ -34,10 +34,10 @@ index 5746e9e..21a93bc 100644
|
||||
@property (nonatomic, assign) BOOL cachedMarkActive;
|
||||
@property (nonatomic, copy) NSString *cachedCompletionAnnouncement;
|
||||
diff --git a/src/nsterm.m b/src/nsterm.m
|
||||
index 426b029..8d44b5f 100644
|
||||
index 25e8aeff34..b3daec31f1 100644
|
||||
--- a/src/nsterm.m
|
||||
+++ b/src/nsterm.m
|
||||
@@ -7271,11 +7271,154 @@ Accessibility virtual elements (macOS / Cocoa only)
|
||||
@@ -7262,11 +7262,154 @@ Accessibility virtual elements (macOS / Cocoa only)
|
||||
|
||||
/* ---- Helper: extract buffer text for accessibility ---- */
|
||||
|
||||
@@ -193,7 +193,7 @@ index 426b029..8d44b5f 100644
|
||||
static NSString *
|
||||
ns_ax_buffer_text (struct window *w, ptrdiff_t *out_start,
|
||||
ns_ax_visible_run **out_runs, NSUInteger *out_nruns)
|
||||
@@ -7346,7 +7489,7 @@ Accessibility virtual elements (macOS / Cocoa only)
|
||||
@@ -7337,7 +7480,7 @@ Accessibility virtual elements (macOS / Cocoa only)
|
||||
|
||||
/* Extract this visible run's text. Use
|
||||
Fbuffer_substring_no_properties which correctly handles the
|
||||
@@ -202,7 +202,7 @@ index 426b029..8d44b5f 100644
|
||||
include garbage bytes when the run spans the gap position. */
|
||||
Lisp_Object lstr = Fbuffer_substring_no_properties (
|
||||
make_fixnum (pos), make_fixnum (run_end));
|
||||
@@ -7427,7 +7570,7 @@ Mode lines using icon fonts (e.g. nerd-font icons)
|
||||
@@ -7418,7 +7561,7 @@ Mode lines using icon fonts (e.g. nerd-font icons)
|
||||
return NSZeroRect;
|
||||
|
||||
/* charpos_start and charpos_len are already in buffer charpos
|
||||
@@ -211,7 +211,7 @@ index 426b029..8d44b5f 100644
|
||||
charposForAccessibilityIndex which handles invisible text. */
|
||||
ptrdiff_t cp_start = charpos_start;
|
||||
ptrdiff_t cp_end = cp_start + charpos_len;
|
||||
@@ -7906,6 +8049,7 @@ @implementation EmacsAccessibilityBuffer
|
||||
@@ -7893,6 +8036,7 @@ @implementation EmacsAccessibilityBuffer
|
||||
@synthesize cachedOverlayModiff;
|
||||
@synthesize cachedTextStart;
|
||||
@synthesize cachedModiff;
|
||||
@@ -219,7 +219,7 @@ index 426b029..8d44b5f 100644
|
||||
@synthesize cachedPoint;
|
||||
@synthesize cachedMarkActive;
|
||||
@synthesize cachedCompletionAnnouncement;
|
||||
@@ -8003,7 +8147,7 @@ - (void)ensureTextCache
|
||||
@@ -7990,7 +8134,7 @@ - (void)ensureTextCache
|
||||
NSTRACE ("EmacsAccessibilityBuffer ensureTextCache");
|
||||
/* This method is only called from the main thread (AX getters
|
||||
dispatch_sync to main first). Reads of cachedText/cachedTextModiff
|
||||
@@ -228,7 +228,7 @@ index 426b029..8d44b5f 100644
|
||||
write section at the end needs synchronization to protect
|
||||
against concurrent reads from AX server thread. */
|
||||
eassert ([NSThread isMainThread]);
|
||||
@@ -8015,25 +8159,16 @@ - (void)ensureTextCache
|
||||
@@ -8002,25 +8146,16 @@ - (void)ensureTextCache
|
||||
if (!b)
|
||||
return;
|
||||
|
||||
@@ -262,7 +262,7 @@ index 426b029..8d44b5f 100644
|
||||
&& cachedTextStart == BUF_BEGV (b)
|
||||
&& pt >= cachedTextStart
|
||||
&& (textLen == 0
|
||||
@@ -8049,7 +8184,7 @@ included in the cached AX text (it is handled separately via
|
||||
@@ -8036,7 +8171,7 @@ included in the cached AX text (it is handled separately via
|
||||
{
|
||||
[cachedText release];
|
||||
cachedText = [text retain];
|
||||
@@ -271,7 +271,7 @@ index 426b029..8d44b5f 100644
|
||||
cachedTextStart = start;
|
||||
|
||||
if (visibleRuns)
|
||||
@@ -8118,7 +8253,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
|
||||
@@ -8105,7 +8240,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
|
||||
/* Binary search: runs are sorted by charpos (ascending). Find the
|
||||
run whose [charpos, charpos+length) range contains the target,
|
||||
or the nearest run after an invisible gap. O(log n) instead of
|
||||
@@ -280,7 +280,7 @@ index 426b029..8d44b5f 100644
|
||||
NSUInteger lo = 0, hi = visibleRunCount;
|
||||
while (lo < hi)
|
||||
{
|
||||
@@ -8167,10 +8302,10 @@ by run length (visible window), not total buffer size. */
|
||||
@@ -8154,10 +8289,10 @@ by run length (visible window), not total buffer size. */
|
||||
|
||||
/* Convert accessibility string index to buffer charpos.
|
||||
Safe to call from any thread: uses only cachedText (NSString) and
|
||||
@@ -293,7 +293,7 @@ index 426b029..8d44b5f 100644
|
||||
@synchronized (self)
|
||||
{
|
||||
if (visibleRunCount == 0)
|
||||
@@ -8212,7 +8347,7 @@ the slow path (composed character sequence walk), which is
|
||||
@@ -8199,7 +8334,7 @@ the slow path (composed character sequence walk), which is
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
@@ -302,7 +302,7 @@ index 426b029..8d44b5f 100644
|
||||
if (lo > 0)
|
||||
{
|
||||
ns_ax_visible_run *last = &visibleRuns[visibleRunCount - 1];
|
||||
@@ -8234,7 +8369,7 @@ the slow path (composed character sequence walk), which is
|
||||
@@ -8221,7 +8356,7 @@ the slow path (composed character sequence walk), which is
|
||||
deadlocking the AX server thread. This is prevented by:
|
||||
|
||||
1. validWindow checks WINDOW_LIVE_P and BUFFERP before every
|
||||
@@ -311,7 +311,7 @@ index 426b029..8d44b5f 100644
|
||||
2. All dispatch_sync blocks run on the main thread where no
|
||||
concurrent Lisp code can modify state between checks.
|
||||
3. block_input prevents timer events and process output from
|
||||
@@ -8588,6 +8723,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
|
||||
@@ -8567,6 +8702,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
|
||||
return [self lineForAXIndex:point_idx];
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ index 426b029..8d44b5f 100644
|
||||
- (NSRange)accessibilityRangeForLine:(NSInteger)line
|
||||
{
|
||||
if (![NSThread isMainThread])
|
||||
@@ -8810,7 +8989,7 @@ - (NSRect)accessibilityFrame
|
||||
@@ -8789,7 +8968,7 @@ - (NSRect)accessibilityFrame
|
||||
|
||||
|
||||
/* ===================================================================
|
||||
@@ -371,7 +371,7 @@ index 426b029..8d44b5f 100644
|
||||
|
||||
These methods notify VoiceOver of text and selection changes.
|
||||
Called from the redisplay cycle (postAccessibilityUpdates).
|
||||
@@ -8825,7 +9004,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
|
||||
@@ -8804,7 +8983,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
|
||||
if (point > self.cachedPoint
|
||||
&& point - self.cachedPoint == 1)
|
||||
{
|
||||
@@ -380,7 +380,7 @@ index 426b029..8d44b5f 100644
|
||||
[self invalidateTextCache];
|
||||
[self ensureTextCache];
|
||||
if (cachedText)
|
||||
@@ -8844,7 +9023,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
|
||||
@@ -8823,7 +9002,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
|
||||
/* Update cachedPoint here so the selection-move branch does NOT
|
||||
fire for point changes caused by edits. WebKit and Chromium
|
||||
never send both ValueChanged and SelectedTextChanged for the
|
||||
@@ -389,7 +389,7 @@ index 426b029..8d44b5f 100644
|
||||
self.cachedPoint = point;
|
||||
|
||||
NSDictionary *change = @{
|
||||
@@ -9178,16 +9357,83 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
|
||||
@@ -9215,16 +9394,83 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
|
||||
BOOL markActive = !NILP (BVAR (b, mark_active));
|
||||
|
||||
/* --- Text changed (edit) --- */
|
||||
@@ -477,7 +477,7 @@ index 426b029..8d44b5f 100644
|
||||
{
|
||||
ptrdiff_t oldPoint = self.cachedPoint;
|
||||
BOOL oldMarkActive = self.cachedMarkActive;
|
||||
@@ -9355,7 +9601,7 @@ - (NSRect)accessibilityFrame
|
||||
@@ -9393,7 +9639,7 @@ - (NSRect)accessibilityFrame
|
||||
|
||||
|
||||
/* ===================================================================
|
||||
@@ -486,7 +486,7 @@ index 426b029..8d44b5f 100644
|
||||
=================================================================== */
|
||||
|
||||
/* Scan visible range of window W for interactive spans.
|
||||
@@ -9564,7 +9810,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
|
||||
@@ -9602,7 +9848,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
|
||||
dispatch_async (dispatch_get_main_queue (), ^{
|
||||
/* lwin is a Lisp_Object captured by value. This is GC-safe
|
||||
because Lisp_Objects are tagged integers/pointers that
|
||||
@@ -495,7 +495,7 @@ index 426b029..8d44b5f 100644
|
||||
Emacs. The WINDOW_LIVE_P check below guards against the
|
||||
window being deleted between capture and execution. */
|
||||
if (!WINDOWP (lwin) || NILP (Fwindow_live_p (lwin)))
|
||||
@@ -9590,7 +9836,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
|
||||
@@ -9628,7 +9874,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
|
||||
|
||||
@end
|
||||
|
||||
@@ -504,7 +504,7 @@ index 426b029..8d44b5f 100644
|
||||
Methods are kept here (same .m file) so they access the ivars
|
||||
declared in the @interface ivar block. */
|
||||
@implementation EmacsAccessibilityBuffer (InteractiveSpans)
|
||||
@@ -12312,7 +12558,7 @@ - (int) fullscreenState
|
||||
@@ -12350,7 +12596,7 @@ - (int) fullscreenState
|
||||
|
||||
if (WINDOW_LEAF_P (w))
|
||||
{
|
||||
@@ -513,7 +513,7 @@ index 426b029..8d44b5f 100644
|
||||
EmacsAccessibilityBuffer *elem
|
||||
= [existing objectForKey:[NSValue valueWithPointer:w]];
|
||||
if (!elem)
|
||||
@@ -12346,7 +12592,7 @@ - (int) fullscreenState
|
||||
@@ -12384,7 +12630,7 @@ - (int) fullscreenState
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -522,7 +522,7 @@ index 426b029..8d44b5f 100644
|
||||
Lisp_Object child = w->contents;
|
||||
while (!NILP (child))
|
||||
{
|
||||
@@ -12458,7 +12704,7 @@ - (void)postAccessibilityUpdates
|
||||
@@ -12496,7 +12742,7 @@ - (void)postAccessibilityUpdates
|
||||
accessibilityUpdating = YES;
|
||||
|
||||
/* Detect window tree change (split, delete, new buffer). Compare
|
||||
@@ -531,7 +531,7 @@ index 426b029..8d44b5f 100644
|
||||
Lisp_Object curRoot = FRAME_ROOT_WINDOW (emacsframe);
|
||||
if (!EQ (curRoot, lastRootWindow))
|
||||
{
|
||||
@@ -12467,12 +12713,12 @@ - (void)postAccessibilityUpdates
|
||||
@@ -12505,12 +12751,12 @@ - (void)postAccessibilityUpdates
|
||||
}
|
||||
|
||||
/* If tree is stale, rebuild FIRST so we don't iterate freed
|
||||
|
||||
Reference in New Issue
Block a user