简体   繁体   English

NSTextView:替换所有选项卡

[英]NSTextView: replace all tabs

I have a NSTextView where I would like to use spaces instead of tabs. 我有一个NSTextView ,我想使用空格而不是制表符。 I though I would replaceOccurrencesOfString:withString:options:range: in textStorageWillProcessEditing: of my textview delegate but it doesn't work (undo breaks). 我虽然我会replaceOccurrencesOfString:withString:options:range: in textStorageWillProcessEditing:我的textview delegate但它不起作用(撤消中断)。

Please, does anyone know how to implement such functionality? 请问,有谁知道如何实现这样的功能? Is there other way of doing it? 有其他方式吗?

Edit: this is what I have in the textStorageWillProcessEditing: method: 编辑:这是我在textStorageWillProcessEditing:方法中的内容:

ts = [notification object];
[[ts mutableString] replaceOccurrencesOfString:@"\t"
                                    withString:@"  "
                                       options:NSLiteralSearch
                                         range:[ts editedRange]];

You could override the the keyUp: method. 您可以覆盖keyUp:方法。 If the event.keyCode == keycodefortabwhichidontknow :) then you could insert four spaces. 如果event.keyCode == keycodefortabwhichidontknow :)那么你可以插入四个空格。

And if else, of course just call [super keyDown:theEvent]; 如果是其他的,当然只需要调用[super keyDown:theEvent];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM