Re: Providing citation data for a text view
Re: Providing citation data for a text view
- Subject: Re: Providing citation data for a text view
- From: Douglas Davidson <email@hidden>
- Date: Wed, 28 Jun 2006 17:55:38 -0700
On Jun 28, 2006, at 4:52 PM, D.K. Johnston wrote:
I want to display some read-only text in a text view, along with a
text field that shows citation information (e.g. chapter, section,
line numbers) for the selected line. Of course, the text field
should be updated every time the selected line changes. I was
thinking of using NSAttributedString, with the citation values for
each line embedded as an attribute; or perhaps creating an array
containing the citation values that is indexed somehow to the lines
of text displayed in the text view.
I'm sure I'm reinventing the wheel. Can anyone point me toward some
documentation, or example code, that deals with this kind of thing?
Depending on how your text view is set up as far as wrapping goes, a
displayed line of text may or may not correspond to a single "line"
in the sense of hard line breaks. If your information is strictly
based on hard line breaks (which the Cocoa text system usually deals
with as "paragraphs") then you can set up an auxiliary data structure
based on line numbers, but it's not completely trivial to write an
efficient mechanism to go from text to line numbers. If the text
really is read-only, then you can map from the index of the first
character in the line; given a position in the text, it's easy to
find out the line start. It would be more flexible to use
attributes, e.g. a chapter attribute set for the range of the entire
chapter, but might require extra work to make sure the attributes are
consistent, especially if the text ever does change. You can
probably find some code for handling line numbers if you search
mailing list archives.
Douglas Davidson
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden