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

Lines appearing after coping and refilling text #141

Closed
spoeck opened this issue Apr 28, 2015 · 9 comments
Closed

Lines appearing after coping and refilling text #141

spoeck opened this issue Apr 28, 2015 · 9 comments

Comments

@spoeck
Copy link

spoeck commented Apr 28, 2015

Step 1:
I copy the text out of Java Keywords Demo and filling it into Notepad++. Everything perfect.

Step 2:
After that, I copy the text out of the Notepad++ and filling it into Java Keywords Demo. Everything perfect.

Step 3:
I repeat Step 1 and have the effect that between every code line is a empty line appearing.

@bigDevDe
Copy link

Hi Tomas,

I have the same problem! There are double line breaks after several copy and paste from/into the TextArea (in the TextArea these double linebreaks are not displayed, only outside in a text editor)

Regards Michael

@bigDevDe
Copy link

It seems like when you paste text into the area, then the line breaks are doubled...

@TomasMikula
Copy link
Member

This seems like a Windows-only problem. Or can anyone reproduce it on Mac or Linux? I only have Mac and Linux available.

The cause is likely the following two "features" not working well together:

  1. RichTextFX preserves whatever line terminator characters the file has. This means that if you insertText into the text area and then getText, you get the same String (no conversion of line terminators happens). This means, for example, that if you open a file with Unix line terminators (\n) on Windows and save it back, it will be saved with Unix line terminators.
  2. JavaFX clipboard seems to be converting \n to system-specific line terminators on copy and system-specific line terminators to \n on paste.

As a result, if you copy text with Windows line terminators (\r\n) on Windows, JavaFX clipboard converts \n to \r\n, resulting in \r\r\n. If you paste it right back, JavaFX clipboard undoes this, RichTextFX receives \r\n and recognizes it as a single Windows line terminator. If, however, you paste it to a non-Java program, the program receives \r\r\n and treats that as two line terminators (\r and \r\n).

@JordanMartinez
Copy link
Contributor

I downloaded the JavaKeywords demo and tested it on Linux. After doing the above method using Linux's GEdit (Text Editor) and again using a Word Processor (Kingsoft Writer), I didn't have the problem.

@TomasMikula
Copy link
Member

Thanks for testing, Jordan!

@bigDevDe
Copy link

Hi Tomas,

thanks for your reply. I really get double 0D0A0D0A (\r\n\r\n). Do you suggest a workaround?

@TomasMikula
Copy link
Member

The workaround would be to override Ctrl+C, Ctrl+X, Ctrl+V and do the right thing there. You would put the selected text to the clipboard, with all line terminators replaced by \n. This would be even easier to change in RichTextFX directly. However, it would mean that Ctrl+C immediately followed by Ctrl+V within RichTextFX could change the line terminators in the copy-pasted text, which I'm not sure is desired.

@bigDevDe
Copy link

Thank you for your reply, Tomas!

@hbrackmann
Copy link

another possible workaround using awt

codeArea.addEventFilter(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
                if (event.isControlDown() && event.getCode() == KeyCode.C){
                    java.awt.datatransfer.Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
                    java.awt.datatransfer.StringSelection stringSelection = new java.awt.datatransfer.StringSelection (messageContentCodeArea.getText());
                    clipboard.setContents(stringSelection, null);
                    event.consume();
                }
            }
        });

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

5 participants