patches: fix all review blockers (iteration 2)

Fixes from Opus maintainer review:
1. [BLOCKER] Zoom code completely removed from ALL intermediate patches
   (0005-0007 no longer have UAZoom/overlayZoom at any commit point)
2. [BLOCKER] Unified cursor rect ivar: lastCursorRect (was split
   between lastZoomCursorRect and lastAccessibilityCursorRect)
3. [HIGH] Child frame static vars moved to EmacsView ivars
   (childFrameLastCandidate/Buffer/Modiff — no cross-frame interference)
4. [HIGH] intern_c_string replaced with Qbefore_string/Qafter_string
5. [MEDIUM] Zoom fallback gated by zoomCursorUpdated flag (no double call)
This commit is contained in:
2026-02-28 22:39:57 +01:00
parent d9b4cbb87a
commit 9d2b1da729
9 changed files with 135 additions and 317 deletions

View File

@@ -1,4 +1,4 @@
From 2222c14590612835529f88c0062fefeedc8f7187 Mon Sep 17 00:00:00 2001
From 5143187e2fa42fa8f5c28e4f39be08ca981692c9 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
@@ -44,12 +44,12 @@ Key implementation details:
(EmacsAccessibilityBuffer postAccessibilityNotificationsForFrame:):
Independent overlay branch, BUF_CHARS_MODIFF gating, candidate
---
src/nsterm.h | 3 +
src/nsterm.m | 359 ++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 327 insertions(+), 35 deletions(-)
src/nsterm.h | 1 +
src/nsterm.m | 312 +++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 279 insertions(+), 34 deletions(-)
diff --git a/src/nsterm.h b/src/nsterm.h
index 5298386..a007925 100644
index ec7b587..19a7e7a 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -509,6 +509,7 @@ typedef struct ns_ax_visible_run
@@ -60,34 +60,11 @@ index 5298386..a007925 100644
@property (nonatomic, assign) ptrdiff_t cachedPoint;
@property (nonatomic, assign) BOOL cachedMarkActive;
@property (nonatomic, copy) NSString *cachedCompletionAnnouncement;
@@ -595,6 +596,8 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
BOOL accessibilityUpdating;
@public /* Accessed by ns_draw_phys_cursor (C function). */
NSRect lastAccessibilityCursorRect;
+ BOOL overlayZoomActive;
+ NSRect overlayZoomRect;
#endif
BOOL font_panel_active;
NSFont *font_panel_result;
diff --git a/src/nsterm.m b/src/nsterm.m
index b3bef4b..7025e6e 100644
index f0e8751..3d72b5d 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -3258,7 +3258,12 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
&& MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
if (UAZoomEnabled ())
{
- NSRect windowRect = [view convertRect:r toView:nil];
+ /* When overlay completion is active (e.g. Vertico),
+ focus Zoom on the selected candidate row instead
+ of the text cursor. */
+ NSRect zoomSrc = view->overlayZoomActive
+ ? view->overlayZoomRect : r;
+ NSRect windowRect = [view convertRect:zoomSrc toView:nil];
NSRect screenRect = [[view window] convertRectToScreen:windowRect];
CGRect cgRect = NSRectToCGRect (screenRect);
@@ -6909,11 +6914,154 @@ Accessibility virtual elements (macOS / Cocoa only)
@@ -6884,11 +6884,154 @@ Accessibility virtual elements (macOS / Cocoa only)
/* ---- Helper: extract buffer text for accessibility ---- */
@@ -148,8 +125,8 @@ index b3bef4b..7025e6e 100644
+ {
+ Lisp_Object ov = XCAR (tail);
+ Lisp_Object strings[2];
+ strings[0] = Foverlay_get (ov, intern_c_string ("before-string"));
+ strings[1] = Foverlay_get (ov, intern_c_string ("after-string"));
+ strings[0] = Foverlay_get (ov, Qbefore_string);
+ strings[1] = Foverlay_get (ov, Qafter_string);
+
+ for (int s = 0; s < 2; s++)
+ {
@@ -243,7 +220,7 @@ index b3bef4b..7025e6e 100644
static NSString *
ns_ax_buffer_text (struct window *w, ptrdiff_t *out_start,
ns_ax_visible_run **out_runs, NSUInteger *out_nruns)
@@ -6984,7 +7132,7 @@ Accessibility virtual elements (macOS / Cocoa only)
@@ -6959,7 +7102,7 @@ Accessibility virtual elements (macOS / Cocoa only)
/* Extract this visible run's text. Use
Fbuffer_substring_no_properties which correctly handles the
@@ -252,7 +229,7 @@ index b3bef4b..7025e6e 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));
@@ -7065,7 +7213,7 @@ Mode lines using icon fonts (e.g. doom-modeline with nerd-font)
@@ -7040,7 +7183,7 @@ Mode lines using icon fonts (e.g. doom-modeline with nerd-font)
return NSZeroRect;
/* charpos_start and charpos_len are already in buffer charpos
@@ -261,7 +238,7 @@ index b3bef4b..7025e6e 100644
charposForAccessibilityIndex which handles invisible text. */
ptrdiff_t cp_start = charpos_start;
ptrdiff_t cp_end = cp_start + charpos_len;
@@ -7544,6 +7692,7 @@ @implementation EmacsAccessibilityBuffer
@@ -7519,6 +7662,7 @@ @implementation EmacsAccessibilityBuffer
@synthesize cachedOverlayModiff;
@synthesize cachedTextStart;
@synthesize cachedModiff;
@@ -269,7 +246,7 @@ index b3bef4b..7025e6e 100644
@synthesize cachedPoint;
@synthesize cachedMarkActive;
@synthesize cachedCompletionAnnouncement;
@@ -7641,7 +7790,7 @@ - (void)ensureTextCache
@@ -7616,7 +7760,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
@@ -278,7 +255,7 @@ index b3bef4b..7025e6e 100644
write section at the end needs synchronization to protect
against concurrent reads from AX server thread. */
eassert ([NSThread isMainThread]);
@@ -7654,16 +7803,15 @@ - (void)ensureTextCache
@@ -7629,16 +7773,15 @@ - (void)ensureTextCache
return;
ptrdiff_t modiff = BUF_MODIFF (b);
@@ -301,7 +278,7 @@ index b3bef4b..7025e6e 100644
&& cachedTextStart == BUF_BEGV (b)
&& pt >= cachedTextStart
&& (textLen == 0
@@ -7680,7 +7828,6 @@ - (void)ensureTextCache
@@ -7655,7 +7798,6 @@ - (void)ensureTextCache
[cachedText release];
cachedText = [text retain];
cachedTextModiff = modiff;
@@ -309,7 +286,7 @@ index b3bef4b..7025e6e 100644
cachedTextStart = start;
if (visibleRuns)
@@ -7745,7 +7892,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -7720,7 +7862,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
@@ -318,7 +295,7 @@ index b3bef4b..7025e6e 100644
NSUInteger lo = 0, hi = visibleRunCount;
while (lo < hi)
{
@@ -7758,7 +7905,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -7733,7 +7875,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
else
{
/* Found: charpos is inside this run. Compute UTF-16 delta
@@ -327,7 +304,7 @@ index b3bef4b..7025e6e 100644
NSUInteger chars_in = (NSUInteger)(charpos - r->charpos);
if (chars_in == 0 || !cachedText)
return r->ax_start;
@@ -7783,10 +7930,10 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -7758,10 +7900,10 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
/* Convert accessibility string index to buffer charpos.
Safe to call from any thread: uses only cachedText (NSString) and
@@ -340,7 +317,7 @@ index b3bef4b..7025e6e 100644
@synchronized (self)
{
if (visibleRunCount == 0)
@@ -7820,7 +7967,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
@@ -7795,7 +7937,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
return cp;
}
}
@@ -349,7 +326,7 @@ index b3bef4b..7025e6e 100644
if (lo > 0)
{
ns_ax_visible_run *last = &visibleRuns[visibleRunCount - 1];
@@ -7842,7 +7989,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
@@ -7817,7 +7959,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
deadlocking the AX server thread. This is prevented by:
1. validWindow checks WINDOW_LIVE_P and BUFFERP before every
@@ -358,7 +335,7 @@ index b3bef4b..7025e6e 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
@@ -8196,6 +8343,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
@@ -8171,6 +8313,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
return [self lineForAXIndex:point_idx];
}
@@ -409,7 +386,7 @@ index b3bef4b..7025e6e 100644
- (NSRange)accessibilityRangeForLine:(NSInteger)line
{
if (![NSThread isMainThread])
@@ -8417,7 +8608,7 @@ - (NSRect)accessibilityFrame
@@ -8392,7 +8578,7 @@ - (NSRect)accessibilityFrame
/* ===================================================================
@@ -418,7 +395,7 @@ index b3bef4b..7025e6e 100644
These methods notify VoiceOver of text and selection changes.
Called from the redisplay cycle (postAccessibilityUpdates).
@@ -8432,7 +8623,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
@@ -8407,7 +8593,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
if (point > self.cachedPoint
&& point - self.cachedPoint == 1)
{
@@ -427,7 +404,7 @@ index b3bef4b..7025e6e 100644
[self invalidateTextCache];
[self ensureTextCache];
if (cachedText)
@@ -8451,7 +8642,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
@@ -8426,7 +8612,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
@@ -436,7 +413,7 @@ index b3bef4b..7025e6e 100644
self.cachedPoint = point;
NSDictionary *change = @{
@@ -8784,14 +8975,112 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
@@ -8759,14 +8945,72 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
BOOL markActive = !NILP (BVAR (b, mark_active));
/* --- Text changed (edit) --- */
@@ -454,7 +431,6 @@ index b3bef4b..7025e6e 100644
+ if (chars_modiff != self.cachedCharsModiff)
+ {
+ self.cachedCharsModiff = chars_modiff;
+ self.emacsView->overlayZoomActive = NO;
+ [self postTextChangedNotification:point];
+ }
+ }
@@ -502,46 +478,7 @@ index b3bef4b..7025e6e 100644
+ NSAccessibilityAnnouncementRequestedNotification,
+ annInfo);
+
+ /* --- Zoom tracking for overlay candidates ---
+ Store the candidate row rect so draw_window_cursor
+ focuses Zoom there instead of on the text cursor.
+ Cleared when the user types (chars_modiff change).
+
+ Use default line height to compute the Y offset:
+ row 0 is the input line, overlay candidates start
+ from row 1. This avoids fragile glyph matrix row
+ index mapping which can be off when group titles
+ or wrapped lines shift row numbering. */
+ if (selected_line >= 0)
+ {
+ struct window *w2 = [self validWindow];
+ if (w2)
+ {
+ EmacsView *view = self.emacsView;
+ struct frame *f2 = XFRAME (w2->frame);
+ int line_h = FRAME_LINE_HEIGHT (f2);
+ int y_off = (selected_line + 1) * line_h;
+
+ if (y_off < w2->pixel_height)
+ {
+ view->overlayZoomRect = NSMakeRect (
+ WINDOW_TEXT_TO_FRAME_PIXEL_X (w2, 0),
+ WINDOW_TO_FRAME_PIXEL_Y (w2, y_off),
+ FRAME_COLUMN_WIDTH (f2),
+ line_h);
+ view->overlayZoomActive = YES;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ /* No selected candidate --- overlay completion ended
+ (minibuffer exit, C-g, etc.) or overlay has no
+ recognizable selection face. Return Zoom to the
+ text cursor. */
+ self.emacsView->overlayZoomActive = NO;
+ }
}
@@ -551,7 +488,7 @@ index b3bef4b..7025e6e 100644
per the WebKit/Chromium pattern. */
else if (point != self.cachedPoint || markActive != self.cachedMarkActive)
{
@@ -8961,7 +9250,7 @@ - (NSRect)accessibilityFrame
@@ -8936,7 +9180,7 @@ - (NSRect)accessibilityFrame
/* ===================================================================
@@ -560,7 +497,7 @@ index b3bef4b..7025e6e 100644
=================================================================== */
/* Scan visible range of window W for interactive spans.
@@ -9152,7 +9441,7 @@ - (NSRect) accessibilityFrame
@@ -9127,7 +9371,7 @@ - (NSRect) accessibilityFrame
- (BOOL) isAccessibilityFocused
{
/* Read the cached point stored by EmacsAccessibilityBuffer on the main
@@ -569,7 +506,7 @@ index b3bef4b..7025e6e 100644
EmacsAccessibilityBuffer *pb = self.parentBuffer;
if (!pb)
return NO;
@@ -9169,7 +9458,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@@ -9144,7 +9388,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
@@ -578,7 +515,7 @@ index b3bef4b..7025e6e 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)))
@@ -9195,7 +9484,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@@ -9170,7 +9414,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@end
@@ -587,7 +524,7 @@ index b3bef4b..7025e6e 100644
Methods are kept here (same .m file) so they access the ivars
declared in the @interface ivar block. */
@implementation EmacsAccessibilityBuffer (InteractiveSpans)
@@ -10515,13 +10804,13 @@ - (NSSize)windowWillResize: (NSWindow *)sender toSize: (NSSize)frameSize
@@ -10490,13 +10734,13 @@ - (NSSize)windowWillResize: (NSWindow *)sender toSize: (NSSize)frameSize
if (old_title == 0)
{
char *t = strdup ([[[self window] title] UTF8String]);
@@ -603,7 +540,7 @@ index b3bef4b..7025e6e 100644
[window setTitle: [NSString stringWithUTF8String: size_title]];
[window display];
xfree (size_title);
@@ -11917,7 +12206,7 @@ - (int) fullscreenState
@@ -11892,7 +12136,7 @@ - (int) fullscreenState
if (WINDOW_LEAF_P (w))
{
@@ -612,7 +549,7 @@ index b3bef4b..7025e6e 100644
EmacsAccessibilityBuffer *elem
= [existing objectForKey:[NSValue valueWithPointer:w]];
if (!elem)
@@ -11951,7 +12240,7 @@ - (int) fullscreenState
@@ -11926,7 +12170,7 @@ - (int) fullscreenState
}
else
{
@@ -621,7 +558,7 @@ index b3bef4b..7025e6e 100644
Lisp_Object child = w->contents;
while (!NILP (child))
{
@@ -12063,7 +12352,7 @@ - (void)postAccessibilityUpdates
@@ -12038,7 +12282,7 @@ - (void)postAccessibilityUpdates
accessibilityUpdating = YES;
/* Detect window tree change (split, delete, new buffer). Compare
@@ -630,7 +567,7 @@ index b3bef4b..7025e6e 100644
Lisp_Object curRoot = FRAME_ROOT_WINDOW (emacsframe);
if (!EQ (curRoot, lastRootWindow))
{
@@ -12072,12 +12361,12 @@ - (void)postAccessibilityUpdates
@@ -12047,12 +12291,12 @@ - (void)postAccessibilityUpdates
}
/* If tree is stale, rebuild FIRST so we don't iterate freed