Skip to content

Bug: Broken Paste logic #4305

Closed
eclipse-jdtls/eclipse.jdt.ls
#3674

Description

@CookedMelon

Using this extension causes issues with the copy function in VS Code.

Step to Reproduce:

Create a file like test.java, the content is:

class test {
    private String function () {
        String a = "555\n555";
        a = "ggg";
        return a;
    }
}

Scenario A (Selection Paste): Use the mouse to select the \n characters (inside the double quotes), copy them, and attempt to paste them.

Scenario B (Line Copy/Paste): Place the cursor anywhere inside the double quotes (on the line String a = "\n";) without selecting any text. Use the VS Code shortcut Ctrl + C then Ctrl + V (intended to duplicate the entire line).

Expected Behavior:

Scenario A

Before Paste

Image

After Paste

Image

Scenario B

Before Paste

Image

After Paste

Image

Actual Behavior:

Scenario A

Image

Scenario B

If I place the cursor inside the double quotes

Image

I press ctrl c & ctrl v

Image

Activity

  1. fbricon commented on Jan 13, 2026

    @fbricon
    Collaborator

    The paste logic mostly does what it's supposed to do: escape the content before pasting it into a Java String (see #1249). So it will literally escape all new lines from the clipboard to insert into a compilable java String.
    What you're expecting is raw pasting, you can choose by either Ctrl+Shift+P, or selecting "Insert Plain Text"

    Image

    you can also disable Java smart pasting entirely with this setting:

    "[java]": {
            "editor.pasteAs.enabled": false
    }

    Now admittedly, at least one thing is not working as expected:

    • cursor anywhere on the a = "ggg"; line, then Ctrl+C then Ctrl+Shift+P (Insert plain text) inside the quotes doesn't just duplicate the line, but pastes the whole content into the existing line.
  2. fbricon commented on Jan 13, 2026

    @fbricon
    Collaborator

    @CookedMelon the proposed changes in #4306 should fix the duplicate line problem.

    Smart pasting could be improved so that pasting \n inside "555\n555" can turn into "555\n\\n555" (as in Eclipse), instead of aggressively adding a new line

    String a = "555\n\\n" + //
    						"555";
    

    But that needs to happen in https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/main/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PasteEventHandler.java#L279

  3. added this to the End January 2026 milestone on Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions