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
17
votes
2 answers

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

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…
pjv
  • 566
  • 3
  • 16
17
votes
3 answers

how to disable LookUp (Dictionary, Thesaurus, Wikipedia) functionality within a NSTextView?

One of my projects is an testing app where a student shouldn't be able to easily look up words while they're typing. It's relatively easy to turn off automatic spelling checking in a NSTextView via setContinuousSpellCheckingEnabled: and…
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
17
votes
4 answers

NSString boundingRectWithSize slightly underestimating the correct height - why?

I'm attempting to resize a text field / view automatically depending on its current width. In other words I want the width to stay constant but resize the height according to the text supplied to it. It seems to be working but for some reason is…
Desh__
  • 899
  • 1
  • 10
  • 16
16
votes
4 answers

When I paste text to a NSTextView, how to paste plain text only?

When I paste text to a NSTextView, I wish I can paste plain text only. All the rich text formats should be removed, include: font, color, link, and paragraph style. All the text pasted should be displayed with the default font and style of the text…
Stephen Hsu
  • 5,127
  • 7
  • 31
  • 39
16
votes
4 answers

NSTextView draws black on almost-black in Dark Mode

When I build my macOS app in Dark Mode, some of my text views (NSTextView) render black text on a almost-black background. In Interface Builder, in the Attributes Inspector, the "Text Color" is set to to the system "Default (Text Color)", which I…
Jerry Krinock
  • 4,860
  • 33
  • 39
16
votes
4 answers

NSTextView value changed

I'm pretty new to mac development (coming from a web and iOS background) and I can't work out how I could get a notification every time the value of an NSTextView changes. Any ideas?
tarnfeld
  • 25,992
  • 41
  • 111
  • 146
16
votes
3 answers

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

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…
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
15
votes
1 answer

NSTextView and NSAttributedString

I'm trying to stick an attributed string into my NSTextView, but it's just showing as plain text, no attributes. I created my string like so: NSString *str = @"Parsing Directory Structure\n\n"; NSMutableAttributedString *attrstr =…
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
15
votes
5 answers

Scrolling NSTextView to bottom

I'm making a little server app for OS X and I'm using an NSTextView to log some info about connected clients. Whenever I need to log something I'm appending the new message to the text of the NSTextView this way: - (void)logMessage:(NSString…
BigLex
  • 2,978
  • 5
  • 19
  • 27
14
votes
1 answer

Changing text selection color in NSTextView

I'm trying to write a "highlight" feature on an NSTextView. Currently, everything works great. You select a range of text and the background color of that text changes to yellow. However, while it's still selected, the background is that standard…
Dexter
  • 5,666
  • 6
  • 33
  • 45
14
votes
6 answers

Set the placeholder string for NSTextView

Is there any way to set the placeholder string for NSTextView like that in NSTextField? I have checked the property but couldn't find it. I have searched some questions but there isn't a proper explanation.
Zeist
  • 635
  • 1
  • 7
  • 17
14
votes
3 answers

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

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…
jbrennan
  • 11,943
  • 14
  • 73
  • 115
13
votes
1 answer

NSTextView insert image in between text

Is it possible to insert an image (not a background image) into an NSTextView? Something like: Hi :) How are you? and it should display a "smiley" image. I have an NSTextView and an NSImage.
Amitg2k12
  • 3,765
  • 10
  • 48
  • 97
13
votes
1 answer

Bulleted list with NSTextList in NSTextView example?

I would want to parse user input in a NSTextView, so that a line beginning with "- " would automatically start a bulleted list. What do I have to do to the NSTextView.textStorage to enable a bulleted list so that the next bullet automatically…
Melodius
  • 2,505
  • 3
  • 22
  • 37
13
votes
4 answers

Real time NSTask output to NSTextView with Swift

I'm using an NSTask to run rsync, and I'd like the status to show up in the text view of a scroll view inside a window. Right now I have this: let pipe = NSPipe() task2.standardOutput = pipe task2.launch() let data =…
The Beanstalk
  • 798
  • 1
  • 5
  • 20
1
2
3
58 59