[plt-scheme] Custom style ranges in text%
I need to associate arbitrary data with ranges of text in a text%
subclass, and those ranges ought to work analogous to normal text
styles, i.e. they should allow overlapping, automatically get adjusted
when a user edits text, etc. So they are sort of custom styles, though
not necessarily changing visible properties of the text. (They usually
would have a background color.) Additionally, I need to be able to get
all custom styles associated with a certain region, get the start and
end of a given a custom style found at a given snip position, and the
editor ought to save and load the custom styles to/from disk.
So far, I'm unsure how to implement this, because I've still got
troubles understanding some of the concepts in text% editors. Could
somebody tell me which of the following approaches would work:
1. Custom Styles: Put a new named style into the editor's style list,
use change-style to add it or a derived delta of it to a range.
Problem: How can I find all such styles at a given position? How would
I find the start and end of such a style from a given position within
the range---except for looping back and forth?
2. Set-region-data/get-region-data: Set the data to a range given those
commands. Problem: What kind of data can a default editor-data% object
hold? I mean, it can't hold arbitrary data since it writes the data to
a stream, but the kind of data it holds is not documented. Is it
mandatory to derive a subclass , as well as of editor-data-class%?
Get-region-data returns just an editor-data% object, not a list of
them. So how can I get all the data I've stored in overlapping regions?
3. Custom solution: Write my own handling of ranges, updating
dynamically upon edit operations. Problem: Looks too complicated and
error-prone for me.
Any ideas?
Best regards,
Erich