-
Notifications
You must be signed in to change notification settings - Fork 236
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
Out of bounds error on applying style to a selection #43
Comments
not able to reproduce it again though... |
Thanks for reporting. I can see the problem. It occurs when the selection ends at the very beginning of a line. And yes, it is related to line terminators. |
cool! On Fri, Apr 18, 2014 at 6:53 PM, TomasMikula [email protected]:
|
will give it a shot it now On Fri, Apr 18, 2014 at 8:05 PM, TomasMikula [email protected]:
|
Got another error: Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: 37 not in [0, 27] |
Can you post steps to reproduce the problem? Are you sure you are passing a valid range (i.e. within document bounds) to I added some range checks to the code. They will not fix the problem, just make it fail faster if you pass invalid range. |
Found out why. this is the process: 1-I am trying to allow the user to store text values--each is a styled document (so it has many styles for example). 2-the user can swap the strings between these styled documents. To get around the issue of length, i am doing a replace, and I require that a selection is made. and I keep refreshing the selection, by a "selectRange" method. I pull the segments from an array,, and i call it "scrolTempSegment". this is the code:
|
I don't understand what exactly you are trying to do, but I suspect at least one problem with this code: Also, I don't know what exactly Maybe this will do what you are trying to do: rangeOfSelection = richTextArea.getSelection();
StyleSpans<String> styles = richTextArea.getStyleSpans(rangeOfSelection);
richTextArea.replaceText(rangeOfSelection, scrollTemSegment.plainText);
int start = rangeOfSelection.getStart();
int newTextLen = scrollTemSegment.plainText.length();
rangeOfSelection = new IndexRange(start, start + newTextLen);
richTextArea.selectRange(rangeOfSelection);
int len = Math.min(newTextLen, styles.length());
richTextArea.setStyleSpans(start, styles.subView(0, len)); But note that if |
Yes this works without errors. Thanks! This is the use case: |
the getStyledTextElements was a method that I ended up not using I guess... The StyledTextElement is basically an styledText but with some additional information, like where it starts and ends, it styles, which view port it came from, etc. This info will be used for saving a file format, that I haven't got into yet . Also, I using it to construct textflow objects so that I can use them as graphic nodes for a tree menu item. Kind of reverse engineering. |
I was applying a style to a selection. after this selection there was a couple of new lines.. so I guess it has to do with the line terminator?
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: 6 not in [0, 6)
at org.fxmisc.richtext.Paragraph.subSequence(Paragraph.java:229)
at org.fxmisc.richtext.Paragraph.restyle(Paragraph.java:262)
at org.fxmisc.richtext.EditableStyledDocument.setStyleSpans(EditableStyledDocument.java:257)
at org.fxmisc.richtext.StyledTextArea.setStyleSpans(StyledTextArea.java:522)
at TextComponentElements.TextEditor.applySizeToSelection(TextEditor.java:1336)
at TextComponentElements.TextEditor.applySize(TextEditor.java:1321)
at TextComponentElements.TextEditor$32.handle(TextEditor.java:889)
at TextComponentElements.TextEditor$32.handle(TextEditor.java:885)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:204)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3456)
at javafx.scene.Scene$ClickGenerator.access$8300(Scene.java:3387)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3755)
at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)
at com.sun.glass.ui.View.handleMouseEvent(View.java:526)
at com.sun.glass.ui.View.notifyMouse(View.java:898)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
at java.lang.Thread.run(Thread.java:744)
The text was updated successfully, but these errors were encountered: