Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8087545

Line separator is broken in the clipboard of WebView

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u45
    • javafx
    • None
    • Windows 7

    • web

      In WebView, If you use the clipboard perform inter-process communication, it is broken line separator of multi-line text.

      Input: 123 [LF] 456 [LF] 789

      In the case of the same process: 123 [CR] [LF] 456 [CR] [LF] 789
      In the case of different processes: 123 [CR] [CR] [LF] 456 [CR] [CR] [LF] 789


      This problem makes it difficult to interoperability of the desktop application.

      Start two following test applications at the same time, you can see the problem by using the clipboard.

      test code:

      WebViewClipboardTest .java
      -----------------------------------
      import javafx.animation.KeyFrame;
      import javafx.animation.Timeline;
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.TextArea;
      import javafx.scene.input.Clipboard;
      import javafx.scene.layout.VBox;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;
      import javafx.util.Duration;


      public class WebViewClipboardTest extends Application{

      @Override
      public void start(Stage stage) throws Exception {
      VBox pane = new VBox();
      WebView browser = new WebView();
      TextArea textArea = new TextArea();

      String html = "<html><body><h1>TEST-1: text</h1>123<br>456<br>789<h1>TEST-2: pre</h1><pre>123\n456\n789</pre><h1>TEST-3: textarea</h1><textarea rows=5>123\n456\n789</textarea></body></html>";
      browser.getEngine().loadContent(html);
      pane.getChildren().addAll(browser, new Label("Clipboard:"), textArea);
      Scene scene = new Scene(pane);
      stage.setScene(scene);
      stage.show();

      Timeline monitor = new Timeline(new KeyFrame(Duration.millis(200), new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent event) {
      Clipboard clipboard = Clipboard.getSystemClipboard();
      if(clipboard.hasString()){
      final String text = clipboard.getString()
           .replace("\r", "[CR]")
      .replace("\n", "[LF]");
      textArea.setText(text);
      //clipboard.clear();
      }
      }
      }));
      monitor.setCycleCount(Timeline.INDEFINITE);
      monitor.play();

      stage.show();
      }

      public static void main(String[] args) {
      WebViewClipboardTest.launch(args);
      }
      }

            dkumar Dipak Kumar (Inactive)
            nyoshimotjfx Naohiro Yoshimoto (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: