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

Error: When I set style to the second line, I get IndexOutOfBoundsException #741

Closed
saifalmutory opened this issue May 5, 2018 · 1 comment

Comments

@saifalmutory
Copy link

saifalmutory commented May 5, 2018

seText is InlineCssTextArea
Here I try to set the style by selecting the first line :
seText.setStyle(seText.getCurrentParagraph(),seText.getSelection().getStart(),seText.getSelection().getEnd(),ControlColorPane.getSelectedColor());
System.out.println(seText.getSelection());
I get good results
capture

Output : 0, 5
But when I select the second line ans try changing the color
capture2
Get Caused by: java.lang.IndexOutOfBoundsException: [6, 11) is not a valid range within [0, 5)
Output : 6, 11
and the style does not change either

@JordanMartinez
Copy link
Contributor

Based on that error message, I believe you're passing in the wrong arguments...

public void setStyle(int paragraphIndex, int columnPositionStart, int columnPositionEnd) {}

columnPositionStart and columnPositionEnd expect to be a value x that is 0 <= x <= area.getParagraphLength(paragraphIndex).

However, you're passing in seText.getSelection().getStart() and seText.getSelection().getEnd(). This issue does not occur in the first example because the selection just happens to be the same values as the one you need (i.e. the start position is 0 and the end position is equal to the paragraph length). However, once you add another line, that is no longer the case. Your start position is in terms of the area's position, not the paragraph's position.

You should just use area.setStyle(getSelection().getStart(), getSelection().getEnd(), style)

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

2 participants