尝试将 NSMutableParagraphStyle 应用于新的 NSRange 失败

发布于 2024-09-13 09:13:24 字数 925 浏览 2 评论 0原文

所有,

我正在调整 NSTextView 以基本上支持插入样板文本和缩进。我遇到了一个问题,在我从编辑范围中删除样板缩进样式后,样板文本的缩进应用于非样板文本(当用户按 Enter 键时删除该样式)。这就是事情变得奇怪的地方:

随着编辑器中公开的文本标尺,我看到了改变缩进的行为。输入回车键后,我运行以下代码:

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; 
[style setTabStops: [NSArray array]];
[style setHeadIndent:0];
[style setFirstLineHeadIndent:0];
NSRange effectiveRange = [textView rangeForUserTextChange];
[self applyStyleToRange:effectiveRange style:style];
[style release];

最初,这是可行的,但是如果我将光标移动到该新行上方的锅炉镀层缩进文本,则制表位会重新出现,并且当我将光标向下移动到回车符创建的新行。在我看来,前一段的风格正在应用于新段落。

我在网上发布了一个视频(30 秒 1.3 MB)来显示问题:

http://gordonjl.com/files/indentingProblem%20-%20Computer.m4v

另外:是的,这是一个糟糕的方法,但这是此版本的最后一个错误,我必须运送它。在后续版本中,我希望将 NSTextView 插入滚动区域并以更明确的方式管理它。在那之前,请帮忙!

All,

I'm tweaking an NSTextView to basically support insertion of boiler plate text and indenting. I'm running into a problem where the indenting of boiler plate text is applied to non-boiler plate text after I remove the boiler plate indenting style from the edited range (i remove the style when the user hits enter). Here's where things get weird:

With the text ruler exposed in the editor, I'm seeing behaviour that changes the indent. After the return key is entered, I run the following code:

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; 
[style setTabStops: [NSArray array]];
[style setHeadIndent:0];
[style setFirstLineHeadIndent:0];
NSRange effectiveRange = [textView rangeForUserTextChange];
[self applyStyleToRange:effectiveRange style:style];
[style release];

Initially, this works, but if I move my cursor up to the boiler-plated, indented text above this new line, the tab stop reappears and doesn't go away when I move the cursor back down to the new line the carriage return created. It seems to me that the style of the prior paragraph is being applied to the new paragraph.

I've put a video up on the web (30 seconds 1.3 MB) that shows the problem:

http://gordonjl.com/files/indentingProblem%20-%20Computer.m4v

Also: Yes, this is a terrible way to do this, but this is the last bug for this release and I have to ship it. In a subsequent release I'm hoping to insert NSTextViews into a scroll area and manage it in a more explicit manner. Until then, help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

用心笑 2024-09-20 09:13:24

我不太明白你的目标,但是 FWIW,如果你要设置段落属性,你可能需要使用 rangeForUserParagraphChange。如果光标位于textStorage的末尾,则必须设置textView的typingAttributes,因为将属性应用于空范围是没有意义的。

I don't really understand your objective but FWIW, if you are setting a paragraph attribute you might want to use rangeForUserParagraphChange. If cursor is at end of textStorage, you must set the textView's typingAttributes because it is meaningless to apply an attribute to an empty range.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文