开发者

How can I implement a text parsing/tokenising interface similar to the way Xcode highlights class names?

开发者 https://www.devze.com 2023-04-11 22:40 出处:网络
I am very new to Cocoa and Objective C so please forgive me if this is a dumb or obvious question. I\'d be very grateful just for pointers to the right classes to read the documentation for or any exi

I am very new to Cocoa and Objective C so please forgive me if this is a dumb or obvious question. I'd be very grateful just for pointers to the right classes to read the documentation for or any existing web resources that will help me figure this out. I am very much willing to do the hard work figuring this out if I can find some suitable resources to point me in the right direction.

I am writing an app that, essentially, will contain a text view into which a user will enter multi-line text. This will then be parsed (I'm thinking of using an NSScanner or, maybe, the ready-made stuff in ParseKit) to extract and tokenise certain words and numerical information which will be stored in a model object.

I thi开发者_如何学Gonk I can figure out the parsing and data-storage stuff. However, I would like the tokenised words and numbers to be highlighted to the user so that they can easily see them, change them and also have a contextual menu (with a disclosure triangle) to perform actions such as ignoring them. Ideally this would look a lot like the way Xcode deals with class names (underlining them with dashed line, giving them a menu etc).

I've had a look at NSTokenField but this seems to be suited most to single-line fields and the big blue tokens are a bit too visually disruptive for what I want. Also, the docs seem to suggest that using the plain text style only allows one token per field so I couldn't mix that with another style to get the effect that I'm after.

I've also had a look at text attachment attributes but I can't quite conceptualise whether they would be the right way to go. So, my questions are:

  1. What is the best way to tokenise only some text within a multi-line text view?
  2. Is it possible to implement a custom visual style for the tokens? Can I do this with existing classes or do I need to create my own?


Watch the WWDC sessions on the Cocoa text system. The class you want to understand is NSLayoutManager.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号