patches: squash perf fixes into respective patches, clean 9-patch series
Performance fixes folded back: - BUF_CHARS_MODIFF → patch 0002 (implement buffer accessibility element) - UAZoomEnabled cache + rate-limit → patch 0000 (Zoom integration) Also in patch 0000: ns_zoom_face_is_selected (standalone compilation). Also in patch 0001: ns_accessibility_enabled defaults to nil.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
From a979f430547512c252320e76683a288872f4f2ff Mon Sep 17 00:00:00 2001
|
||||
From 3840a4b1e57f6fbdfc005ad86ef16bb0bfdf0868 Mon Sep 17 00:00:00 2001
|
||||
From: Martin Sukany <martin@sukany.cz>
|
||||
Date: Sat, 28 Feb 2026 14:46:25 +0100
|
||||
Subject: [PATCH 08/11] ns: announce overlay completion candidates for
|
||||
VoiceOver
|
||||
Subject: [PATCH 8/9] ns: announce overlay completion candidates for VoiceOver
|
||||
|
||||
Completion frameworks such as Vertico, Ivy, and Icomplete render
|
||||
candidates via overlay before-string/after-string properties rather
|
||||
@@ -46,8 +45,8 @@ Key implementation details:
|
||||
Independent overlay branch, BUF_CHARS_MODIFF gating, candidate
|
||||
---
|
||||
src/nsterm.h | 1 +
|
||||
src/nsterm.m | 319 +++++++++++++++++++++++++++++++++++++++++++++------
|
||||
2 files changed, 287 insertions(+), 33 deletions(-)
|
||||
src/nsterm.m | 332 ++++++++++++++++++++++++++++++++++++++++++++-------
|
||||
2 files changed, 290 insertions(+), 43 deletions(-)
|
||||
|
||||
diff --git a/src/nsterm.h b/src/nsterm.h
|
||||
index 6e830de..2102fb9 100644
|
||||
@@ -62,10 +61,10 @@ index 6e830de..2102fb9 100644
|
||||
@property (nonatomic, assign) BOOL cachedMarkActive;
|
||||
@property (nonatomic, copy) NSString *cachedCompletionAnnouncement;
|
||||
diff --git a/src/nsterm.m b/src/nsterm.m
|
||||
index 92a0dde..aaeed33 100644
|
||||
index f7da553..e333d45 100644
|
||||
--- a/src/nsterm.m
|
||||
+++ b/src/nsterm.m
|
||||
@@ -7174,11 +7174,154 @@ Accessibility virtual elements (macOS / Cocoa only)
|
||||
@@ -7208,11 +7208,154 @@ Accessibility virtual elements (macOS / Cocoa only)
|
||||
|
||||
/* ---- Helper: extract buffer text for accessibility ---- */
|
||||
|
||||
@@ -221,7 +220,7 @@ index 92a0dde..aaeed33 100644
|
||||
static NSString *
|
||||
ns_ax_buffer_text (struct window *w, ptrdiff_t *out_start,
|
||||
ns_ax_visible_run **out_runs, NSUInteger *out_nruns)
|
||||
@@ -7249,7 +7392,7 @@ Accessibility virtual elements (macOS / Cocoa only)
|
||||
@@ -7283,7 +7426,7 @@ Accessibility virtual elements (macOS / Cocoa only)
|
||||
|
||||
/* Extract this visible run's text. Use
|
||||
Fbuffer_substring_no_properties which correctly handles the
|
||||
@@ -230,7 +229,7 @@ index 92a0dde..aaeed33 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));
|
||||
@@ -7330,7 +7473,7 @@ Mode lines using icon fonts (e.g. doom-modeline with nerd-font)
|
||||
@@ -7364,7 +7507,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
|
||||
@@ -239,7 +238,7 @@ index 92a0dde..aaeed33 100644
|
||||
charposForAccessibilityIndex which handles invisible text. */
|
||||
ptrdiff_t cp_start = charpos_start;
|
||||
ptrdiff_t cp_end = cp_start + charpos_len;
|
||||
@@ -7809,6 +7952,7 @@ @implementation EmacsAccessibilityBuffer
|
||||
@@ -7843,6 +7986,7 @@ @implementation EmacsAccessibilityBuffer
|
||||
@synthesize cachedOverlayModiff;
|
||||
@synthesize cachedTextStart;
|
||||
@synthesize cachedModiff;
|
||||
@@ -247,7 +246,7 @@ index 92a0dde..aaeed33 100644
|
||||
@synthesize cachedPoint;
|
||||
@synthesize cachedMarkActive;
|
||||
@synthesize cachedCompletionAnnouncement;
|
||||
@@ -7906,7 +8050,7 @@ - (void)ensureTextCache
|
||||
@@ -7940,7 +8084,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
|
||||
@@ -256,38 +255,50 @@ index 92a0dde..aaeed33 100644
|
||||
write section at the end needs synchronization to protect
|
||||
against concurrent reads from AX server thread. */
|
||||
eassert ([NSThread isMainThread]);
|
||||
@@ -7919,16 +8063,15 @@ - (void)ensureTextCache
|
||||
@@ -7952,25 +8096,16 @@ - (void)ensureTextCache
|
||||
if (!b)
|
||||
return;
|
||||
|
||||
ptrdiff_t modiff = BUF_MODIFF (b);
|
||||
- ptrdiff_t overlay_modiff = BUF_OVERLAY_MODIFF (b);
|
||||
- /* Use BUF_CHARS_MODIFF, not BUF_MODIFF, for cache validity.
|
||||
- BUF_MODIFF is bumped by every text-property change, including
|
||||
- font-lock face applications on every redisplay. AX text contains
|
||||
- only characters, not face data, so property-only changes do not
|
||||
- affect the cached value. Rebuilding the full buffer text on
|
||||
- each font-lock pass is O(buffer-size) per redisplay --- this
|
||||
- causes progressive slowdown when scrolling through large files.
|
||||
- BUF_CHARS_MODIFF is bumped only on actual character insertions
|
||||
- and deletions, matching the semantic of "did the text change".
|
||||
- This is the pattern used by WebKit and NSTextView.
|
||||
- Do NOT track BUF_OVERLAY_MODIFF here --- overlay text is not
|
||||
- included in the cached AX text (it is handled separately via
|
||||
- explicit announcements in postAccessibilityNotificationsForFrame).
|
||||
- Including overlay_modiff would silently update cachedOverlayModiff
|
||||
- and prevent the notification dispatch from detecting changes. */
|
||||
- ptrdiff_t chars_modiff = BUF_CHARS_MODIFF (b);
|
||||
+ ptrdiff_t modiff = BUF_MODIFF (b);
|
||||
ptrdiff_t pt = BUF_PT (b);
|
||||
NSUInteger textLen = cachedText ? [cachedText length] : 0;
|
||||
- /* Track both BUF_MODIFF and BUF_OVERLAY_MODIFF. Overlay-only
|
||||
- changes (e.g., timer-based completion highlight move without
|
||||
- text edit) bump overlay_modiff but not modiff. Also detect
|
||||
- narrowing/widening which changes BUF_BEGV without bumping
|
||||
- either modiff counter. */
|
||||
- if (cachedText && cachedTextModiff == chars_modiff
|
||||
+ /* Cache validity: track BUF_MODIFF and buffer narrowing.
|
||||
+ Do NOT track BUF_OVERLAY_MODIFF here --- overlay text is not
|
||||
+ included in the cached AX text (it is handled separately via
|
||||
+ explicit announcements). Including overlay_modiff would
|
||||
+ silently update cachedOverlayModiff and prevent the
|
||||
+ notification dispatch from detecting overlay changes. */
|
||||
if (cachedText && cachedTextModiff == modiff
|
||||
- && cachedOverlayModiff == overlay_modiff
|
||||
+ if (cachedText && cachedTextModiff == modiff
|
||||
&& cachedTextStart == BUF_BEGV (b)
|
||||
&& pt >= cachedTextStart
|
||||
&& (textLen == 0
|
||||
@@ -7945,7 +8088,6 @@ - (void)ensureTextCache
|
||||
@@ -7986,7 +8121,7 @@ included in the cached AX text (it is handled separately via
|
||||
{
|
||||
[cachedText release];
|
||||
cachedText = [text retain];
|
||||
cachedTextModiff = modiff;
|
||||
- cachedOverlayModiff = overlay_modiff;
|
||||
- cachedTextModiff = chars_modiff;
|
||||
+ cachedTextModiff = modiff;
|
||||
cachedTextStart = start;
|
||||
|
||||
if (visibleRuns)
|
||||
@@ -8010,7 +8152,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
|
||||
@@ -8051,7 +8186,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
|
||||
@@ -296,7 +307,7 @@ index 92a0dde..aaeed33 100644
|
||||
NSUInteger lo = 0, hi = visibleRunCount;
|
||||
while (lo < hi)
|
||||
{
|
||||
@@ -8023,7 +8165,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
|
||||
@@ -8064,7 +8199,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
|
||||
else
|
||||
{
|
||||
/* Found: charpos is inside this run. Compute UTF-16 delta
|
||||
@@ -305,7 +316,7 @@ index 92a0dde..aaeed33 100644
|
||||
NSUInteger chars_in = (NSUInteger)(charpos - r->charpos);
|
||||
if (chars_in == 0 || !cachedText)
|
||||
return r->ax_start;
|
||||
@@ -8048,10 +8190,10 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
|
||||
@@ -8089,10 +8224,10 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
|
||||
|
||||
/* Convert accessibility string index to buffer charpos.
|
||||
Safe to call from any thread: uses only cachedText (NSString) and
|
||||
@@ -318,7 +329,7 @@ index 92a0dde..aaeed33 100644
|
||||
@synchronized (self)
|
||||
{
|
||||
if (visibleRunCount == 0)
|
||||
@@ -8085,7 +8227,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
|
||||
@@ -8126,7 +8261,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
@@ -327,7 +338,7 @@ index 92a0dde..aaeed33 100644
|
||||
if (lo > 0)
|
||||
{
|
||||
ns_ax_visible_run *last = &visibleRuns[visibleRunCount - 1];
|
||||
@@ -8107,7 +8249,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
|
||||
@@ -8148,7 +8283,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
|
||||
@@ -336,7 +347,7 @@ index 92a0dde..aaeed33 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
|
||||
@@ -8461,6 +8603,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
|
||||
@@ -8502,6 +8637,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
|
||||
return [self lineForAXIndex:point_idx];
|
||||
}
|
||||
|
||||
@@ -387,7 +398,7 @@ index 92a0dde..aaeed33 100644
|
||||
- (NSRange)accessibilityRangeForLine:(NSInteger)line
|
||||
{
|
||||
if (![NSThread isMainThread])
|
||||
@@ -8683,7 +8869,7 @@ - (NSRect)accessibilityFrame
|
||||
@@ -8724,7 +8903,7 @@ - (NSRect)accessibilityFrame
|
||||
|
||||
|
||||
/* ===================================================================
|
||||
@@ -396,7 +407,7 @@ index 92a0dde..aaeed33 100644
|
||||
|
||||
These methods notify VoiceOver of text and selection changes.
|
||||
Called from the redisplay cycle (postAccessibilityUpdates).
|
||||
@@ -8698,7 +8884,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
|
||||
@@ -8739,7 +8918,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
|
||||
if (point > self.cachedPoint
|
||||
&& point - self.cachedPoint == 1)
|
||||
{
|
||||
@@ -405,7 +416,7 @@ index 92a0dde..aaeed33 100644
|
||||
[self invalidateTextCache];
|
||||
[self ensureTextCache];
|
||||
if (cachedText)
|
||||
@@ -8717,7 +8903,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
|
||||
@@ -8758,7 +8937,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
|
||||
@@ -414,7 +425,7 @@ index 92a0dde..aaeed33 100644
|
||||
self.cachedPoint = point;
|
||||
|
||||
NSDictionary *change = @{
|
||||
@@ -9050,16 +9236,83 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
|
||||
@@ -9091,16 +9270,83 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
|
||||
BOOL markActive = !NILP (BVAR (b, mark_active));
|
||||
|
||||
/* --- Text changed (edit) --- */
|
||||
@@ -502,7 +513,7 @@ index 92a0dde..aaeed33 100644
|
||||
{
|
||||
ptrdiff_t oldPoint = self.cachedPoint;
|
||||
BOOL oldMarkActive = self.cachedMarkActive;
|
||||
@@ -9227,7 +9480,7 @@ - (NSRect)accessibilityFrame
|
||||
@@ -9268,7 +9514,7 @@ - (NSRect)accessibilityFrame
|
||||
|
||||
|
||||
/* ===================================================================
|
||||
@@ -511,7 +522,7 @@ index 92a0dde..aaeed33 100644
|
||||
=================================================================== */
|
||||
|
||||
/* Scan visible range of window W for interactive spans.
|
||||
@@ -9435,7 +9688,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
|
||||
@@ -9476,7 +9722,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
|
||||
@@ -520,7 +531,7 @@ index 92a0dde..aaeed33 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)))
|
||||
@@ -9461,7 +9714,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
|
||||
@@ -9502,7 +9748,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
|
||||
|
||||
@end
|
||||
|
||||
@@ -529,7 +540,7 @@ index 92a0dde..aaeed33 100644
|
||||
Methods are kept here (same .m file) so they access the ivars
|
||||
declared in the @interface ivar block. */
|
||||
@implementation EmacsAccessibilityBuffer (InteractiveSpans)
|
||||
@@ -12186,7 +12439,7 @@ - (int) fullscreenState
|
||||
@@ -12227,7 +12473,7 @@ - (int) fullscreenState
|
||||
|
||||
if (WINDOW_LEAF_P (w))
|
||||
{
|
||||
@@ -538,7 +549,7 @@ index 92a0dde..aaeed33 100644
|
||||
EmacsAccessibilityBuffer *elem
|
||||
= [existing objectForKey:[NSValue valueWithPointer:w]];
|
||||
if (!elem)
|
||||
@@ -12220,7 +12473,7 @@ - (int) fullscreenState
|
||||
@@ -12261,7 +12507,7 @@ - (int) fullscreenState
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -547,7 +558,7 @@ index 92a0dde..aaeed33 100644
|
||||
Lisp_Object child = w->contents;
|
||||
while (!NILP (child))
|
||||
{
|
||||
@@ -12332,7 +12585,7 @@ - (void)postAccessibilityUpdates
|
||||
@@ -12373,7 +12619,7 @@ - (void)postAccessibilityUpdates
|
||||
accessibilityUpdating = YES;
|
||||
|
||||
/* Detect window tree change (split, delete, new buffer). Compare
|
||||
@@ -556,7 +567,7 @@ index 92a0dde..aaeed33 100644
|
||||
Lisp_Object curRoot = FRAME_ROOT_WINDOW (emacsframe);
|
||||
if (!EQ (curRoot, lastRootWindow))
|
||||
{
|
||||
@@ -12341,12 +12594,12 @@ - (void)postAccessibilityUpdates
|
||||
@@ -12382,12 +12628,12 @@ - (void)postAccessibilityUpdates
|
||||
}
|
||||
|
||||
/* If tree is stale, rebuild FIRST so we don't iterate freed
|
||||
|
||||
Reference in New Issue
Block a user