Search code examples
cocoanstextfieldnstextviewnstokenfield

Text token inside NSTextField


I'm trying to create a NSTextField to allow batch renaming of some files. This field should allow to insert some tokens to customize each filename. The problem with NSTokenField is that 1) it trims whitespaces, which should be allowed, 2) it doesn't have enough features to mix tokens and plain text as I want, for example, it should recognize the start of a token even if the actual style is plain text.

Now I thought of subclassing NSTextField or NSTextView to draw my tokens manually, but how can I make each token act as if it was a single character? Can I somehow add a NSCell with some text?


Solution

  • "1) it trims whitespaces, which should be allowed" - I thought this could be customized with delegate methods.

    "2) ... it should recognize the start of a token even if the actual style is plain text" - A token is a token. It should be exact-match-or-not-a-token since your users may in fact conceivably have a substring of a token as an honest-to-god literal.