Quantcast

Typing multiple lines while in quotes vs copy/pasting multiple lines while in quotes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Typing multiple lines while in quotes vs copy/pasting multiple lines while in quotes

rwilson352
Hi, I've noticed that Netbeans acts differently when you type multiple lines while in a String quotes vs when you copy/paste in a String quotes. For the first, it automatically adds a '+' at the front of the next line, whereas for the second, it adds the '+' at the end of the next line. Also, the copy/paste adds '/n' automatically, but it doesn't indent the code properly.

My question is: is this normal? Perhaps this feature needs some attention?

Here is an illustration:


Code:
    public static void main(String[] args) {
        String largeText = "This is what happens"
                + "if I type text but while typing"
                + "I manually press enter while my"
                + "cursor is within the quotes. It"
                + "automatically adds a '+' and"
                + "quotes on the next line.";
        String largeText2 = "But this is what happens if\n" +
"I copy paste a large block\n" +
"of text into the quotes. It\n" +
"adds a '+' sign onto the\n" +
"end of the line, unlike if\n" +
"you were to type and press\n" +
"enter.";
    }







Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Typing multiple lines while in quotes vs copy/pasting multiple lines while in quotes

Sean Carrick-4
rwilson,

The fact that NB automatically indents the next line when you type a hard return is to be expected, because the editor is following what you are doing. When you paste in text that is broken onto several lines, the editor may not know what else is with the text, and therefore the text gets pasted at the left margin. All you need to do to fix the appearance of the code is to select and click the indent block button on the editor toolbar. When you do, the pasted text should indent to the level that it should be according to the indentation of the code preceding it.

There's already quite a bit of logic built into the editor that surrounds the pasted code with quotation marks. The reason I say "logic" is because if you were to paste in the following:

for (int x = 0; x < 10; x++) {
    System.out.println("x = " + x);
}

the text would not be surrounded by quotations. This is NB's intelligence system gleaning what the pasted text is and acting appropriately. 

However, if you would like to see the functionality that you have described with the pasted text being surrounded by quotes and indented to the proper level, you could always write an editor plugin to lex that functionality out.

The way NB's intelligence works is fantastic for 90-95% of all use cases and way better than most other IDEs that are out there.

-- 
photo 
Sean Carrick
VP Software Development, Integrity Solutions 
<a href="tel:(309) 989-0672" style="color: rgb(141, 141, 141); text-decoration: none;">(309) 989-0672 | [hidden email] 

On Sun, 2017-02-19 at 19:18 +0000, rwilson352 wrote:
Hi, I've noticed that Netbeans acts differently when you type multiple lines while in a String quotes vs when you copy/paste in a String quotes. For the first, it automatically adds a '+' at the front of the next line, whereas for the second, it adds the '+' at the end of the next line. Also, the copy/paste adds '/n' automatically, but it doesn't indent the code properly.

My question is: is this normal? Perhaps this feature needs some attention?

Here is an illustration:


Code:
    public static void main(String[] args) {
        String largeText = "This is what happens"
                + "if I type text but while typing"
                + "I manually press enter while my"
                + "cursor is within the quotes. It"
                + "automatically adds a '+' and"
                + "quotes on the next line.";
        String largeText2 = "But this is what happens if\n" +
"I copy paste a large block\n" +
"of text into the quotes. It\n" +
"adds a '+' sign onto the\n" +
"end of the line, unlike if\n" +
"you were to type and press\n" +
"enter.";
    }







Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Typing multiple lines while in quotes vs copy/pasting multiple lines while in quotes

wadechandler
Administrator
In reply to this post by rwilson352
My guess is you copied lines versus a contiguous string. Were you typing you could have chosen to plugin \n or not.

I have a plugin called Java Text Copy and Paste that has options for some of what you would want I believe. I don't know if the editors have yet to mark it for 8.2, but you can definitely get it from the plugin portal on netbeans.org.

Wade

On Feb 19, 2017 5:40 PM, "rwilson352" <[hidden email]> wrote:
Hi, I've noticed that Netbeans acts differently when you type multiple lines while in a String quotes vs when you copy/paste in a String quotes. For the first, it automatically adds a '+' at the front of the next line, whereas for the second, it adds the '+' at the end of the next line. Also, the copy/paste adds '/n' automatically, but it doesn't indent the code properly.

My question is: is this normal? Perhaps this feature needs some attention?

Here is an illustration:


Code:
    public static void main(String[] args) {
        String largeText = "This is what happens"
                + "if I type text but while typing"
                + "I manually press enter while my"
                + "cursor is within the quotes. It"
                + "automatically adds a '+' and"
                + "quotes on the next line.";
        String largeText2 = "But this is what happens if\n" +
"I copy paste a large block\n" +
"of text into the quotes. It\n" +
"adds a '+' sign onto the\n" +
"end of the line, unlike if\n" +
"you were to type and press\n" +
"enter.";
    }








====================
Wade Chandler

Software Engineer
NetBeans and Open Source Contributor
Loading...