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

Enhancement: provide IndexRange for Paragraph #42

Closed
ghost opened this issue Apr 16, 2014 · 4 comments
Closed

Enhancement: provide IndexRange for Paragraph #42

ghost opened this issue Apr 16, 2014 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 16, 2014

Would it be possible to provide indexRange for a given paragraph. This is the use case:

I have a paragraph with multiple styled text objects, each has its own. I need to change one style parameter, for example size.

I am using the styles.mapStyles method. then I apply styles to the whole text area at a given range.

I need a way to know where the given paragraph starts or end in reference to the text area. I tried to figure it out but I could not reach a solution.

@TomasMikula
Copy link
Member

You can already do that using these methods
getStyleSpans(int paragraph, int from, int to)
setStyleSpans(int paragraph, int from, StyleSpans styleSpans)
e.g.

int par = area.getCurrentParagraph();
int parLen = area.getParagraphs().get(par).length();
StyleSpans<S> styles = area.getStyleSpans(par, 0, parLen);
StyleSpans<S> newStyles = styles.mapStyles(...);
area.setStyleSpans(par, 0, newStyles);

@ghost
Copy link
Author

ghost commented Apr 16, 2014

Nice! Thanks. That did it :D

On Wed, Apr 16, 2014 at 3:35 PM, TomasMikula notifications@github.comwrote:

Closed #42 #42.


Reply to this email directly or view it on GitHubhttps://github.com//issues/42
.

@TomasMikula
Copy link
Member

I added a convenience method, so the above code can now be rewritten as

int par = area.getCurrentParagraph();
StyleSpans<S> styles = area.getStyleSpans(par);
StyleSpans<S> newStyles = styles.mapStyles(...);
area.setStyleSpans(par, 0, newStyles);

@ghost
Copy link
Author

ghost commented Apr 17, 2014

Thanks! I just downloaded it. It works fine.

On Wed, Apr 16, 2014 at 4:31 PM, TomasMikula notifications@github.comwrote:

I added a convenience method, so the above code can now be rewritten as

int par = area.getCurrentParagraph();StyleSpans styles = area.getStyleSpans(par);

StyleSpans newStyles = styles.mapStyles(...);area.setStyleSpans(par, 0, newStyles);

Reply to this email directly or view it on GitHubhttps://github.com//issues/42#issuecomment-40665036
.

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