Questions tagged [nstextstorage]

NSTextStorage is an iOS class that contains text that is displayed using NSLayoutManager objects, and notifies the NSLayoutManager objects of any changes to its characters or attributes. It defines the fundamental storage mechanism of the Cocoa Application Kit's extended text handling system.

86 questions
20
votes
3 answers

Confusing encoding exception in NSTextStorage

I have an NSDocument subclass for a simple text editor (using Lion's new document based app template, with few customisations), and I'm encountering a strange bug loading the file content into the text storage. Here's my code: -…
Abhi Beckert
  • 30,929
  • 11
  • 77
  • 106
12
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,523
  • 14
  • 69
  • 110
11
votes
2 answers

How to extend NSTextStorage?

According to documentation, I try to subclass NSTextStorage and use it in text view: /* NSTextStorage is a semi-abstract subclass of NSMutableAttributedString. It implements change management (beginEditing/endEditing), verification of attributes,…
dmitrynikolaev
  • 8,436
  • 4
  • 27
  • 43
11
votes
3 answers

Subdivide a text view's attributed string into (referable) sections

I'm trying to implement a very simple text editor that should work both with NSTextView on macOS and UITextView on iOS. This text editor has a toolbar button "Section Break" that inserts a new section at the current cursor position every time it is…
Mischa
  • 12,670
  • 7
  • 51
  • 94
11
votes
1 answer

Proper way to replace NSTextStorage in NSTextView?

I am making some text viewer app. Currently I need very frequent and precise line handling ability, so I want to subclass NSTextStorage class. But I couldn't find any method to set a new text storage to NSTextView. The only method I could find was…
eonil
  • 75,400
  • 74
  • 294
  • 482
10
votes
1 answer

Performance of measuring text width in AppKit

Is there a way in AppKit to measure the width of a large number of NSString objects(say a million) really fast? I have tried 3 different ways to do this: [NSString sizeWithAttributes:] [NSAttributedString size] NSLayoutManager (get text width…
9
votes
3 answers

How to set up an NSTextView programmatically with explicit NSLayoutManager, NSTextStorage, NSTextContainer?

Following the apple documentation I am trying to set up a simple NSTextView via its two constructor methods. I am placing the below code inside the viewDidAppear method of the view controller of the content view. textView is an instance of…
Sam
  • 2,407
  • 2
  • 14
  • 37
8
votes
3 answers

NSTextStorage subclass can't handle emoji characters and changes font in some cases

I'm subclassing NSTextStorage to do some link highlighting and I've read as much as I can on the topic. Everything works fine until I type the emoji character. My subclass: private let ims = NSMutableAttributedString() override var string: String…
8
votes
0 answers

UITextView crash in iOS 8 with attributed string containing a table

In iOS 8 (or possibly even in iOS 7/7.1) NSAttributedString on iOS added the ability to render text tables. This API is public on OS X but not on iOS. However, it is possible to create an attributed string containing a text table on iOS by passing…
indragie
  • 17,634
  • 15
  • 89
  • 161
7
votes
1 answer

iOS: UITextView with custom NSTextStorage crashes

I am writing an iOS 9 application in Swift. I have a view controller that hosts a UITextView and I am assigning a custom NSTextStorage object to it. The NSTextStorage is just basic right now. Everything works correctly and the text shows up in the…
Michael Collins
  • 269
  • 2
  • 13
7
votes
1 answer

Invalid glyph index when setting viewController's layoutManager for NSTextStorage subclass

My goal is to use TextKit to italicize, set the text size, etc. of certain words. To start, I am only trying to highlight a character in my text string. Being new to TextKit (and truthfully to programming in general), I am following the syntax…
6
votes
2 answers

Hide Markdown Characters with NSLayoutManager in Swift

I am working on a rich text editor in a Mac app that uses Markdown syntax. I use NSTextStorage to watch for matches in Markdown syntax, then apply styles to the NSAttributedString in real time like this: At this point, I'm already in way over my…
Clifton Labrum
  • 9,827
  • 7
  • 45
  • 86
6
votes
0 answers

NSTextStorage easily / background attribute change

I'm finishing a nice app with a relatively small text editor. During implementation of the syntax highlight I found myself in need to change foreground colour attribute of recognized tokens. I noticed that there is a property of NSTextStorage: var…
Ivaylo Nikolov
  • 461
  • 3
  • 12
5
votes
0 answers

How to replace a text attachment with a custom drawing with NSLayoutManager?

My ultimate goal is to give the user the ability to split a text inside an NSTextView or UITextView into several sections, where two subsequent sections are visually separated by a custom view separator (possibly, but not necessarily a horizontal…
5
votes
0 answers

iOS 9: How to update the attributed content in a UITextView with a Custom NSTextStorage

I'm using an UITextView to display an attributed string with custom attributes. For this reason I decided to implement my own NSTextStorage, that way after each processing I can insert my custom attributes. Whenever I need to display the UITextView…
Afonso
  • 407
  • 1
  • 5
  • 16
1
2 3 4 5 6