patches: fix org fold/unfold VoiceOver refresh; revert to BUF_MODIFF
REGRESSION: fold/unfold in org-mode, outline-mode and hideshow-mode did
not refresh VoiceOver text because ensureTextCache used BUF_CHARS_MODIFF
which is NOT bumped by (put-text-property ... 'invisible), the mechanism
used by modern org-fold-core (org >= 29) and outline-mode to hide text.
VoiceOver would continue reading folded content as if visible, or miss
newly unfolded content entirely, because the text cache was considered
valid despite the visible-text having changed.
Revert ensureTextCache to BUF_MODIFF with an explanatory comment:
- BUF_CHARS_MODIFF is bumped only on character insertions/deletions, not
text-property changes. Fold/unfold uses text properties for visibility.
- BUF_OVERLAY_MODIFF alone is also insufficient: org >= 29 uses text
properties, not overlays, for folding. Also hl-line-mode bumps
BUF_OVERLAY_MODIFF every post-command-hook --- same per-keystroke cost
as BUF_MODIFF, with none of its correctness guarantee.
- BUF_MODIFF cost is acceptable: ensureTextCache is called only when
VoiceOver queries AX properties (human interaction speed, not redisplay
speed). Rebuild cost is O(visible-buffer-text).
Also retain C-n/C-p line-read fix from previous commit (7a0b4f6):
FocusedUIElementChanged excluded for sequential isCtrlNP moves.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
From 33333f637c51c1ee2080c780fd623e67d3a85545 Mon Sep 17 00:00:00 2001
|
||||
From f26d6d8d2a9030af3296902b4e3db79fef3ed760 Mon Sep 17 00:00:00 2001
|
||||
From: Daneel <daneel@sukany.cz>
|
||||
Date: Mon, 2 Mar 2026 18:49:13 +0100
|
||||
Subject: [PATCH 8/8] ns: announce child frame completion candidates for
|
||||
@@ -33,8 +33,8 @@ area announcements.
|
||||
doc/emacs/macos.texi | 14 +-
|
||||
etc/NEWS | 18 +-
|
||||
src/nsterm.h | 20 ++
|
||||
src/nsterm.m | 456 +++++++++++++++++++++++++++++++++++++++----
|
||||
4 files changed, 460 insertions(+), 48 deletions(-)
|
||||
src/nsterm.m | 436 ++++++++++++++++++++++++++++++++++++++++---
|
||||
4 files changed, 446 insertions(+), 42 deletions(-)
|
||||
|
||||
diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi
|
||||
index 8d4a7825d8..03a657f970 100644
|
||||
@@ -149,7 +149,7 @@ index 21a93bc799..bdd40b8eb7 100644
|
||||
@end
|
||||
|
||||
diff --git a/src/nsterm.m b/src/nsterm.m
|
||||
index 3d8a5dd0fc..7555ae3e95 100644
|
||||
index 8f744d1bf3..b434a7fd41 100644
|
||||
--- a/src/nsterm.m
|
||||
+++ b/src/nsterm.m
|
||||
@@ -1126,24 +1126,19 @@ Uses CFAbsoluteTimeGetCurrent() (~5 ns, a VDSO read) for timing. */
|
||||
@@ -300,37 +300,7 @@ index 3d8a5dd0fc..7555ae3e95 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
|
||||
@@ -8149,15 +8250,23 @@ - (void)ensureTextCache
|
||||
if (!b)
|
||||
return;
|
||||
|
||||
+ /* 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 add BUF_OVERLAY_MODIFF here: modes like hl-line-mode move
|
||||
+ overlays on every post-command-hook, bumping BUF_OVERLAY_MODIFF and
|
||||
+ causing O(buffer-size) text rebuilds per keystroke. Fold/unfold
|
||||
+ changes visible characters and thereby bumps BUF_CHARS_MODIFF. */
|
||||
ptrdiff_t chars_modiff = BUF_CHARS_MODIFF (b);
|
||||
ptrdiff_t pt = BUF_PT (b);
|
||||
NSUInteger textLen = cachedText ? [cachedText length] : 0;
|
||||
- /* 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 == chars_modiff
|
||||
&& cachedTextStart == BUF_BEGV (b)
|
||||
&& pt >= cachedTextStart
|
||||
@@ -8587,6 +8696,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range
|
||||
@@ -8605,6 +8706,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range
|
||||
|
||||
[self ensureTextCache];
|
||||
|
||||
@@ -342,7 +312,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
specpdl_ref count = SPECPDL_INDEX ();
|
||||
record_unwind_current_buffer ();
|
||||
/* Ensure block_input is always matched by unblock_input even if
|
||||
@@ -9042,15 +9156,23 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point
|
||||
@@ -9060,15 +9166,23 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point
|
||||
= @(ns_ax_text_state_change_selection_move);
|
||||
moveInfo[@"AXTextSelectionDirection"] = @(direction);
|
||||
moveInfo[@"AXTextChangeElement"] = self;
|
||||
@@ -372,7 +342,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
NSAccessibilitySelectedTextChangedNotification,
|
||||
moveInfo);
|
||||
|
||||
@@ -9148,12 +9270,17 @@ user expectation ("w" jumps to next word and reads it). */
|
||||
@@ -9166,12 +9280,17 @@ user expectation ("w" jumps to next word and reads it). */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +365,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
if (cachedText
|
||||
&& granularity == ns_ax_text_selection_granularity_line)
|
||||
{
|
||||
@@ -9218,6 +9345,11 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
|
||||
@@ -9236,6 +9355,11 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
|
||||
|
||||
block_input ();
|
||||
specpdl_ref count2 = SPECPDL_INDEX ();
|
||||
@@ -407,7 +377,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
record_unwind_protect_void (unblock_input);
|
||||
record_unwind_current_buffer ();
|
||||
if (b != current_buffer)
|
||||
@@ -9394,12 +9526,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
|
||||
@@ -9412,12 +9536,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
|
||||
if (!b)
|
||||
return;
|
||||
|
||||
@@ -437,7 +407,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
if (modiff != self.cachedModiff)
|
||||
{
|
||||
self.cachedModiff = modiff;
|
||||
@@ -9413,6 +9562,7 @@ Text property changes (e.g. face updates from
|
||||
@@ -9431,6 +9572,7 @@ Text property changes (e.g. face updates from
|
||||
{
|
||||
self.cachedCharsModiff = chars_modiff;
|
||||
[self postTextChangedNotification:point];
|
||||
@@ -445,7 +415,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9435,8 +9585,15 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
|
||||
@@ -9453,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.
|
||||
@@ -463,7 +433,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
goto skip_overlay_scan;
|
||||
|
||||
int selected_line = -1;
|
||||
@@ -9482,7 +9639,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
|
||||
@@ -9500,7 +9649,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
|
||||
self.cachedPoint = point;
|
||||
self.cachedMarkActive = markActive;
|
||||
|
||||
@@ -483,7 +453,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
NSInteger direction = ns_ax_text_selection_direction_discontiguous;
|
||||
if (point > oldPoint)
|
||||
direction = ns_ax_text_selection_direction_next;
|
||||
@@ -9716,6 +9884,13 @@ - (NSRect)accessibilityFrame
|
||||
@@ -9734,6 +9894,13 @@ - (NSRect)accessibilityFrame
|
||||
if (vis_start >= vis_end)
|
||||
return @[];
|
||||
|
||||
@@ -497,7 +467,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
block_input ();
|
||||
specpdl_ref blk_count = SPECPDL_INDEX ();
|
||||
record_unwind_protect_void (unblock_input);
|
||||
@@ -9840,6 +10015,7 @@ than O(chars). Fall back to pos+1 as safety net. */
|
||||
@@ -9858,6 +10025,7 @@ than O(chars). Fall back to pos+1 as safety net. */
|
||||
pos = span_end;
|
||||
}
|
||||
|
||||
@@ -505,7 +475,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
return [[spans copy] autorelease];
|
||||
}
|
||||
|
||||
@@ -10021,6 +10197,10 @@ - (void)dealloc
|
||||
@@ -10039,6 +10207,10 @@ - (void)dealloc
|
||||
#endif
|
||||
|
||||
[accessibilityElements release];
|
||||
@@ -516,7 +486,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
[[self menu] release];
|
||||
[super dealloc];
|
||||
}
|
||||
@@ -11470,6 +11650,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
|
||||
@@ -11488,6 +11660,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
|
||||
|
||||
windowClosing = NO;
|
||||
processingCompose = NO;
|
||||
@@ -526,7 +496,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
scrollbarsNeedingUpdate = 0;
|
||||
fs_state = FULLSCREEN_NONE;
|
||||
fs_before_fs = next_maximized = -1;
|
||||
@@ -12778,6 +12961,154 @@ - (id)accessibilityFocusedUIElement
|
||||
@@ -12796,6 +12971,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. */
|
||||
@@ -681,7 +651,7 @@ index 3d8a5dd0fc..7555ae3e95 100644
|
||||
- (void)postAccessibilityUpdates
|
||||
{
|
||||
NSTRACE ("[EmacsView postAccessibilityUpdates]");
|
||||
@@ -12788,11 +13119,64 @@ - (void)postAccessibilityUpdates
|
||||
@@ -12806,11 +13129,64 @@ - (void)postAccessibilityUpdates
|
||||
|
||||
/* Re-entrance guard: VoiceOver callbacks during notification posting
|
||||
can trigger redisplay, which calls ns_update_end, which calls us
|
||||
|
||||
Reference in New Issue
Block a user