nstextview

Appending text to NSTextView in Swift 3

﹥>﹥吖頭↗ 提交于 2019-12-04 15:47:59
I am building an application that utilizes an MDM API to make bulk updates to attributes of devices. I am looking to have some sort of visible output/logging in the main view so that the user can see what lines of their CSV may have failed and what the HTTP Response Code was. I can append to an NSTextField or a label easy enough, but seeing as how there may be a large output with many lines, I'd like to have a scrollable text box to append the information to. All of the documentation that I've found for doing this seems to be Swift 2, and this is the one piece of the puzzle I'm missing.

Growing NSTextView to fit contents is clipping last line of text

孤街醉人 提交于 2019-12-04 07:21:17
I'm trying to create an NSTextView that grows vertically as the user types and scrolls once the height has reached a maximum. This is similar to the text view in Messages works. My first attempt uses the delegate to listen for text changes and adjust the height constraint associated with the NSTextView's scroll view: - (void)textDidChange:(NSNotification *)notification { NSTextView *textView = self.textView; NSRect usedRect = [textView.textContainer.layoutManager usedRectForTextContainer:textView.textContainer]; NSLog(@"DEBUG: used rect: %@", NSStringFromRect(usedRect)); self

How to implement undo/redo with programatic change of the textValue of a NSTextView?

落花浮王杯 提交于 2019-12-04 02:29:44
I created a simple demo app with a NSTextView and a button, the provided a NSTextViewDelegate to the textView and added an action: - (IBAction)actionButtonClicked:(id)sender { NSString *oldText = [[[self.textView textStorage] string] copy]; NSString *newText = @"And... ACTION!"; [[self.textView undoManager] registerUndoWithTarget:self.textView selector:@selector(setString:) object:oldText]; [[self.textView undoManager] setActionName:@"ACTION"]; [self.textView setString:newText]; } Undo/redo works without problems, if I change text by hand. But if I change the text with the action method, undo

How to find the text in an NSTextView?

我是研究僧i 提交于 2019-12-03 16:26:55
问题 I need to find the text in an NSTextView , and save it to a file. I can do the saving fine. I have used -stringValue , and -textStorage so far, but neither have worked. When I put -stringValue in, it just gave me (null), and when I put -textStorage in, it gave me a very large chunk of nothing (like a long paragraph of invisible text). How can I put the text from an NSTextView into an NSString ? 回答1: Try NSString *text = [[myTextView textStorage] string]; The NSTextStorage inherits from

NSPopover below caret in NSTextView

柔情痞子 提交于 2019-12-03 08:50:40
I know that in order to show a popover I need an NSView, but I don't think that there is one associated with the caret (inside the NSTextView). Is there a way to show a NSPopover below the caret? I tried to alloc a NSView and position it using (NSRect)boundingRectForGlyphRange:(NSRange)glyphRange inTextContainer:(NSTextContainer *)container , but the popover will not appear (and there's a reason, that method returns NSRect: {{0, 0}, {0, 0}} ). I'm not sure if you are still looking for answer. I recently was working on a project which happens to need a very similar feature like you described.

Saving NSAttributedString with NSTextAttachment into file. How to?

不羁的心 提交于 2019-12-03 08:27:17
I have a NSTextView , which may contains rich text or rich text with image as NSTextAttachment . There is how I adds attachment: NSImage *image = [NSImage imageNamed:@"image"]; NSTextAttachmentCell *attachmentCell =[[NSTextAttachmentCell alloc] initImageCell:image]; NSTextAttachment *attachment =[[NSTextAttachment alloc] init]; [attachment setAttachmentCell: attachmentCell ]; NSAttributedString *attributedString =[NSAttributedString attributedStringWithAttachment: attachment]; [[aTextView textStorage] beginEditing]; if ([aTextView shouldChangeTextInRange:NSMakeRange([aTextView selectedRange]

How to find the text in an NSTextView?

…衆ロ難τιáo~ 提交于 2019-12-03 05:50:16
I need to find the text in an NSTextView , and save it to a file. I can do the saving fine. I have used -stringValue , and -textStorage so far, but neither have worked. When I put -stringValue in, it just gave me (null), and when I put -textStorage in, it gave me a very large chunk of nothing (like a long paragraph of invisible text). How can I put the text from an NSTextView into an NSString ? Try NSString *text = [[myTextView textStorage] string]; The NSTextStorage inherits from NSMutableAttributedString which inherits from NSAttributedString . The latter implements the string method. This

What is the best way to implement syntax highlighting of source code in Cocoa? [closed]

孤街醉人 提交于 2019-12-03 01:05:00
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm working on Cocoa Application that should be able to analyze and highlight a source code written in such languages as Objective-C, SQL, JavaScript, Python etc. The text should be editable too (by using NSTextView, for example). Please advise what is the best way to implement such feature in Mac OS X 10.5.

How to programmatically add bullet list to NSTextView

别说谁变了你拦得住时间么 提交于 2019-12-02 21:17:50
The question may sound strange but I've been struggling with it for a few days. I have a NSTextView that can display some text with a few formatting options. One of them is the ability to turn on/off the bullet list (the easiest one) for a selection or current row. I know that there is a orderFrontListPanel: method on NSTextView that opens the window with available list parameters to select from and edit (like in TextView when you press Menu->Format->List...). I have already figured out and implemented adding bullets by hand and the NSTextView seems to behave with them almost correctly. By

Restoring from versions browser on OSX lion not working… ideas?

人走茶凉 提交于 2019-12-02 11:10:42
I'm trying to restore a document based application from a previous version on Lion. When I select "restore version", the text view doesn't reflect the changes. However, if I close the application and reopen, the changes are there. I'm using the file wrapper variants of NSDocument, so how can I make the text view's text storage reflect the version that's selected immediately? Am I missing something? I had a similar problem recently (my interface didn't seem to update). Are you updating your interface in windowControllerDidLoadNib: or awakeFromNib ? When a document is reverted (revert to last