Questions tagged [nstextview]

NSTextView is the front-end class to MacOS's Application Kit text system. It draws the text managed by the back-end components and handles user events to select and modify its text. While NSTextView is a subclass of NSText—which declares the most general Cocoa interface to the text system—NSTextView adds major features beyond the capabilities of NSText.

Text views are user interface objects instantiated from the NSTextView class. Text views typically display multiple lines of text laid out in paragraphs with all the characteristics of sophisticated typesetting. A text view is the main user interface to the Cocoa text-editing system. It handles user events to provide text entry and modification, and to display any font, including those of non-English languages, with arbitrary colors, styles, and other attributes.

The Cocoa text system supports text views with many other underlying objects providing text storage, layout, font and attribute manipulation, spell checking, undo and redo, copy and paste, drag and drop, saving of text to files, and other features. NSTextView is a subclass of NSText, which is a separate class for historical reasons. You don’t instantiate NSText, although it declares many of the methods you use with NSTextView. When you put an NSTextView object in an NSWindow object, you have a full-featured text editor whose capabilities are provided “for free” by the Cocoa text system.

871 questions
8
votes
2 answers

How to implement undo with NSTextview

I want to implement undo action after replacing portion of text in an NSTextView. I am replacing portion of text with following code - (void)omeAction { NSString *fullString = [self.textView string]; NSRange selectedRange = [self.textView…
Johnykutty
  • 12,091
  • 13
  • 59
  • 100
8
votes
3 answers

How do I know when an attachment attribute is being added to my NSTextView?

Because of the semantics of certain NSTextView attachments in my application, I want to know when they are inserted or deleted from my text storage. My subclass of NSTextView implements the shouldChangeTextInRange:replacementString: method, which…
danielpunkass
  • 17,527
  • 4
  • 24
  • 38
8
votes
3 answers

How can I set [NSTextView selectedTextAttributes] on a background window?

The default value for [NSTextView selectedTextAttributes] is unusable in my app, because i allow the user to select colors (syntax highlighting) that are almost exactly the same as the background color. I have written some math to determine a…
Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110
8
votes
2 answers

Custom insertion point for NSTextView

I'm changing the insertion point size by overriding -(void)drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor turnedOn:(BOOL)flag, But it doesn't handle the first blink (when you move the insertion point, it goes back to normal) I…
Jensen
  • 1,653
  • 4
  • 26
  • 42
7
votes
1 answer

Technique on how to format/color NSTextView's string

I'm looking for a reliable technique to do simple string formatting(bold, italic,...) in a NSTextView. The text parsing is almost done with regex, but now I need to apply font trait and also change the size. Some code snippets on how I make a text…
brutella
  • 1,597
  • 13
  • 26
7
votes
4 answers

NSTextView not refreshed properly on scrolling

I have a NSTextView with a sizeable quantity of text. Whenever I scroll however, the view isn't updated properly. There are some artifacts that remain at the top or the bottom of the view. It appears that the view doesn't refresh itself often…
EightyEight
  • 3,430
  • 4
  • 36
  • 67
7
votes
2 answers

How do I make a Cocoa NSTextView grow as the user types into it?

For a Cocoa application I am writing, I would like to support a panel to the right of the main document content where users can add notes for the currently selected document content. (If you are familiar with Microsoft Word or Scrivener, this…
Kaelin Colclasure
  • 3,925
  • 1
  • 26
  • 36
7
votes
2 answers

NSView receiving click events thru a NSTextView

I have a NSTextView, non-editable, non-selectable, in a NSView. I need the NSView to receive click events when the text view is clicked - basically I need the click events to act as though the text view doesn't even exist. Obviously I would just use…
Chris
  • 1,037
  • 15
  • 26
7
votes
1 answer

Focus on a NSTextView

I have a button and a NSTextView in my application. I want that the NSTextView gets focus when the button is pushed. If I then enter text through keyboard it should go in the NSTextView. What code should i put in the button's action method?
AmaltasCoder
  • 1,123
  • 3
  • 17
  • 35
7
votes
4 answers

setting an NSTextView

How can I set an NSTextView to an NSAttributedString? I do not want to use a textConainer, and I tried: [myTextView insertText:myMutableAttributedString]; but it didn't work. Nothing happened...not even a warning or a runtime error. Any help would…
user657819
  • 141
  • 1
  • 4
7
votes
2 answers

NSTextView not showing red misspelling underlines when on a layer

When an NSTextView is a subview of an NSView that is layer-backed (-wantsLayer == YES), it does not render the squiggly red underlines for misspelled words. All it takes to reproduce this is to make an empty Cocoa project, open the nib, drag…
Sean
  • 1,272
  • 1
  • 13
  • 27
7
votes
1 answer

How does NSFontManager addFontTrait change the actual font on the UI element

I want to achieve the same thing as [[NSFontManager sharedFontManager] addFontTrait:(nullable id)sender] only using my code The doc states This action method causes the receiver to send its action message up the responder chain. By default, the…
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
7
votes
2 answers

NSTextView inside NSView and NSScrollView

My goal is to make a view that is similar to the Goole Docs text editor, with comment highlighting behind the text where there are comments. My solution is to have an NSScrollView containing an NSView (set as the document view) that scrolls and…
jamespick
  • 1,974
  • 3
  • 23
  • 45
7
votes
2 answers

set default Font for NSTextView with swift

I am able to change the Font in NSTextView AFTER I have loaded some text. nameTextView.string = "Some Text" nameTextView.textStorage?.font = NSFont(name: "Lucida Sans", size: 15) but how can I set this Font as the default Font? if the user starts…
7
votes
1 answer

What's the equivalent "sizeWithFont: " method for the Mac?

I'm familiar with sizeWithFont: for the iPhone. Now I'm trying to build an app for the Mac and need something like that, but I don't know how to do it :/ Here's why I need it: I've got a panel that displays some text, and I want to size it so that…
Bernardo
  • 73
  • 4