Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getIndexRange() on StyledText in reference to text area. Enhancement suggestion #66

Closed
ghost opened this issue Jul 4, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 4, 2014

Hi Tomas, since paragraphs are styledText elements, would it be possible for the styledText to report its start position in reference to the text area? or example
styledText.getIndex()? something to go with the styledText.getStyle();
I can calculate it, but thought it would be convenient to provide such a method since the infra structure is already there.

@TomasMikula
Copy link
Member

StyledText instances are immutable (i.e. they don't have any fields that can change, such as index). They don't hold a reference to the text area they are used in. In fact, a single StyledText instance may be used in more than one text area at the same time, at different positions. Therefore, it does not make sense for StyledText to have an index. You should think of StyledText as just a String with an associated style. The same String instance can be used in many different places in your Java program, and the String itself is not aware of where it is being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant