patches: fix Blocker #2 - remove ensureTextCache from notification path

BUF_MODIFF was needed for fold/unfold correctness (org-mode), but
ensureTextCache was called from postAccessibilityNotificationsForFrame:
on every cursor move, causing O(buffer-size) rebuild on every font-lock
pass.

Fix: remove [self ensureTextCache] from the granularity-detection branch
of the notification path.  The granularity detection now uses cachedText
directly, falling back to granularity_unknown when absent (safe: VoiceOver
makes its own determination).  ensureTextCache is called exclusively from
AX getters (human interaction speed).  Font-lock passes no longer trigger
any cache rebuild.

The BUF_MODIFF validity in ensureTextCache is retained (correct for
fold/unfold). Comment updated to accurately describe the calling pattern.

All 9 patches apply cleanly on fresh base (git apply verified).
This commit is contained in:
2026-03-03 18:26:17 +01:00
parent 70f0cb9a86
commit f42e799991
2 changed files with 79 additions and 57 deletions

View File

@@ -1,4 +1,4 @@
From 137cb30bb546a9599983c25a9873d1518ad8edee Mon Sep 17 00:00:00 2001
From b54ed57b93cb47250695106021d6e96030ffdd59 Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Mon, 2 Mar 2026 18:49:13 +0100
Subject: [PATCH 9/9] ns: announce child frame completion candidates for
@@ -37,8 +37,8 @@ Remove Zoom section (covered by patch 0000). Fix dangling paragraph.
doc/emacs/macos.texi | 13 +-
etc/NEWS | 25 +-
src/nsterm.h | 21 ++
src/nsterm.m | 561 +++++++++++++++++++++++++++++++++++++------
4 files changed, 529 insertions(+), 91 deletions(-)
src/nsterm.m | 560 +++++++++++++++++++++++++++++++++++++------
4 files changed, 528 insertions(+), 91 deletions(-)
diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi
index 72ac3a9aa9..cf5ed0ff28 100644
@@ -160,7 +160,7 @@ index a210ceba14..2edd7cd6e0 100644
@end
diff --git a/src/nsterm.m b/src/nsterm.m
index 54cee74401..6ba2229639 100644
index b9d3a0eb53..5e48710930 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1275,6 +1275,12 @@ If a completion candidate is selected (overlay or child frame),
@@ -309,7 +309,7 @@ index 54cee74401..6ba2229639 100644
if (b != current_buffer)
set_buffer_internal_1 (b);
@@ -8605,6 +8726,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range
@@ -8609,6 +8730,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range
[self ensureTextCache];
@@ -321,7 +321,7 @@ index 54cee74401..6ba2229639 100644
specpdl_ref count = SPECPDL_INDEX ();
record_unwind_current_buffer ();
/* Ensure block_input is always matched by unblock_input even if
@@ -9053,20 +9179,38 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point
@@ -9057,20 +9183,38 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point
&& granularity
== ns_ax_text_selection_granularity_character);
@@ -370,7 +370,7 @@ index 54cee74401..6ba2229639 100644
ns_ax_post_notification_with_info (
self,
NSAccessibilitySelectedTextChangedNotification,
@@ -9166,12 +9310,17 @@ user expectation ("w" jumps to next word and reads it). */
@@ -9170,12 +9314,17 @@ user expectation ("w" jumps to next word and reads it). */
}
}
@@ -393,7 +393,7 @@ index 54cee74401..6ba2229639 100644
if (cachedText
&& granularity == ns_ax_text_selection_granularity_line)
{
@@ -9236,6 +9385,11 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
@@ -9240,6 +9389,11 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
block_input ();
specpdl_ref count2 = SPECPDL_INDEX ();
@@ -405,7 +405,7 @@ index 54cee74401..6ba2229639 100644
record_unwind_protect_void (unblock_input);
record_unwind_current_buffer ();
if (b != current_buffer)
@@ -9412,12 +9566,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
@@ -9416,12 +9570,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
if (!b)
return;
@@ -435,7 +435,7 @@ index 54cee74401..6ba2229639 100644
if (modiff != self.cachedModiff)
{
self.cachedModiff = modiff;
@@ -9431,6 +9602,7 @@ Text property changes (e.g. face updates from
@@ -9435,6 +9606,7 @@ Text property changes (e.g. face updates from
{
self.cachedCharsModiff = chars_modiff;
[self postTextChangedNotification:point];
@@ -443,7 +443,7 @@ index 54cee74401..6ba2229639 100644
}
}
@@ -9453,37 +9625,44 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
@@ -9457,37 +9629,44 @@ 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.
@@ -517,7 +517,7 @@ index 54cee74401..6ba2229639 100644
}
}
}
@@ -9497,7 +9676,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
@@ -9501,7 +9680,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
self.cachedPoint = point;
self.cachedMarkActive = markActive;
@@ -537,15 +537,7 @@ index 54cee74401..6ba2229639 100644
NSInteger direction = ns_ax_text_selection_direction_discontiguous;
if (point > oldPoint)
direction = ns_ax_text_selection_direction_next;
@@ -9509,6 +9699,7 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
/* --- Granularity detection --- */
NSInteger granularity = ns_ax_text_selection_granularity_unknown;
+ BOOL singleLineMove = NO;
[self ensureTextCache];
if (cachedText && oldPoint > 0)
{
@@ -9523,7 +9714,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
@@ -9534,7 +9724,18 @@ to VoiceOver via the AX getter path (accessibilityValue etc.). */
NSRange newLine = [cachedText lineRangeForRange:
NSMakeRange (newIdx, 0)];
if (oldLine.location != newLine.location)
@@ -565,7 +557,7 @@ index 54cee74401..6ba2229639 100644
else
{
NSUInteger dist = (newIdx > oldIdx
@@ -9545,38 +9747,23 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
@@ -9556,38 +9757,23 @@ to VoiceOver via the AX getter path (accessibilityValue etc.). */
granularity = ns_ax_text_selection_granularity_line;
}
@@ -617,7 +609,7 @@ index 54cee74401..6ba2229639 100644
{
NSWindow *win = [self.emacsView window];
if (win)
@@ -9735,6 +9922,13 @@ - (NSRect)accessibilityFrame
@@ -9746,6 +9932,13 @@ - (NSRect)accessibilityFrame
if (vis_start >= vis_end)
return @[];
@@ -631,7 +623,7 @@ index 54cee74401..6ba2229639 100644
block_input ();
specpdl_ref blk_count = SPECPDL_INDEX ();
record_unwind_protect_void (unblock_input);
@@ -10042,6 +10236,10 @@ - (void)dealloc
@@ -10053,6 +10246,10 @@ - (void)dealloc
#endif
[accessibilityElements release];
@@ -642,7 +634,7 @@ index 54cee74401..6ba2229639 100644
[[self menu] release];
[super dealloc];
}
@@ -11491,6 +11689,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
@@ -11502,6 +11699,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
windowClosing = NO;
processingCompose = NO;
@@ -652,7 +644,7 @@ index 54cee74401..6ba2229639 100644
scrollbarsNeedingUpdate = 0;
fs_state = FULLSCREEN_NONE;
fs_before_fs = next_maximized = -1;
@@ -12799,6 +13000,156 @@ - (id)accessibilityFocusedUIElement
@@ -12810,6 +13010,156 @@ - (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. */
@@ -809,7 +801,7 @@ index 54cee74401..6ba2229639 100644
- (void)postAccessibilityUpdates
{
NSTRACE ("[EmacsView postAccessibilityUpdates]");
@@ -12809,11 +13160,69 @@ - (void)postAccessibilityUpdates
@@ -12820,11 +13170,69 @@ - (void)postAccessibilityUpdates
/* Re-entrance guard: VoiceOver callbacks during notification posting
can trigger redisplay, which calls ns_update_end, which calls us