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,7 @@
From 3bb5a0bed12de424e79a24228e6ae2b4a6e0ecf1 Mon Sep 17 00:00:00 2001
From d176c3c9d97574f0cd493d6491eda0a82ad28387 Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 12:58:11 +0100
Subject: [PATCH 1/6] ns: add accessibility base classes and text extraction
Subject: [PATCH 1/8] ns: add accessibility base classes and text extraction
Add the foundation for macOS VoiceOver accessibility in the NS
(Cocoa) port. No existing code paths are modified.
@@ -15,7 +15,7 @@ Add the foundation for macOS VoiceOver accessibility in the NS
(EmacsAXSpanType): New enum.
(EmacsView): New ivars for accessibility state.
* src/nsterm.m: Include intervals.h for TEXT_PROP_MEANS_INVISIBLE.
(NS_AX_TEXT_CAP): New macro, 100000.
(ns_ax_buffer_text, ns_ax_mode_line_text, ns_ax_frame_for_range)
(ns_ax_completion_string_from_prop, ns_ax_window_buffer_object)
(ns_ax_window_end_charpos, ns_ax_text_prop_at)
@@ -29,15 +29,15 @@ ns-accessibility-enabled.
Tested on macOS 14 Sonoma with VoiceOver 10. Builds cleanly;
no functional change (dead code until patch 5/6 wires it in).
---
src/nsterm.h | 127 ++++++++++++++
src/nsterm.m | 468 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 595 insertions(+)
src/nsterm.h | 131 +++++++++++++++
src/nsterm.m | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 587 insertions(+)
diff --git a/src/nsterm.h b/src/nsterm.h
index 7c1ee4c..51c30ca 100644
index 7c1ee4c..5298386 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -453,6 +453,118 @@ enum ns_return_frame_mode
@@ -453,6 +453,122 @@ enum ns_return_frame_mode
@end
@@ -87,6 +87,8 @@ index 7c1ee4c..51c30ca 100644
+{
+ ns_ax_visible_run *visibleRuns;
+ NSUInteger visibleRunCount;
+ NSUInteger *lineStartOffsets; /* AX string index of each line start. */
+ NSUInteger lineCount; /* Number of entries in lineStartOffsets. */
+ NSMutableArray *cachedInteractiveSpans;
+ BOOL interactiveSpansDirty;
+}
@@ -102,6 +104,8 @@ index 7c1ee4c..51c30ca 100644
+@property (nonatomic, assign) ptrdiff_t cachedCompletionOverlayEnd;
+@property (nonatomic, assign) ptrdiff_t cachedCompletionPoint;
+- (void)invalidateTextCache;
+- (NSInteger)lineForAXIndex:(NSUInteger)idx;
+- (NSRange)rangeForLine:(NSUInteger)line textLength:(NSUInteger)tlen;
+- (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx;
+- (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos;
+@end
@@ -156,7 +160,7 @@ index 7c1ee4c..51c30ca 100644
/* ==========================================================================
The main Emacs view
@@ -471,6 +583,14 @@ enum ns_return_frame_mode
@@ -471,6 +587,14 @@ enum ns_return_frame_mode
#ifdef NS_IMPL_COCOA
char *old_title;
BOOL maximizing_resize;
@@ -171,7 +175,7 @@ index 7c1ee4c..51c30ca 100644
#endif
BOOL font_panel_active;
NSFont *font_panel_result;
@@ -528,6 +648,13 @@ enum ns_return_frame_mode
@@ -528,6 +652,13 @@ enum ns_return_frame_mode
- (void)windowWillExitFullScreen;
- (void)windowDidExitFullScreen;
- (void)windowDidBecomeKey;
@@ -186,7 +190,7 @@ index 7c1ee4c..51c30ca 100644
diff --git a/src/nsterm.m b/src/nsterm.m
index 74e4ad5..935919f 100644
index 74e4ad5..2ac1d9d 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -46,6 +46,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
@@ -197,7 +201,7 @@ index 74e4ad5..935919f 100644
#include "systime.h"
#include "character.h"
#include "xwidget.h"
@@ -6856,6 +6857,442 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action)
@@ -6856,6 +6857,430 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action)
}
#endif
@@ -211,12 +215,6 @@ index 74e4ad5..935919f 100644
+
+/* ---- Helper: extract buffer text for accessibility ---- */
+
+/* Maximum characters exposed via accessibilityValue. */
+/* Cap accessibility text at 100,000 UTF-16 units (~200 KB). VoiceOver
+ performance degrades beyond this; buffers larger than ~50,000 lines
+ are truncated for accessibility purposes. */
+#define NS_AX_TEXT_CAP 100000
+
+/* 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
@@ -288,13 +286,7 @@ index 74e4ad5..935919f 100644
+ make_fixnum (pos), Qinvisible, Qnil, make_fixnum (zv));
+ ptrdiff_t run_end = FIXNUMP (next) ? XFIXNUM (next) : zv;
+
+ /* Cap total text at NS_AX_TEXT_CAP. */
+ ptrdiff_t run_len = run_end - pos;
+ if (ax_offset + (NSUInteger) run_len > NS_AX_TEXT_CAP)
+ run_len = (ptrdiff_t) (NS_AX_TEXT_CAP - ax_offset);
+ if (run_len <= 0)
+ break;
+ run_end = pos + run_len;
+
+ /* Extract this visible run's text. Use
+ Fbuffer_substring_no_properties which correctly handles the
@@ -640,7 +632,7 @@ index 74e4ad5..935919f 100644
/* ==========================================================================
EmacsView implementation
@@ -11312,6 +11749,28 @@ syms_of_nsterm (void)
@@ -11312,6 +11737,28 @@ syms_of_nsterm (void)
DEFSYM (Qns_drag_operation_generic, "ns-drag-operation-generic");
DEFSYM (Qns_handle_drag_motion, "ns-handle-drag-motion");
@@ -669,7 +661,7 @@ index 74e4ad5..935919f 100644
Fput (Qalt, Qmodifier_value, make_fixnum (alt_modifier));
Fput (Qhyper, Qmodifier_value, make_fixnum (hyper_modifier));
Fput (Qmeta, Qmodifier_value, make_fixnum (meta_modifier));
@@ -11460,6 +11919,15 @@ Note that this does not apply to images.
@@ -11460,6 +11907,15 @@ Note that this does not apply to images.
This variable is ignored on Mac OS X < 10.7 and GNUstep. */);
ns_use_srgb_colorspace = YES;