{"action":"created","issue":{"url":"https://api.github.com/repos/TomasMikula/RichTextFX/issues/183","labels_url":"https://api.github.com/repos/TomasMikula/RichTextFX/issues/183/labels{/name}","comments_url":"https://api.github.com/repos/TomasMikula/RichTextFX/issues/183/comments","events_url":"https://api.github.com/repos/TomasMikula/RichTextFX/issues/183/events","html_url":"https://github.com/TomasMikula/RichTextFX/issues/183","id":108527265,"number":183,"title":"Line terminator problems on Windows","user":{"login":"JFormDesigner","id":12702749,"avatar_url":"https://avatars.githubusercontent.com/u/12702749?v=3","gravatar_id":"","url":"https://api.github.com/users/JFormDesigner","html_url":"https://github.com/JFormDesigner","followers_url":"https://api.github.com/users/JFormDesigner/followers","following_url":"https://api.github.com/users/JFormDesigner/following{/other_user}","gists_url":"https://api.github.com/users/JFormDesigner/gists{/gist_id}","starred_url":"https://api.github.com/users/JFormDesigner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JFormDesigner/subscriptions","organizations_url":"https://api.github.com/users/JFormDesigner/orgs","repos_url":"https://api.github.com/users/JFormDesigner/repos","events_url":"https://api.github.com/users/JFormDesigner/events{/privacy}","received_events_url":"https://api.github.com/users/JFormDesigner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-27T10:16:28Z","updated_at":"2015-09-28T22:15:17Z","closed_at":null,"body":"Hi Thomas,\r\n\r\nThe commit b03e1cc2971884a42ee9ff32d67ac0a2325574f9 causes some new problems with \\r\\n handling on Windows.\r\n\r\na) Pasting some multiline text (from notepad.exe) throws following exception **when pasting it twice**:\r\n```\r\nC:\\Users\\charly\\Downloads>\"C:\\Program Files\\Java\\jdk1.8.0_60\\bin\\java\" -cp richtextfx-demos-fat-0.6.9.jar org.fxmisc.richtext.demo.JavaKeywords\r\nException in thread \"JavaFX Application Thread\" java.lang.StringIndexOutOfBoundsException: String index out of range: -2\r\n        at java.lang.String.substring(String.java:1967)\r\n        at org.fxmisc.richtext.Paragraph.substring(Paragraph.java:73)\r\n        at org.fxmisc.richtext.StyledDocumentBase.sub(StyledDocumentBase.java:245)\r\n        at org.fxmisc.richtext.StyledDocumentBase.getText(StyledDocumentBase.java:51)\r\n        at org.fxmisc.richtext.EditableStyledDocument.lambda$null$22(EditableStyledDocument.java:129)\r\n        at org.reactfx.util.Tuple2.map(Tuple2.java:31)\r\n        at org.fxmisc.richtext.EditableStyledDocument.lambda$new$23(EditableStyledDocument.java:129)\r\n        at org.reactfx.MappedStream.lambda$observeInputs$201(MappedStream.java:22)\r\n        at org.reactfx.util.NonAccumulativeStreamNotifications.lambda$head$272(NotificationAccumulator.java:134)\r\n        at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)\r\n        at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)\r\n        at org.reactfx.ProperEventStream.emit(ProperEventStream.java:18)\r\n        at org.reactfx.EventStreams$20.tryEmit(EventStreams.java:441)\r\n        at org.reactfx.EventStreams$20.lambda$observeInputs$36(EventStreams.java:436)\r\n        at org.reactfx.util.NonAccumulativeStreamNotifications.lambda$head$272(NotificationAccumulator.java:134)\r\n        at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)\r\n        at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)\r\n        at org.reactfx.ProperEventStream.emit(ProperEventStream.java:18)\r\n        at org.reactfx.EventSource.push(EventSource.java:18)\r\n        at org.fxmisc.richtext.EditableStyledDocument.replace(EditableStyledDocument.java:454)\r\n        at org.fxmisc.richtext.EditableStyledDocument.replaceText(EditableStyledDocument.java:192)\r\n        at org.fxmisc.richtext.StyledTextArea.replaceText(StyledTextArea.java:720)\r\n        at org.fxmisc.richtext.TextEditingArea.replaceText(TextEditingArea.java:204)\r\n        at org.fxmisc.richtext.EditActions.replaceSelection(EditActions.java:119)\r\n        at org.fxmisc.richtext.ClipboardActions.paste(ClipboardActions.java:97)\r\n        at org.fxmisc.richtext.skin.StyledTextAreaBehavior.lambda$static$69(StyledTextAreaBehavior.java:65)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate$On.lambda$null$23(EventHandlerTemplate.java:156)\r\n        at java.util.Optional.ifPresent(Optional.java:159)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate$On.lambda$act$24(EventHandlerTemplate.java:155)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate$Builder.lambda$create$21(EventHandlerTemplate.java:117)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate.lambda$null$17(EventHandlerTemplate.java:39)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate.lambda$null$15(EventHandlerTemplate.java:26)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate.lambda$null$19(EventHandlerTemplate.java:49)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate.lambda$null$15(EventHandlerTemplate.java:26)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate.lambda$null$15(EventHandlerTemplate.java:26)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate.lambda$null$15(EventHandlerTemplate.java:26)\r\n        at org.fxmisc.wellbehaved.event.EventHandlerTemplate.lambda$bind$14(EventHandlerTemplate.java:18)\r\n        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)\r\n        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)\r\n        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)\r\n        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)\r\n        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)\r\n        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)\r\n        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)\r\n        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)\r\n        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)\r\n        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)\r\n        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)\r\n        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)\r\n        at javafx.event.Event.fireEvent(Event.java:198)\r\n        at javafx.scene.Scene$KeyHandler.process(Scene.java:3964)\r\n        at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910)\r\n        at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)\r\n        at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501)\r\n        at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:197)\r\n        at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:147)\r\n        at java.security.AccessController.doPrivileged(Native Method)\r\n        at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$354(GlassViewEventHandler.java:228)\r\n        at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)\r\n        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:227)\r\n        at com.sun.glass.ui.View.handleKeyEvent(View.java:546)\r\n        at com.sun.glass.ui.View.notifyKey(View.java:966)\r\n        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)\r\n        at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)\r\n        at java.lang.Thread.run(Thread.java:745)\r\n```\r\n\r\nb) `EditableStyledDocument.getLength()` returns a too large length (including \\r characters)\r\n```java\r\n@Test\r\npublic void testWinDocumentLength() {\r\n    EditableStyledDocument<String> document = new EditableStyledDocument<>(\"\");\r\n    document.replaceText(0, 0, \"X\\r\\nY\");\r\n    assertEquals(document.getText().length(), document.getLength());\r\n}\r\n```\r\nthrows `java.lang.AssertionError: expected:<3> but was:<4>`\r\n\r\n\r\nc) after pasting a text that contains \\r characters, the caret is not at the end of the pasted text. It is some characters behind it, which depends on the number of \\r characters in the pasted text.\r\n\r\nd) Undo after pasting a text that contains \\r characters removes too many text.\r\n\r\n\r\nLooking at the source code, one reason may be the usage of `text.length()` where `text` contains \\r characters, but paragraphs no longer contain them. There several places. E.g.\r\n\r\n* https://github.com/TomasMikula/RichTextFX/blob/master/richtextfx/src/main/java/org/fxmisc/richtext/EditableStyledDocument.java#L473\r\n* https://github.com/TomasMikula/RichTextFX/blob/master/richtextfx/src/main/java/org/fxmisc/richtext/EditableStyledDocument.java#L196\r\n* https://github.com/TomasMikula/RichTextFX/blob/master/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java#L722\r\n\r\nDon't know how to fix this best. Maybe always do `text.replace(\"\\r\\n\", \"\\n\")` on all inserted strings.\r\n\r\nKarl"},"comment":{"url":"https://api.github.com/repos/TomasMikula/RichTextFX/issues/comments/143888988","html_url":"https://github.com/TomasMikula/RichTextFX/issues/183#issuecomment-143888988","issue_url":"https://api.github.com/repos/TomasMikula/RichTextFX/issues/183","id":143888988,"user":{"login":"TomasMikula","id":433439,"avatar_url":"https://avatars.githubusercontent.com/u/433439?v=3","gravatar_id":"","url":"https://api.github.com/users/TomasMikula","html_url":"https://github.com/TomasMikula","followers_url":"https://api.github.com/users/TomasMikula/followers","following_url":"https://api.github.com/users/TomasMikula/following{/other_user}","gists_url":"https://api.github.com/users/TomasMikula/gists{/gist_id}","starred_url":"https://api.github.com/users/TomasMikula/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomasMikula/subscriptions","organizations_url":"https://api.github.com/users/TomasMikula/orgs","repos_url":"https://api.github.com/users/TomasMikula/repos","events_url":"https://api.github.com/users/TomasMikula/events{/privacy}","received_events_url":"https://api.github.com/users/TomasMikula/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T22:15:17Z","updated_at":"2015-09-28T22:15:17Z","body":"Thanks for providing a test case. I fixed your point b) in a recent commit. Not sure how it affects the other points. Would be great if you could try it out. Obviously, there's no release with this fix yet, but I updated the [1.0.0-SNAPSHOT](https://github.com/TomasMikula/RichTextFX#snapshot-releases), if you want to give it a try."}}