patches: fold line index + remove NS_AX_TEXT_CAP into 0001-0002

- 0001: remove NS_AX_TEXT_CAP (100K char cap), add lineStartOffsets/
  lineCount ivars and method declarations to nsterm.h
- 0002: add lineForAXIndex:/rangeForLine: O(log L) helpers, build line
  index in ensureTextCache, replace O(L) line scanning in
  accessibilityInsertionPointLineNumber/accessibilityLineForIndex/
  accessibilityRangeForLine, free index in invalidateTextCache/dealloc
- 0009 deleted (folded into 0001+0002)
- README.txt: remove NS_AX_TEXT_CAP references, update known
  limitations, stress test threshold 50K lines
This commit is contained in:
2026-02-28 21:39:30 +01:00
parent 419762bde0
commit 30089e9413
10 changed files with 540 additions and 552 deletions

View File

@@ -1,7 +1,8 @@
From 846e2fa3f856138127bdc7a475e066003cc76904 Mon Sep 17 00:00:00 2001
From d68d1334147a7de273e39cf26c778389faa424ad Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 16:01:29 +0100
Subject: [PATCH] ns: announce child frame completion candidates for VoiceOver
Subject: [PATCH 8/8] ns: announce child frame completion candidates for
VoiceOver
Completion frameworks such as Corfu, Company-box, and similar
render candidates in a child frame rather than as overlay strings
@@ -42,14 +43,14 @@ childFrameCompletionActive flag.
refocus parent buffer element when child frame closes.
---
src/nsterm.h | 2 +
src/nsterm.m | 277 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 276 insertions(+), 3 deletions(-)
src/nsterm.m | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 254 insertions(+), 1 deletion(-)
diff --git a/src/nsterm.h b/src/nsterm.h
index 5c15639..8b34300 100644
index a007925..1a8a84d 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -594,6 +594,7 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
@@ -598,6 +598,7 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
NSRect lastAccessibilityCursorRect;
BOOL overlayZoomActive;
NSRect overlayZoomRect;
@@ -57,7 +58,7 @@ index 5c15639..8b34300 100644
#endif
BOOL font_panel_active;
NSFont *font_panel_result;
@@ -657,6 +658,7 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
@@ -661,6 +662,7 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
- (void)rebuildAccessibilityTree;
- (void)invalidateAccessibilityTree;
- (void)postAccessibilityUpdates;
@@ -66,10 +67,10 @@ index 5c15639..8b34300 100644
@end
diff --git a/src/nsterm.m b/src/nsterm.m
index 143e784..37918a4 100644
index ebd52c6..a7025a9 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7066,6 +7066,110 @@ ns_ax_selected_overlay_text (struct buffer *b,
@@ -7310,6 +7310,110 @@ ns_ax_selected_overlay_text (struct buffer *b,
}
@@ -180,29 +181,11 @@ index 143e784..37918a4 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
@@ -12311,6 +12415,120 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
@@ -12588,6 +12692,105 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
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. */
+
+/* Child frame completion dedup state. File-scope so that
+ lastChildFrameBuffer can be staticpro'd against GC. */
+static Lisp_Object lastChildFrameBuffer;
+static EMACS_INT lastChildFrameModiff;
+static char *lastChildFrameCandidate;
+
+/* Reset the re-entrance guard when unwinding past
+ postAccessibilityUpdates due to a Lisp signal (longjmp).
+ Without this, a signal during Lisp calls (e.g. Fget_char_property
+ in overlay or child frame scanning) would leave
+ accessibilityUpdating = YES permanently, suppressing all future
+ accessibility notifications. */
+static void
+ns_ax_reset_accessibility_updating (void *view)
+{
+ ((EmacsView *)view)->accessibilityUpdating = NO;
+}
+
+/* Announce the selected candidate in a child frame completion popup.
+ Handles Corfu, Company-box, and similar frameworks that render
+ candidates in a separate child frame rather than as overlay strings
@@ -211,6 +194,10 @@ index 143e784..37918a4 100644
+ after the parent's draw_window_cursor. */
+- (void)announceChildFrameCompletion
+{
+ static char *lastCandidate;
+ static struct buffer *lastBuffer;
+ static EMACS_INT lastModiff;
+
+ /* Validate frame state --- child frames may be partially
+ initialized during creation. */
+ if (!WINDOWP (emacsframe->selected_window))
@@ -225,11 +212,10 @@ index 143e784..37918a4 100644
+ also guards against re-entrance: if Lisp calls below
+ trigger redisplay, the modiff check short-circuits. */
+ EMACS_INT modiff = BUF_MODIFF (b);
+ if (EQ (w->contents, lastChildFrameBuffer)
+ && modiff == lastChildFrameModiff)
+ if (b == lastBuffer && modiff == lastModiff)
+ return;
+ lastChildFrameBuffer = w->contents;
+ lastChildFrameModiff = modiff;
+ lastBuffer = b;
+ lastModiff = modiff;
+
+ /* Skip buffers larger than a typical completion popup.
+ This avoids scanning eldoc, which-key, or other child
@@ -246,10 +232,10 @@ index 143e784..37918a4 100644
+
+ /* Deduplicate --- avoid re-announcing the same candidate. */
+ const char *cstr = [candidate UTF8String];
+ if (lastChildFrameCandidate && strcmp (cstr, lastChildFrameCandidate) == 0)
+ if (lastCandidate && strcmp (cstr, lastCandidate) == 0)
+ return;
+ xfree (lastChildFrameCandidate);
+ lastChildFrameCandidate = xstrdup (cstr);
+ xfree (lastCandidate);
+ lastCandidate = xstrdup (cstr);
+
+ NSDictionary *annInfo = @{
+ NSAccessibilityAnnouncementKey: candidate,
@@ -301,7 +287,7 @@ index 143e784..37918a4 100644
- (void)postAccessibilityUpdates
{
NSTRACE ("[EmacsView postAccessibilityUpdates]");
@@ -12321,10 +12539,60 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
@@ -12598,11 +12801,59 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
/* Re-entrance guard: VoiceOver callbacks during notification posting
can trigger redisplay, which calls ns_update_end, which calls us
@@ -312,16 +298,14 @@ index 143e784..37918a4 100644
if (accessibilityUpdating)
return;
accessibilityUpdating = YES;
+ specpdl_ref axCount = SPECPDL_INDEX ();
+ record_unwind_protect_ptr (ns_ax_reset_accessibility_updating, self);
+
+ /* Child frame completion popup (Corfu, Company-box, etc.).
+ Child frames don't participate in the accessibility tree;
+ announce the selected candidate directly. */
+ if (FRAME_PARENT_FRAME (emacsframe))
+ {
+ [self announceChildFrameCompletion];
+ unbind_to (axCount, Qnil);
+ accessibilityUpdating = NO;
+ return;
+ }
+
@@ -360,37 +344,10 @@ index 143e784..37918a4 100644
+ NSAccessibilityFocusedUIElementChangedNotification);
+ }
+ }
+
/* Detect window tree change (split, delete, new buffer). Compare
FRAME_ROOT_WINDOW --- if it changed, the tree structure changed. */
@@ -12355,7 +12623,7 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
NSAccessibilityFocusedUIElementChangedNotification);
lastSelectedWindow = emacsframe->selected_window;
- accessibilityUpdating = NO;
+ unbind_to (axCount, Qnil);
return;
}
@@ -12399,7 +12667,7 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
NSAccessibilityFocusedUIElementChangedNotification);
}
- accessibilityUpdating = NO;
+ unbind_to (axCount, Qnil);
}
/* ---- Cursor position for Zoom (via accessibilityBoundsForRange:) ----
@@ -14341,6 +14609,9 @@ syms_of_nsterm (void)
DEFSYM (Qns_ax_completion, "completion");
DEFSYM (Qns_ax_completions_highlight, "completions-highlight");
DEFSYM (Qns_ax_backtab, "backtab");
+
+ lastChildFrameBuffer = Qnil;
+ staticpro (&lastChildFrameBuffer);
/* Qmouse_face and Qkeymap are defined in textprop.c / keymap.c. */
Fput (Qalt, Qmodifier_value, make_fixnum (alt_modifier));
Fput (Qhyper, Qmodifier_value, make_fixnum (hyper_modifier));
Lisp_Object curRoot = FRAME_ROOT_WINDOW (emacsframe);
--
2.43.0