diff --git a/patches/0003-ns-add-buffer-notification-dispatch-and-mode-line-el.patch b/patches/0003-ns-add-buffer-notification-dispatch-and-mode-line-el.patch index aede7b9..3f2b6d9 100644 --- a/patches/0003-ns-add-buffer-notification-dispatch-and-mode-line-el.patch +++ b/patches/0003-ns-add-buffer-notification-dispatch-and-mode-line-el.patch @@ -27,7 +27,7 @@ diff --git a/src/nsterm.m b/src/nsterm.m index 8f528bd..7e3d57a 100644 --- a/src/nsterm.m +++ b/src/nsterm.m -@@ -8718,6 +8718,551 @@ - (NSRect)accessibilityFrame +@@ -8718,6 +8718,552 @@ - (NSRect)accessibilityFrame @end @@ -432,17 +432,18 @@ index 8f528bd..7e3d57a 100644 + [self ensureTextCache]; + if (cachedText && oldPoint > 0) + { -+ NSUInteger tlen = [cachedText length]; + NSUInteger oldIdx = [self accessibilityIndexForCharpos:oldPoint]; + NSUInteger newIdx = [self accessibilityIndexForCharpos:point]; -+ if (oldIdx > tlen) oldIdx = tlen; -+ if (newIdx > tlen) newIdx = tlen; + -+ NSRange oldLine = [cachedText lineRangeForRange: -+ NSMakeRange (oldIdx, 0)]; -+ NSRange newLine = [cachedText lineRangeForRange: -+ NSMakeRange (newIdx, 0)]; -+ if (oldLine.location != newLine.location) ++ /* Use precomputed lineStartOffsets for O(log L) line lookup. ++ NSString lineRangeForRange: is O(offset) — it scans from ++ the start of the string, causing progressive slowdown in ++ large buffers (O(cursor_position) per redisplay cycle). ++ lineForAXIndex: binary-searches lineStartOffsets, built ++ once per cache rebuild in ensureTextCache. */ ++ NSInteger oldLine = [self lineForAXIndex: oldIdx]; ++ NSInteger newLine = [self lineForAXIndex: newIdx]; ++ if (oldLine != newLine) + granularity = ns_ax_text_selection_granularity_line; + else + {