From bc5714b7b7b84b48e6977f12b34aace6196b94d1 Mon Sep 17 00:00:00 2001 From: Daneel Date: Mon, 2 Mar 2026 12:38:40 +0100 Subject: [PATCH] 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) --- ...-with-macOS-Zoom-for-cursor-tracking.patch | 8 +- ...lity-base-classes-and-text-extractio.patch | 14 +-- ...fer-accessibility-element-core-proto.patch | 10 +- ...tification-dispatch-and-mode-line-el.patch | 16 +-- ...ive-span-elements-for-Tab-navigation.patch | 6 +- ...essibility-with-EmacsView-and-redisp.patch | 24 ++-- ...r-accessibility-section-to-macOS-app.patch | 8 +- ...lay-completion-candidates-for-VoiceO.patch | 52 ++++----- ...d-frame-completion-candidates-for-Vo.patch | 104 +++++++++--------- 9 files changed, 124 insertions(+), 118 deletions(-) diff --git a/patches/0000-ns-integrate-with-macOS-Zoom-for-cursor-tracking.patch b/patches/0000-ns-integrate-with-macOS-Zoom-for-cursor-tracking.patch index b314cdd..a8495ea 100644 --- a/patches/0000-ns-integrate-with-macOS-Zoom-for-cursor-tracking.patch +++ b/patches/0000-ns-integrate-with-macOS-Zoom-for-cursor-tracking.patch @@ -1,4 +1,4 @@ -From edb3a37f853fc9b98dfc96a7ba0434e87e1fdc3e Mon Sep 17 00:00:00 2001 +From a92cfbac382d563f5d54fac32fab1711414574bb Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Sat, 28 Feb 2026 22:39:35 +0100 Subject: [PATCH 0/8] ns: integrate with macOS Zoom for cursor tracking @@ -32,7 +32,7 @@ to the selected completion candidate after normal cursor tracking. 3 files changed, 370 insertions(+) diff --git a/etc/NEWS b/etc/NEWS -index ef36df5..80661a9 100644 +index 7367e3ccbd..4c149e41d6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -82,6 +82,17 @@ other directory on your system. You can also invoke the @@ -54,7 +54,7 @@ index ef36df5..80661a9 100644 ** 'line-spacing' now supports specifying spacing above the line. Previously, only spacing below the line could be specified. The user diff --git a/src/nsterm.h b/src/nsterm.h -index 7c1ee4c..ea6e7ba 100644 +index 7c1ee4cf53..ea6e7ba4f5 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -484,6 +484,12 @@ enum ns_return_frame_mode @@ -71,7 +71,7 @@ index 7c1ee4c..ea6e7ba 100644 } diff --git a/src/nsterm.m b/src/nsterm.m -index 74e4ad5..fc75910 100644 +index 932d209f56..417c312a88 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -71,6 +71,11 @@ Updated by Christian Limpach (chris@nice.ch) diff --git a/patches/0001-ns-add-accessibility-base-classes-and-text-extractio.patch b/patches/0001-ns-add-accessibility-base-classes-and-text-extractio.patch index a801e44..38584b6 100644 --- a/patches/0001-ns-add-accessibility-base-classes-and-text-extractio.patch +++ b/patches/0001-ns-add-accessibility-base-classes-and-text-extractio.patch @@ -1,4 +1,4 @@ -From 1ecb71555d3419523d8ccebc03ace9bffac4f99e Mon Sep 17 00:00:00 2001 +From efe1a90a98dc725ea55bda0fa466427b39cdd253 Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Sat, 28 Feb 2026 12:58:11 +0100 Subject: [PATCH 1/8] ns: add accessibility base classes and text extraction @@ -29,11 +29,11 @@ ns-accessibility-enabled with corrected doc: initial value is nil, set non-nil automatically when an AT is detected at startup. --- src/nsterm.h | 131 +++++++++++++++ - src/nsterm.m | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++ + src/nsterm.m | 452 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 583 insertions(+) diff --git a/src/nsterm.h b/src/nsterm.h -index ea6e7ba..5746e9e 100644 +index ea6e7ba4f5..5746e9e9bd 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -453,6 +453,124 @@ enum ns_return_frame_mode @@ -189,7 +189,7 @@ index ea6e7ba..5746e9e 100644 diff --git a/src/nsterm.m b/src/nsterm.m -index fc75910..852e7f9 100644 +index 417c312a88..a1cece7c23 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -46,6 +46,7 @@ Updated by Christian Limpach (chris@nice.ch) @@ -200,7 +200,7 @@ index fc75910..852e7f9 100644 #include "systime.h" #include "character.h" #include "xwidget.h" -@@ -7209,6 +7210,430 @@ - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg +@@ -7200,6 +7201,430 @@ - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg } #endif @@ -631,7 +631,7 @@ index fc75910..852e7f9 100644 /* ========================================================================== EmacsView implementation -@@ -11665,6 +12090,24 @@ Convert an X font name (XLFD) to an NS font name. +@@ -11656,6 +12081,24 @@ Convert an X font name (XLFD) to an NS font name. DEFSYM (Qns_drag_operation_generic, "ns-drag-operation-generic"); DEFSYM (Qns_handle_drag_motion, "ns-handle-drag-motion"); @@ -656,7 +656,7 @@ index fc75910..852e7f9 100644 Fput (Qalt, Qmodifier_value, make_fixnum (alt_modifier)); Fput (Qhyper, Qmodifier_value, make_fixnum (hyper_modifier)); Fput (Qmeta, Qmodifier_value, make_fixnum (meta_modifier)); -@@ -11813,6 +12260,15 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with +@@ -11804,6 +12247,15 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with This variable is ignored on Mac OS X < 10.7 and GNUstep. */); ns_use_srgb_colorspace = YES; diff --git a/patches/0002-ns-implement-buffer-accessibility-element-core-proto.patch b/patches/0002-ns-implement-buffer-accessibility-element-core-proto.patch index 08db4ac..800d11f 100644 --- a/patches/0002-ns-implement-buffer-accessibility-element-core-proto.patch +++ b/patches/0002-ns-implement-buffer-accessibility-element-core-proto.patch @@ -1,4 +1,4 @@ -From f29ed7e4e305a5f8857e72d3762d43c0901be718 Mon Sep 17 00:00:00 2001 +From 3e4f7fff7eb999c4a497ef21bf01ad41819191eb Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Sat, 28 Feb 2026 12:58:11 +0100 Subject: [PATCH 2/8] ns: implement buffer accessibility element (core @@ -23,14 +23,14 @@ loop is safe: it runs only on actual character modifications. (accessibilityRangeForPosition:, setAccessibilitySelectedTextRange:) (setAccessibilityFocused:): Implement NSAccessibility protocol methods. --- - src/nsterm.m | 1127 ++++++++++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 1123 insertions(+) + src/nsterm.m | 1115 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 1115 insertions(+) diff --git a/src/nsterm.m b/src/nsterm.m -index 852e7f9..3e1ac74 100644 +index a1cece7c23..3d031ddb69 100644 --- a/src/nsterm.m +++ b/src/nsterm.m -@@ -7631,6 +7631,1121 @@ - (id)accessibilityTopLevelUIElement +@@ -7622,6 +7622,1121 @@ - (id)accessibilityTopLevelUIElement @end diff --git a/patches/0003-ns-add-buffer-notification-dispatch-and-mode-line-el.patch b/patches/0003-ns-add-buffer-notification-dispatch-and-mode-line-el.patch index b2a107d..5ae5210 100644 --- a/patches/0003-ns-add-buffer-notification-dispatch-and-mode-line-el.patch +++ b/patches/0003-ns-add-buffer-notification-dispatch-and-mode-line-el.patch @@ -1,4 +1,4 @@ -From b4b09f69a8a4742e9f1431242d58e2c52400112c Mon Sep 17 00:00:00 2001 +From 554bc4a174d0f6ec934108687da165f71ce9cf9a Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Sat, 28 Feb 2026 12:58:11 +0100 Subject: [PATCH 3/8] ns: add buffer notification dispatch and mode-line @@ -22,14 +22,14 @@ detects text edit, cursor/mark change, or overlay change. (EmacsAccessibilityModeLine): Implement AXStaticText element for the mode line. --- - src/nsterm.m | 546 +++++++++++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 546 insertions(+) + src/nsterm.m | 605 +++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 605 insertions(+) diff --git a/src/nsterm.m b/src/nsterm.m -index 3e1ac74..d3015e2 100644 +index 3d031ddb69..221697b78a 100644 --- a/src/nsterm.m +++ b/src/nsterm.m -@@ -8758,6 +8758,609 @@ - (NSRect)accessibilityFrame +@@ -8737,6 +8737,611 @@ - (NSRect)accessibilityFrame @end @@ -94,6 +94,7 @@ index 3e1ac74..d3015e2 100644 + granularity:(NSInteger)granularity + markActive:(BOOL)markActive + oldMarkActive:(BOOL)oldMarkActive ++ emacsInitiated:(BOOL)emacsInitiated +{ + BOOL isCharMove + = (!markActive && !oldMarkActive @@ -163,7 +164,7 @@ index 3e1ac74..d3015e2 100644 + BOOL isWordMove + = (!markActive && !oldMarkActive + && granularity == ns_ax_text_selection_granularity_word -+ && direction == ns_ax_text_selection_direction_discontiguous); ++ && emacsInitiated); + if (isWordMove && cachedText) + { + NSCharacterSet *ws @@ -531,7 +532,8 @@ index 3e1ac74..d3015e2 100644 + direction:direction + granularity:granularity + markActive:markActive -+ oldMarkActive:oldMarkActive]; ++ oldMarkActive:oldMarkActive ++ emacsInitiated:NO]; + + if (![self isAccessibilityFocused] && cachedText) + [self postCompletionAnnouncementForBuffer:b point:point]; diff --git a/patches/0004-ns-add-interactive-span-elements-for-Tab-navigation.patch b/patches/0004-ns-add-interactive-span-elements-for-Tab-navigation.patch index 988ffc0..0850f51 100644 --- a/patches/0004-ns-add-interactive-span-elements-for-Tab-navigation.patch +++ b/patches/0004-ns-add-interactive-span-elements-for-Tab-navigation.patch @@ -1,4 +1,4 @@ -From 1ce902a7a0b0d4d63e9d9f8718145d183a3c5d1a Mon Sep 17 00:00:00 2001 +From e2e327e374445912764bf3efb4dd65af9a238a41 Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Sat, 28 Feb 2026 12:58:11 +0100 Subject: [PATCH 4/8] ns: add interactive span elements for Tab navigation @@ -18,10 +18,10 @@ rebuilding lazily when interactiveSpansDirty is set. 1 file changed, 287 insertions(+) diff --git a/src/nsterm.m b/src/nsterm.m -index d3015e2..6d3b87a 100644 +index 221697b78a..70ec4286bf 100644 --- a/src/nsterm.m +++ b/src/nsterm.m -@@ -9304,6 +9304,293 @@ - (NSRect)accessibilityFrame +@@ -9342,6 +9342,293 @@ - (NSRect)accessibilityFrame @end diff --git a/patches/0005-ns-integrate-accessibility-with-EmacsView-and-redisp.patch b/patches/0005-ns-integrate-accessibility-with-EmacsView-and-redisp.patch index 2c552df..e1778e5 100644 --- a/patches/0005-ns-integrate-accessibility-with-EmacsView-and-redisp.patch +++ b/patches/0005-ns-integrate-accessibility-with-EmacsView-and-redisp.patch @@ -1,4 +1,4 @@ -From 6e6c5f4cf33d302e23141ce241c1747cdc0304be Mon Sep 17 00:00:00 2001 +From d1adda245af7b5a2b8bc3b0c738f661dcc78b626 Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Sat, 28 Feb 2026 12:58:11 +0100 Subject: [PATCH 5/8] ns: integrate accessibility with EmacsView and redisplay @@ -27,10 +27,10 @@ com.apple.accessibility.api distributed notification. 2 files changed, 431 insertions(+), 12 deletions(-) diff --git a/etc/NEWS b/etc/NEWS -index 80661a9..2b1f9e6 100644 +index 4c149e41d6..7f917f93b2 100644 --- a/etc/NEWS +++ b/etc/NEWS -@@ -4400,6 +4400,19 @@ allowing Emacs users access to speech recognition utilities. +@@ -4385,6 +4385,19 @@ allowing Emacs users access to speech recognition utilities. Note: Accepting this permission allows the use of system APIs, which may send user data to Apple's speech recognition servers. @@ -51,7 +51,7 @@ index 80661a9..2b1f9e6 100644 ** Re-introduced dictation, lost in Emacs v30 (macOS). We lost macOS dictation in v30 when migrating to NSTextInputClient. diff --git a/src/nsterm.m b/src/nsterm.m -index 6d3b87a..7574da4 100644 +index 70ec4286bf..1444ff2d13 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1275,7 +1275,7 @@ If a completion candidate is selected (overlay or child frame), @@ -92,7 +92,7 @@ index 6d3b87a..7574da4 100644 { NSRect windowRect = [view convertRect:r toView:nil]; NSRect screenRect -@@ -6731,9 +6735,56 @@ - (void)applicationDidFinishLaunching: (NSNotification *)notification +@@ -6722,9 +6726,56 @@ - (void)applicationDidFinishLaunching: (NSNotification *)notification } #endif @@ -149,7 +149,7 @@ index 6d3b87a..7574da4 100644 - (void)antialiasThresholdDidChange:(NSNotification *)notification { #ifdef NS_IMPL_COCOA -@@ -7634,7 +7685,6 @@ - (id)accessibilityTopLevelUIElement +@@ -7625,7 +7676,6 @@ - (id)accessibilityTopLevelUIElement @@ -157,7 +157,7 @@ index 6d3b87a..7574da4 100644 static BOOL ns_ax_find_completion_overlay_range (struct buffer *b, ptrdiff_t point, ptrdiff_t *out_start, -@@ -8759,7 +8809,6 @@ - (NSRect)accessibilityFrame +@@ -8738,7 +8788,6 @@ - (NSRect)accessibilityFrame @end @@ -165,7 +165,7 @@ index 6d3b87a..7574da4 100644 /* =================================================================== EmacsAccessibilityBuffer (Notifications) — AX event dispatch -@@ -9305,7 +9354,6 @@ - (NSRect)accessibilityFrame +@@ -9343,7 +9392,6 @@ - (NSRect)accessibilityFrame @end @@ -173,7 +173,7 @@ index 6d3b87a..7574da4 100644 /* =================================================================== EmacsAccessibilityInteractiveSpan — helpers and implementation =================================================================== */ -@@ -9636,6 +9684,7 @@ - (void)dealloc +@@ -9674,6 +9722,7 @@ - (void)dealloc [layer release]; #endif @@ -181,7 +181,7 @@ index 6d3b87a..7574da4 100644 [[self menu] release]; [super dealloc]; } -@@ -10984,6 +11033,32 @@ - (void)windowDidBecomeKey /* for direct calls */ +@@ -11022,6 +11071,32 @@ - (void)windowDidBecomeKey /* for direct calls */ XSETFRAME (event.frame_or_window, emacsframe); kbd_buffer_store_event (&event); ns_send_appdefined (-1); // Kick main loop @@ -214,7 +214,7 @@ index 6d3b87a..7574da4 100644 } -@@ -12221,6 +12296,332 @@ - (int) fullscreenState +@@ -12259,6 +12334,332 @@ - (int) fullscreenState return fs_state; } @@ -547,7 +547,7 @@ index 6d3b87a..7574da4 100644 @end /* EmacsView */ -@@ -14221,12 +14622,17 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with +@@ -14255,12 +14656,17 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with ns_use_srgb_colorspace = YES; DEFVAR_BOOL ("ns-accessibility-enabled", ns_accessibility_enabled, diff --git a/patches/0006-doc-add-VoiceOver-accessibility-section-to-macOS-app.patch b/patches/0006-doc-add-VoiceOver-accessibility-section-to-macOS-app.patch index 5f5edf7..622aaf3 100644 --- a/patches/0006-doc-add-VoiceOver-accessibility-section-to-macOS-app.patch +++ b/patches/0006-doc-add-VoiceOver-accessibility-section-to-macOS-app.patch @@ -1,4 +1,4 @@ -From cd2037fc2078f3db365fa3f222413d9022c882f5 Mon Sep 17 00:00:00 2001 +From 9703257f348868b6d28ffb07a32515be05180ab3 Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Sat, 28 Feb 2026 12:58:11 +0100 Subject: [PATCH 6/8] doc: add VoiceOver accessibility section to macOS @@ -16,7 +16,7 @@ default: initial value is nil, set automatically at startup. 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi -index 6bd334f..6514dfc 100644 +index 6bd334f48e..f3671354b5 100644 --- a/doc/emacs/macos.texi +++ b/doc/emacs/macos.texi @@ -36,6 +36,7 @@ Support}), but we hope to improve it in the future. @@ -110,10 +110,10 @@ index 6bd334f..6514dfc 100644 @section GNUstep Support diff --git a/src/nsterm.m b/src/nsterm.m -index 7574da4..426b029 100644 +index 1444ff2d13..25e8aeff34 100644 --- a/src/nsterm.m +++ b/src/nsterm.m -@@ -14623,9 +14623,13 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with +@@ -14657,9 +14657,13 @@ Nil means use fullscreen the old (< 10.7) way. The old way works better with DEFVAR_BOOL ("ns-accessibility-enabled", ns_accessibility_enabled, doc: /* Non-nil enables Zoom cursor tracking and VoiceOver support. diff --git a/patches/0007-ns-announce-overlay-completion-candidates-for-VoiceO.patch b/patches/0007-ns-announce-overlay-completion-candidates-for-VoiceO.patch index 3d27a9f..35be8da 100644 --- a/patches/0007-ns-announce-overlay-completion-candidates-for-VoiceO.patch +++ b/patches/0007-ns-announce-overlay-completion-candidates-for-VoiceO.patch @@ -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 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 diff --git a/patches/0008-ns-announce-child-frame-completion-candidates-for-Vo.patch b/patches/0008-ns-announce-child-frame-completion-candidates-for-Vo.patch index 0754f08..5a90b30 100644 --- a/patches/0008-ns-announce-child-frame-completion-candidates-for-Vo.patch +++ b/patches/0008-ns-announce-child-frame-completion-candidates-for-Vo.patch @@ -1,4 +1,4 @@ -From 830710de8a7bac560d71ae802dcf7df60517c57b Mon Sep 17 00:00:00 2001 +From a6249e8ad3512f1e80e509c21111f6e3a241405f Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Sat, 28 Feb 2026 16:01:29 +0100 Subject: [PATCH 8/8] ns: announce child frame completion candidates for @@ -20,11 +20,11 @@ element when a child frame completion closes. doc/emacs/macos.texi | 18 +- etc/NEWS | 18 +- src/nsterm.h | 21 ++ - src/nsterm.m | 496 +++++++++++++++++++++++++++++++++++++++---- - 4 files changed, 501 insertions(+), 52 deletions(-) + src/nsterm.m | 505 +++++++++++++++++++++++++++++++++++++++---- + 4 files changed, 509 insertions(+), 53 deletions(-) diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi -index 6514dfc..bcf74b3 100644 +index f3671354b5..03a657f970 100644 --- a/doc/emacs/macos.texi +++ b/doc/emacs/macos.texi @@ -278,7 +278,6 @@ restart Emacs to access newly-available services. @@ -67,10 +67,10 @@ index 6514dfc..bcf74b3 100644 correctly: character navigation announces the character at the cursor position, not the character before it. diff --git a/etc/NEWS b/etc/NEWS -index 2b1f9e6..5766428 100644 +index 7f917f93b2..d7631fa6c7 100644 --- a/etc/NEWS +++ b/etc/NEWS -@@ -4400,15 +4400,19 @@ allowing Emacs users access to speech recognition utilities. +@@ -4385,16 +4385,20 @@ allowing Emacs users access to speech recognition utilities. Note: Accepting this permission allows the use of system APIs, which may send user data to Apple's speech recognition servers. @@ -99,7 +99,7 @@ index 2b1f9e6..5766428 100644 interface and eliminate the associated overhead. diff --git a/src/nsterm.h b/src/nsterm.h -index 21a93bc..d435e42 100644 +index 21a93bc799..d435e42998 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -504,9 +504,21 @@ typedef struct ns_ax_visible_run @@ -148,7 +148,7 @@ index 21a93bc..d435e42 100644 @end diff --git a/src/nsterm.m b/src/nsterm.m -index 8d44b5f..29b646d 100644 +index b3daec31f1..33b72a0825 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1126,24 +1126,19 @@ Uses CFAbsoluteTimeGetCurrent() (~5 ns, a VDSO read) for timing. */ @@ -199,7 +199,7 @@ index 8d44b5f..29b646d 100644 } #endif /* MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 */ -@@ -7415,6 +7416,112 @@ visual line index for Zoom (skip whitespace-only lines +@@ -7406,6 +7407,112 @@ visual line index for Zoom (skip whitespace-only lines return nil; } @@ -312,7 +312,7 @@ index 8d44b5f..29b646d 100644 /* Build accessibility text for window W, skipping invisible text. Populates *OUT_START with the buffer start charpos. Populates *OUT_RUNS with an array of visible runs and *OUT_NRUNS -@@ -8046,6 +8153,7 @@ that remapped bindings (e.g., C-j -> next-line) are recognized. +@@ -8033,6 +8140,7 @@ that remapped bindings (e.g., C-j -> next-line) are recognized. @implementation EmacsAccessibilityBuffer @synthesize cachedText; @synthesize cachedTextModiff; @@ -320,7 +320,7 @@ index 8d44b5f..29b646d 100644 @synthesize cachedOverlayModiff; @synthesize cachedTextStart; @synthesize cachedModiff; -@@ -8159,16 +8267,34 @@ - (void)ensureTextCache +@@ -8146,16 +8254,34 @@ - (void)ensureTextCache if (!b) return; @@ -363,7 +363,7 @@ index 8d44b5f..29b646d 100644 && cachedTextStart == BUF_BEGV (b) && pt >= cachedTextStart && (textLen == 0 -@@ -8184,7 +8310,8 @@ included in the cached AX text (it is handled separately via +@@ -8171,7 +8297,8 @@ included in the cached AX text (it is handled separately via { [cachedText release]; cachedText = [text retain]; @@ -373,7 +373,7 @@ index 8d44b5f..29b646d 100644 cachedTextStart = start; if (visibleRuns) -@@ -8597,6 +8724,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range +@@ -8584,6 +8711,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range [self ensureTextCache]; @@ -385,7 +385,7 @@ index 8d44b5f..29b646d 100644 specpdl_ref count = SPECPDL_INDEX (); record_unwind_current_buffer (); /* Ensure block_input is always matched by unblock_input even if -@@ -9064,11 +9196,13 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point +@@ -9040,11 +9172,14 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point = @(ns_ax_text_state_change_selection_move); moveInfo[@"AXTextSelectionDirection"] = @(direction); moveInfo[@"AXTextChangeElement"] = self; @@ -394,17 +394,18 @@ index 8d44b5f..29b646d 100644 - for block-cursor mode). Include it for word/line/ - selection so VoiceOver reads the appropriate text. */ - if (!isCharMove) -+ /* Include granularity for sequential moves so VoiceOver reads the -+ appropriate unit. Omit for character moves (announced explicitly -+ below) and for discontiguous jumps (destination line announced -+ explicitly; omitting granularity lets VoiceOver use its default -+ behaviour and re-anchor its browse cursor). */ -+ if (!isCharMove ++ /* Include granularity for sequential VO-initiated moves so VoiceOver ++ reads the appropriate unit. Omit for character moves (announced ++ explicitly below), discontiguous jumps (destination line announced ++ explicitly), and Emacs-initiated moves (announced explicitly; ++ including granularity would cause VoiceOver to auto-speak, ++ doubling the explicit announcement). */ ++ if (!isCharMove && !emacsInitiated + && direction != ns_ax_text_selection_direction_discontiguous) moveInfo[@"AXTextSelectionGranularity"] = @(granularity); ns_ax_post_notification_with_info ( -@@ -9111,12 +9245,17 @@ derive its own speech (it would read the wrong character +@@ -9145,12 +9280,17 @@ user expectation ("w" jumps to next word and reads it). */ } } @@ -427,7 +428,7 @@ index 8d44b5f..29b646d 100644 if (cachedText && granularity == ns_ax_text_selection_granularity_line) { -@@ -9179,7 +9318,14 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b +@@ -9213,7 +9353,14 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b ptrdiff_t currentOverlayStart = 0; ptrdiff_t currentOverlayEnd = 0; @@ -442,7 +443,7 @@ index 8d44b5f..29b646d 100644 record_unwind_current_buffer (); if (b != current_buffer) set_buffer_internal_1 (b); -@@ -9356,12 +9502,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f +@@ -9389,12 +9536,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f if (!b) return; @@ -472,7 +473,7 @@ index 8d44b5f..29b646d 100644 if (modiff != self.cachedModiff) { self.cachedModiff = modiff; -@@ -9375,6 +9538,7 @@ Text property changes (e.g. face updates from +@@ -9408,6 +9572,7 @@ Text property changes (e.g. face updates from { self.cachedCharsModiff = chars_modiff; [self postTextChangedNotification:point]; @@ -480,7 +481,7 @@ index 8d44b5f..29b646d 100644 } } -@@ -9397,8 +9561,15 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property +@@ -9430,8 +9595,15 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property displayed in the minibuffer. In normal editing buffers, font-lock and other modes change BUF_OVERLAY_MODIFF on every redisplay, triggering O(overlays) work per keystroke. @@ -498,7 +499,7 @@ index 8d44b5f..29b646d 100644 goto skip_overlay_scan; int selected_line = -1; -@@ -9444,7 +9615,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property +@@ -9477,7 +9649,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property self.cachedPoint = point; self.cachedMarkActive = markActive; @@ -518,7 +519,7 @@ index 8d44b5f..29b646d 100644 NSInteger direction = ns_ax_text_selection_direction_discontiguous; if (point > oldPoint) direction = ns_ax_text_selection_direction_next; -@@ -9492,6 +9674,36 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property +@@ -9525,6 +9708,30 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property granularity = ns_ax_text_selection_granularity_line; } @@ -532,30 +533,33 @@ index 8d44b5f..29b646d 100644 + if (!isCtrlNP && granularity == ns_ax_text_selection_granularity_line) + direction = ns_ax_text_selection_direction_discontiguous; + -+ /* If Emacs moved the cursor (not VoiceOver), force discontiguous -+ so VoiceOver re-anchors its browse cursor to the current -+ accessibilitySelectedTextRange. This covers all Emacs-initiated -+ moves: editing commands, ELisp, isearch, etc. ++ /* If Emacs moved the cursor (not VoiceOver) and the move ++ crosses a line boundary or jumps to an unknown position, force ++ discontiguous so VoiceOver re-anchors its browse cursor. ++ For character and word moves within a line, keep the natural ++ next/previous direction: SelectedTextChanged with direction=next ++ advances VoiceOver's browse cursor sequentially, and the explicit ++ announcement in postFocusedCursorNotification provides speech. + Exception: C-n/C-p (isCtrlNP) already uses next/previous with -+ line granularity; those are already sequential and VoiceOver -+ handles them correctly. */ -+ if (emacsMovedCursor && !isCtrlNP) ++ line granularity; VoiceOver handles them correctly. */ ++ if (emacsMovedCursor && !isCtrlNP ++ && (granularity == ns_ax_text_selection_granularity_line ++ || granularity == ns_ax_text_selection_granularity_unknown)) + direction = ns_ax_text_selection_direction_discontiguous; -+ -+ /* Post FocusedUIElementChanged on the containing NSView whenever -+ Emacs moves the cursor independently of VoiceOver. Posting on -+ the view causes VoiceOver to re-query accessibilityFocusedUIElement -+ and re-anchor its browse cursor at the new selection range, without -+ re-announcing the element name. Required for all granularities. */ -+ if (emacsMovedCursor && [self isAccessibilityFocused]) -+ ns_ax_post_notification ( -+ self.emacsView, -+ NSAccessibilityFocusedUIElementChangedNotification); + /* Post notifications for focused and non-focused elements. */ if ([self isAccessibilityFocused]) [self postFocusedCursorNotification:point -@@ -9634,6 +9836,17 @@ - (NSRect)accessibilityFrame +@@ -9532,7 +9739,7 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property + granularity:granularity + markActive:markActive + oldMarkActive:oldMarkActive +- emacsInitiated:NO]; ++ emacsInitiated:emacsMovedCursor]; + + if (![self isAccessibilityFocused] && cachedText) + [self postCompletionAnnouncementForBuffer:b point:point]; +@@ -9668,6 +9875,17 @@ - (NSRect)accessibilityFrame if (vis_start >= vis_end) return @[]; @@ -573,7 +577,7 @@ index 8d44b5f..29b646d 100644 /* Symbols are interned once at startup via DEFSYM in syms_of_nsterm; reference them directly here (GC-safe, no repeated obarray lookup). */ -@@ -9754,6 +9967,7 @@ than O(chars). Fall back to pos+1 as safety net. */ +@@ -9788,6 +10006,7 @@ than O(chars). Fall back to pos+1 as safety net. */ pos = span_end; } @@ -581,7 +585,7 @@ index 8d44b5f..29b646d 100644 return [[spans copy] autorelease]; } -@@ -9935,6 +10149,10 @@ - (void)dealloc +@@ -9969,6 +10188,10 @@ - (void)dealloc #endif [accessibilityElements release]; @@ -592,7 +596,7 @@ index 8d44b5f..29b646d 100644 [[self menu] release]; [super dealloc]; } -@@ -11384,6 +11602,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f +@@ -11418,6 +11641,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f windowClosing = NO; processingCompose = NO; @@ -602,7 +606,7 @@ index 8d44b5f..29b646d 100644 scrollbarsNeedingUpdate = 0; fs_state = FULLSCREEN_NONE; fs_before_fs = next_maximized = -1; -@@ -12692,6 +12913,154 @@ - (id)accessibilityFocusedUIElement +@@ -12726,6 +12952,154 @@ - (id)accessibilityFocusedUIElement The existing elements carry cached state (modiff, point) from the previous redisplay cycle. Rebuilding first would create fresh elements with current values, making change detection impossible. */ @@ -757,7 +761,7 @@ index 8d44b5f..29b646d 100644 - (void)postAccessibilityUpdates { NSTRACE ("[EmacsView postAccessibilityUpdates]"); -@@ -12702,11 +13069,64 @@ - (void)postAccessibilityUpdates +@@ -12736,11 +13110,64 @@ - (void)postAccessibilityUpdates /* Re-entrance guard: VoiceOver callbacks during notification posting can trigger redisplay, which calls ns_update_end, which calls us