• 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
Re: Saving position in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving position in NSTextView


  • Subject: Re: Saving position in NSTextView
  • From: Douglas Davidson <email@hidden>
  • Date: Fri, 4 Dec 2009 10:02:56 -0800


On Dec 4, 2009, at 9:30 AM, Pascal Harris wrote:

I am writing an application which, amongst other things, can be used to read text files. These text files are rather long (could be more than 1MB), which isn't convenient for anyone to read in one sitting. The text files are not editable. I would like to be able to save the position in the text file so that a reader can come back to file at a later time and not have to hunt for the last sentence that they read.

My research shows that I can do half of what I need using NSRange - using scrollRangeToVisible it seems that I can scroll to a given range (allowing the reader to resume where they left off). Sadly, I can't work out how I can save a range without the reader selecting text in the window first (hardly user friendly!). I need this to work invisibly - i.e. the user closes the window, or the app, and when the window is reopened Presto! the window contains the same view of the text as it did previously.

If I understand correctly, what you want to be able to determine is the range of text that is currently visible. This can be a bit tricky, since depending on the arrangement of text, the visible text might not be a single contiguous range in the document, but one way to do this is to get the text view's visibleRect, convert it into container coordinates (by subtracting the textContainerOrigin), ask the layout manager for glyphRangeForBoundingRect:inTextContainer:, and convert the resulting glyph range to a character range.


Douglas Davidson

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Saving position in NSTextView (From: Pascal Harris <email@hidden>)

  • Prev by Date: Re: Best way to hook into the run loop?
  • Next by Date: seg fault or not?
  • Previous by thread: Saving position in NSTextView
  • Next by thread: seg fault or not?
  • Index(es):
    • Date
    • Thread