nstextview

NSPopover below caret in NSTextView

烈酒焚心 提交于 2019-12-21 03:12:19
问题 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}} ). 回答1: I'm not sure if you are still looking for

IBOutlet for NSTextView in a ARC project

孤街醉人 提交于 2019-12-20 17:26:10
问题 As you read here in most cases a IBOutlet should be weak. Now as you can read in the development library not all classes support weak references. (e.g. NSTextView). This means you have to use assign: @property (assign) IBOutlet NSTextView *textView; If you use a weak reference you will get the following error: "Synthesis of a weak-unavailable property is disallowed because it requires synthesis of an ivar of the __weak object" What the documentation missed to mention is now you have to set

How to implement a horizontal rule in a text view?

北城余情 提交于 2019-12-20 04:39:12
问题 Say I have an NSTextView (or a UITextView on iOS) and I want the user to be able to insert horizontal divider rules, like the HTML <hr> tag or this thing: What's the best way to implement this? Apple's documentation is very thing on this. So far, I have two ideas: Insert an NSTextAttachment for each rule and make the layout manager draw it somehow. Instead of a single text view, use multiple text views with scrolling disabled, put them in a stack view, add separator views between them and

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

无人久伴 提交于 2019-12-19 05:24:54
问题 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

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

主宰稳场 提交于 2019-12-19 00:08:25
问题 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

How can I make the Tab key move focus out of a NSTextView?

此生再无相见时 提交于 2019-12-18 11:48:37
问题 I'm using an NSTextView to allow multi-line input. However, due to the nature of my app, users will be more comfortable moving to the next input element when they press TAB. How can I make TAB exit the NSTextView, while keeping the newline behaviour of the Enter key? 回答1: You could implement -textView:doCommandBySelector: in your text view's delegate: - (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector { if (aSelector == @selector(insertTab:)) { [[aTextView window]

Cocoa: looking for a general strategy for programmatic manipulation of NSTextView storage without messing up undo

梦想与她 提交于 2019-12-18 11:08:24
问题 I am writing a special-purpose text editor in cocoa that does things like automatic text substitution, inline text completions (ala Xcode ), etc. I need to be able to programmatically manipulate the NSTextView ’s NSTextStorage in response to 1) user typing, 2) user pasting, 3) user dropping text. I have tried two different general approaches and both of them have caused the NSTextView ’s native undo manager to get out of sync in different ways. In each case, I am only using NSTextView

NSTextField or NSTextView?

徘徊边缘 提交于 2019-12-18 10:42:24
问题 Could someone explain to me what are the main differences between NSTextField and NSTextView? I know that NSTextView has more features and is usually used for longer texts, and NSTextField is usually used for one-line plain text fields, but if I understand correctly, NSTextField can be also used with attributed strings and with multiple lines... What I need specifically is a control that would display the text of messages inside a timeline view like in Tweetie or any other similar software.

How does line spacing work in Core Text? (and why is it different from NSLayoutManager?)

会有一股神秘感。 提交于 2019-12-17 17:25:14
问题 I'm trying to draw text using Core Text functions, with a line spacing that's as close as possible to what it would be if I used NSTextView. Take this font as an example: NSFont *font = [NSFont fontWithName:@"Times New Roman" size:96.0]; The line height of this font, if I would use it in an NSTextView is 111.0. NSLayoutManager *lm = [[NSLayoutManager alloc] init]; NSLog(@"%f", [lm defaultLineHeightForFont:font]); // this is 111.0 Now, if I do the same thing with Core Text, the result is 110.4

NSTextView and highlighting links

别说谁变了你拦得住时间么 提交于 2019-12-13 05:12:36
问题 I'm using a NSTextView with an NSAttributedString to display some links using the NSLinkAttributeName . I'm styling those links using the setLinkTextAttributes: method of NSTextView . However, I would like to give the user a visual feedback when he clicks the link, for example by changing the color of the link while the user pressed down the left mouse button. Is there an easy way to do that or do I have to use NSTextAttachment ? 回答1: I don't think there is an easy way to do this if you want