nstextview

Appending to NSTextView

本秂侑毒 提交于 2019-12-22 20:32:10
问题 I've got an NSTask (with an NSPipe set up) running in the background and I want to output the contents, as they're coming in, in an NSTextView ( output ). The code I'm using is : NSMutableAttributedString* str = [[NSMutableAttributedString alloc] initWithString:s]; //[str addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:NSMakeRange(0, [str length])]; [[output textStorage] appendAttributedString:str]; [output scrollRangeToVisible:NSMakeRange([[output string] length]

Get selection (highlighted text) string from NSTextView Objective-C

不打扰是莪最后的温柔 提交于 2019-12-22 11:18:39
问题 How can I get the selected text's string from a NSTextView as an NSString ? Your help is greatly appreciated. 回答1: Since NSTextView is a subclass of NSText, you can use NSText instance methods to figure out the selected string like so: NSString *selected = [[myTextView string] substringWithRange:[myTextView selectedRange]]; 回答2: An NSText can have more than only one selection. Check it out with TextEditapp: select a string with the mouse while pressing CMD. So you can select as many strings

NSTextStorageDelegate's textStorage(_,willProcessEditing:,range:,changeInLength:) moves selection

泄露秘密 提交于 2019-12-22 11:16:33
问题 I'm trying to implement a syntax-coloring text editor that also does things like insert whitespace at the start of a new line for you, or replace text with text attachments. After perusing the docs again after a previous implementation had issues with undoing, it seems like the recommended bottleneck for this is NSTextStorageDelegate's textStorage(_,willProcessEditing:,range:,changeInLength:) method (which states that Delegates can change the characters or attributes. , whereas

How to insert emoji into NSTextView without shifting the line down?

与世无争的帅哥 提交于 2019-12-22 10:31:35
问题 How do I insert emoji into an NSTextView without moving the line down? If I insert an emoji character into an NSTextView , the whole line will shift down a couple pixels. If I remove the emoji character, it will move back up to its original position. On the other hand, if I insert an emoji into an NSTextField , the line doesn't move at all, even when the text in the line is the same font and size as it was in the NSTextView . You can see this behavior in TextEdit. When you are typing in the

NSTextView textDidChange/didChangeText not called for bindings

徘徊边缘 提交于 2019-12-22 09:05:33
问题 I have a custom NSTextView implementation that automatically adjusts the font size so that the text fills the entire view. I overwrote didChangeText to call my font size adjustment method. Works great when the user is editing text, but didChangeText (and the delegate method textDidChange: ) are not called when the text view contents are set via bindings. The font adjustment code needs to run whenever the text is set/changes, not only when it's changed by the user. How can I detect all changes

Cocoa: Stopping the field editor from auto-completing on space key

北城余情 提交于 2019-12-22 08:12:38
问题 I have a custom view with several NSTextField controls for which I want to supply custom auto-completions and I have successfully implemented all that using the NSTextFieldDelegate Protocol. The auto-completions are full names or place names, depending on which text field is being edited. The issue is that the auto-completions almost always contain a space character and so if the user is typing something that matches a suggestion, but doesn't want to accept that suggestion, the field editor

Appending text to NSTextView in Swift 3

左心房为你撑大大i 提交于 2019-12-22 00:09:02
问题 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

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

烂漫一生 提交于 2019-12-21 08:13:28
问题 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

NSTextView non-editable areas of text?

泪湿孤枕 提交于 2019-12-21 05:38:29
问题 I have an NSTextView that contains data for the user to edit, but I want to surround it with a header and footer of non-editable data to give the user an idea of context. I don't think an NSTextView can handle the concept of mixed editable/non-editable data, so I've come up with a few ideas. a) Use text attachments with a custom cell to draw the header and footers. b) Have 3 NSTextView s within the NSScrollView . c) Use attributes to determine what cannot be edited,and use the delegate

Xcode-style placeholders in an NSTextView

只谈情不闲聊 提交于 2019-12-21 05:11:18
问题 In Xcode, if you type <# Hello, Word #> into the text editor, it automatically gets converted to a pale-blue pill-shaped placeholder, but on disk, the text remains exactly as it was typed. Does anyone know if the same effect is achievable using NSTextView ? I've got some very ugly filepaths that must remain exactly as they are so sphinx can put together my docs, but I want to present the user with something a little more attractive when they view the file in my custom text editor. // This on