• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Text: expand certain characters during editing, but still treat as single chars?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Text: expand certain characters during editing, but still treat as single chars?


  • Subject: Text: expand certain characters during editing, but still treat as single chars?
  • From: Andrew Abernathy <email@hidden>
  • Date: Fri, 11 Jul 2003 23:16:59 -0700

I wish to have a text view where certain individual characters in the text storage get expanded to longer text for display/editing, but are stored and manipulated (for the most part, anyway) as single characters.

I'm currently targeting 10.1, but if there is a good solution that requires 10.2 I would like to be aware of that as well.



For more detail on my exact situation, to give some context (and so people can tell me if I'm barking up a completely wrong tree):

I have the situation where the user can insert a variable in a text view and meaningful placeholder text will be displayed, highlighted to indicate that it is a variable. While editing, I want the variable to be treated as a single character - if the user backspaces over the end of the variable, it should delete the entire variable; if they select into the variable text the entire variable text should be selected; etc. At print time the placeholder text is replaced with the "real" value of the variable (page number, print time,
etc).

My approach has been to store a variable as some placeholder text in the text storage, so it looks meaningful to the user, with a custom attribute indicating that it is a variable (and which variable it was), and to use a text delegate to manage the special behavior. That worked mostly; I had to subclass the text view to get nice text selection (the delegate method only gets called at mouse up, so the user could select part-way through the variable placeholder text, and the selection highlight wouldn't snap to engulf the entire variable until mouse up).

But I'm left with one problem: you can't have multiple instances of the same variable side-by-side. For instance, you can't insert the "page number" variable twice in a row with no separating space. Well, you can, but there's now no way to tell that they are intended to be two instances of the same variable - since the attribute name is the same and the attribute value is the same,
the two ranges get unioned in the attributed string (normally a good thing)
and it now gets treated as a single variable instance.

I thought I could get around this by having my variable marker in the text storage always be a single character, so if I get a text range marked with the variable attribute, I simply repeat the variable by the length of the effective range of the attribute. But I don't know how to go about handling this in the text system during editing - I need the placeholder text to be displayed for each character in the effective range, and I need to know the boundaries between the placeholder text to manage the user selection, etc.

Thoughts?

-andrew
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Dictionaries in IB
  • Next by Date: Re: Linking problems with PostgreSQL
  • Previous by thread: One line NSTextFieldCell
  • Next by thread: Implementing a "Column View"-like layout
  • Index(es):
    • Date
    • Thread