TextEdit (and most other implementations) supports mixed-directional text -- i.e., a combination of scripts having left-to-right and right-to-left text within a single line. You can usually rely on TextEdit to properly configure your insertion point. In a left-to-right system, when the insertion point is somewhere within a style run, the style you apply at the insertion point should be the same as the style that is already in effect for the run (for example, bold-12-point-geneva). However, the correct style isn't as easy to identify at the boundaries between runs. When you are between two style runs in a left-to-right system, the style associated with the run on the left is usually applied. This rule is essentially the same for right-to-left script systems, except that, at a boundary between runs, you use the style associated with the run on the right.
Unfortunately, it is more difficult to determine the correct style when you are at a boundary where left-to-right text meets right-to-left text. The best technique in this situation is to programmatically choose the style based on the exact point where the user clicks (if in the right-to-left run, use the style associated with this run; otherwise, use the style associated with the l-to-r run). A similar approach should be taken for situations where the user clicks in a boundary between two styles -- choose the style associated with the run closest to the place they click.
When there are multiple style runs within a selection, the style added should
be added across the entire selection. In this situation, selecting bold from a
style menu would apply bold to all characters in the run. If the user selects a
range and enters some new text (replacing the range), apply the style
associated with the first character in the run (bearing in mind that the first
character of the selection is the left-most character if the script for the
selection is left-to-right, and the right-most character if the script for the
selection is right-to-left).
For additional information on this and for other text-related questions, see
Inside Macintosh: Text. There is an electronic version on the Developer
CD: Reference Library Edition.
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help