nstextview

Search-like highlighting in NSTextView

五迷三道 提交于 2019-12-01 04:03:37
问题 So, this is what I want : When a match is highlighted under Mac OS X (when using the "Find" Action), a specific golden rounded box is drawn around the match for an instant (animated) and then goes away. Is there any way I can programmatically trigger the very same function, and highlight a specific range in an NSTextView ? I'm sure there must be something like that out-of-the-box, but I definitely cannot find it... 回答1: I thought it was this one: - (void)showFindIndicatorForRange:(NSRange

How can you intercept pasting into a NSTextView to remove unsupported formatting?

拜拜、爱过 提交于 2019-12-01 04:03:29
I'm trying to create a simple NSTextView-based window for simple WYSIWYG editing. However, I only want to allow certain types of formatting (e.g. Bold, Italic, Underline and a single heading type but no colors or different fonts.) The issue is if I simply use NSTextView, someone can create or copy formatted text in another program, then simply paste it into that view and all that formatting goes with it, allowing things I'm not allowing, such as different fonts, colors, etc. At best, I want to automatically strip out any formatting that my application doesn't support. At worst, I want to

bind:toObject:withKeyPath:options: is one-way binding?

六月ゝ 毕业季﹏ 提交于 2019-12-01 03:48:19
I have two windows: Window A is loaded from NIB; and Window B is created programmatically. Both windows have a NStextView: the attributedString of the textview in Window A is bound to the the property text of a model using IB ; while the attributedString of the textview in Window B is bound to text property of the model using -[NSObject bind:toObject:withKeyPath:options:] method. [textview bind:@"attributedString" toObject:obj withKeyPath:@"text" options:nil]; Here is the weird thing: the textview in Window B is indeed bound to the obj.text , but the changes in the textview is never updated to

Modifying NSTextStorage causes insertion point to move to the end of the line

帅比萌擦擦* 提交于 2019-12-01 03:40:27
I've got an NSTextView subclass acting as its NSTextStorage delegate. I'm trying to do 2 things: Highlight the text in some ways Evaluate the text and then append the answer to the textview. I'm doing this in two different methods, both invoked by the - (void)textStorageWillProcessEditing:(NSNotification *)notification delegate callback. I can do the syntax highlighting just fine, but when it comes to appending my answer, the insertion point jumps to the end of the line and I don't really know why. My evaluate method looks like the following: NSString *result = ..; NSRange lineRange = [

bind:toObject:withKeyPath:options: is one-way binding?

一笑奈何 提交于 2019-12-01 00:30:43
问题 I have two windows: Window A is loaded from NIB; and Window B is created programmatically. Both windows have a NStextView: the attributedString of the textview in Window A is bound to the the property text of a model using IB ; while the attributedString of the textview in Window B is bound to text property of the model using -[NSObject bind:toObject:withKeyPath:options:] method. [textview bind:@"attributedString" toObject:obj withKeyPath:@"text" options:nil]; Here is the weird thing: the

Programmatically set up NSTextView inside NSScrollView

为君一笑 提交于 2019-11-30 17:22:09
问题 I'm trying to set up an NSTextView in an NSScrollView programmatically and am having trouble. Specifically, I can't scroll the text view; the scroll view seems to think "this is all there is". When you try to scroll down to see the rest of the content (without releasing), this is the result: As soon as you release, the scroll view bounces back, so it's not a graphical glitch; it simply clips the text view at the frame height. I've tried experimenting with the Apple 'Text In ScrollView' docs

Truncate NSTextView?

亡梦爱人 提交于 2019-11-30 14:43:31
I tried using defaultParagraphStyle, but I can't seem to get a NSTextView (programmatically added) to truncate text with an ellipsis (...). I am setting the frame during the initWithFrame (150, 20) and I also set the maxSize (150,20). However, text simply overflows. If I set the height where half a line is visible, I can see the top half of the text, however I would like to see the text truncated with ellipsis instead. How can I do this? If you hover over the corresponding control in IB, you can see the declaration and brief documentation on the method that it triggers (usually the getter

How to disable word-wrap of NSTextView?

一个人想着一个人 提交于 2019-11-30 11:21:23
NSTextView does word-wrap by default. How can I disable this? I'm making a JSON code viewer, so I have to disable this. Eonil I got solution from: http://lists.apple.com/archives/cocoa-dev/2008/May/msg02396.html You have to set NSTextView's maximum width to very large number to make this work correctly. (Just copy maximum height) And enable horizontal scrolling of NSScrollView which is superview of the NSTextView. See these pictures: http://www.flickr.com/photos/47601728@N06/4759470529/ http://www.flickr.com/photos/47601728@N06/4759470533/ Update I discovered my old sample code was

NSTextView syntax highlighting

让人想犯罪 __ 提交于 2019-11-30 10:18:10
问题 I'm working on a Cocoa text editor which uses an NSTextView. Is it possible to change the color of certain portions of the text? 回答1: You should add your controller as the delegate of the NSTextStorage object of the NSTextView ( [textView textStorage] ) and then implement the delegate method ‑textStorageDidProcessEditing: . This is called whenever the text changes. In the delegate method you need to get the current NSTextStorage object from the text view using the -textStorage method of

Change the text of a NSTextView programmatically

你说的曾经没有我的故事 提交于 2019-11-30 08:08:58
I can't find any parameter that seems to be related with the text value showed in a NSTextView . I understood that a NSTextView uses a complex structure (with NSLayoutManager etc...), but I can't find a valid way to modify the current text value. MatterGoal The right method is "setString" [textView setString:@"the string"]; Setting text on outlet textView Swift Xcode 8.0 textView.string = newString Ramy Al Zuhouri Something like this: [textView setString:@"new value"]; Duncan Groenewald If you want to set attributed text (formatted text) them try [myTextView setAttributedString: