修改NSTextStorage属性会导致滚动视图跳转 [英] Modifying NSTextStorage attributes causes scroll view to jump around

查看:173
本文介绍了修改NSTextStorage属性会导致滚动视图跳转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通过正确设置 NSTextStorage 委托我的 NSTextView 并更改文本属性 -textStorageDidProcessEditing

I have implemented basic syntax highlighting by properly setting the NSTextStorage delegate of my NSTextView and changing the text attributes in -textStorageDidProcessEditing.

基本过程如下

- (void)textStorageDidProcessEditing:(NSNotification *)notification {
  NSTextStorage *storage = [notification object];
  [storage beginEditing];

  NSString *text = [storage string];
  NSRange textRange = NSMakeRange(0, [text length]);

  [storage removeAttribute:NSForegroundColorAttributeName range:textRange];

  // Some regex matching here ...

  [storage addAttribute:NSForegroundColorAttributeName
                  value:[COSyntax colorForPatternGroup:pattern.groupName]
                  range:capturedRanges[group]];

  [storage endEditing];
}

每当 -removeAttribute:range: SPACE 字符时调用<$ c>或 -addAttribute:value:range c> NSTextView 周围 NSScrollView 位置开始跳转(滚动旋钮到附近的某个随机位置)

Whenever -removeAttribute:range: or -addAttribute:value:range is invoked when a SPACE character is entered, the NSTextViews surrounding NSScrollView location begins to jump around (scroll knob goes to some random position near the )

这是什么造成的?

推荐答案

我终于从我的观察中发现跳跃不仅发生当按下空格键,但对于其他键,如退格以及正好当这两种情况发生时发生。

- 不连续的布局打开

- 任何修改,甚至属性,在可见区域之前的文本在 -textStorageDidProcessEditing:

内部看起来像是在不连续布局功能的错误!

它似乎与调用 -beginEditing 无关。-endEditing

I have finally found out from my observations that the jumping happens not only when pressing spacebar but for other keys such as backspace as well and this happens exactly when both of these happen.
- Non-contiguous layout is turned on
- Any modification, even to attributes, of text preceding the visible region is made inside -textStorageDidProcessEditing:
Looks like it is a bug in Non-contiguous layout feature! Would be good if an expert could confirm.
It appears to have nothing to do with calling -beginEditing and -endEditing.

这篇关于修改NSTextStorage属性会导致滚动视图跳转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆