Ctrl+Shift+Enter complete statement feature discussion

I few time ago we've implemented long living request that allows user insert
missing parens, semicolons, close string literals and start with a new
statement with a single keystroke.
After some usage I found myself not using this feature for quite a simple
reason: I do not usually want to start new statement after completing the
current one. Sample:

void foo() {
System.out.println("One");
System.out.println("Two|
System.out.println("Three");
}

I obviously do not need new line between lines where "Two" and "Three"
printed.
So I'd propose to change the intention of that action so it inserts whatever
it can where that needed and leaves the caret where it was.

On other hand current behavior is quite natural in the following case:

void foo() {
if (something|
}

to be converted to

void foo() {
if (something) {
|
}
}

What do you guys think?
--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"



0

Maxim Shafirov wrote:

What do you guys think?


Can you not make a distinction on completing a statement versus
completing something that introduces a block? If so, then you could
handle both cases.

Jon

0

I think that distiction could be made, but the default should be to have the insertion point at the end of the line. I find it easier to hit return again than the delete several times(indents)...

--pete

0

I agree, don't open a new line and stay right after the ;
Not afraid to sound like a broken record ;)))) what about the incremental
mode described in
(http://www.intellij.net/tracker/idea/viewSCR?publicId=3254)? I believe that
it would be nice for complex expression coupled with the highlighting of the
matching brace/quote/... It is pretty much like Ctrl-W for closing group. I
won't have to try 3 times to type ] because I want to learn how to do it
without looking and always type the wrong character ;) I will just learn
one key sequence to type ' " ] } )

Jacques

"Peter Morelli" <jiveadmin@jetbrains.com> wrote in message
news:989175.1049484333525.JavaMail.javamailuser@localhost...

I think that distiction could be made, but the default should be to have

the insertion point at the end of the line. I find it easier to hit return
again than the delete several times(indents)...
>

--pete



0

Perhaps a new line should only be inserted when either a) a block is being introduced (as mentioned earlier) or b) the last statement in a block is being edited. So to illustrate (b), in the case of:

10) {
   System.out.println("x is more than 10|
}]]>

CtrlShiftEnter produces:

10) {
   System.out.println("x is more than 10");
   |
}]]>

This is because it's likely I want to introduce more code after the statement. We could say we're in 'code writing' mode, where lots of lines are produced after each other.

(As an aside, a feature request I filed recently is relevant at this point. If the statement is like 'return' or 'throw', i.e., causing a block to be stepped-out of, then the behaviour should be different. See:

http://www.intellij.net/tracker/idea/viewSCR?publicId=11148 )


Back to the story :). In the case of

10) {
   System.out.println("I have deduced that |   
   System.out.println("x is more than 10");
}]]>

it is changed to simply

10) {
   System.out.println("I have deduced that ");|
   System.out.println("x is more than 10");
}]]>

This is because we're in 'code editing' mode, where we're introducing probably single lines among existing ones.

0

As an addendum to my previous posting:

At the moment, there is no defined action for CtrlShiftEnter when there is no statement to be completed. What about making this work as follows:

if (x>10) {
System.out.println("x is more than 10|
}

goes to

if (x>10) {
System.out.println("x is more than 10");
|
}

As before. But I propose pressing it again goes to

if (x>10) {
System.out.println("x is more than 10");
}


So it's an 'exit block' command, which tidies up any blank newlines that it might have left behind. In the 'edit mode' case:

if (x>10) {
System.out.println("I deduce that ");
System.out.println("x is more than 10

System.out.println("hope this is useful");
}

would go to

if (x>10) {
System.out.println("I deduce that ");
System.out.println("x is more than 10");
System.out.println("hope this is useful");
}
|

What do you think? Maybe this is over-complicating matters. But I think my original idea is worth discussing.

0

I really like both ideas of yours. Let's try them!

Jacques

0

looks "natural" and handy.

"Ben Pickering" <benp@marketing.net.uk> wrote in message
news:22131127.1049547996444.JavaMail.jrun@is.intellij.net...

As an addendum to my previous posting:

>

At the moment, there is no defined action for CtrlShiftEnter when there

is no statement to be completed. What about making this work as follows:
>

if (x>10) {
System.out.println("x is more than 10|
}

>

goes to

>

if (x>10) {
System.out.println("x is more than 10");
|
}

>

As before. But I propose pressing it again goes to

>

if (x>10) {
System.out.println("x is more than 10");
}
|

>

So it's an 'exit block' command, which tidies up any blank newlines that

it might have left behind. In the 'edit mode' case:
>

if (x>10) {
System.out.println("I deduce that ");
System.out.println("x is more than 10|
System.out.println("hope this is useful");
}

>

would go to

>

if (x>10) {
System.out.println("I deduce that ");
System.out.println("x is more than 10");
System.out.println("hope this is useful");
}
|

>

What do you think? Maybe this is over-complicating matters. But I think

my original idea is worth discussing.


0

Though sounds interesting I'm affraid this behavior is not somewhat
predictable. It does not seem obvious behavior depends on whether we're on
the last statement (or even last reachable statement) in the block. On other
hand I think it isn't that hard to press <CtrlShiftEnter>+]]> to start
a new statement.
--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"



0

I'm still think that typing:

if (x) { return |

and pressing CtrlShiftEnter going to

if (x) {return;}
|

is desirable. I do this all the time.

0

I'm curious, but is there a reason to maintain the existing ctrl-Enter
behavior?

Couldn't you fold these together, so that Ctrl-Enter finishes the line and
starts a new one, while Ctrl-Shift-Enter just finishes the line? Maybe
Ctrl-Alt-Enter could finish the line and exit the current block? Is there a
reason to want to open a new line and start a new line without finishing the
current one?

Just thought...

"Maxim Shafirov" <max@intellij.net> wrote in message
news:b6pba5$983$1@is.intellij.net...

Though sounds interesting I'm affraid this behavior is not somewhat
predictable. It does not seem obvious behavior depends on whether we're on
the last statement (or even last reachable statement) in the block. On

other

hand I think it isn't that hard to press <CtrlShiftEnter>+<Enter> to

start

a new statement.
--

>

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"

>
>
>


0

What about making the single keystroke be seen by 'undo' as two? That way,
hitting Ctrl-Shift-Enter would finish the line and open a new line. If you
hit Ctrl-Z then the new line part would be undone, and Ctrl-Z again would
undo the finish line. That might not be ideal, but it'd work...

"Maxim Shafirov" <max@intellij.net> wrote in message
news:b6khmf$gm0$1@is.intellij.net...

I few time ago we've implemented long living request that allows user

insert

missing parens, semicolons, close string literals and start with a new
statement with a single keystroke.
After some usage I found myself not using this feature for quite a simple
reason: I do not usually want to start new statement after completing the
current one. Sample:

>

void foo() {
System.out.println("One");
System.out.println("Two|
System.out.println("Three");
}

>

I obviously do not need new line between lines where "Two" and "Three"
printed.
So I'd propose to change the intention of that action so it inserts

whatever

it can where that needed and leaves the caret where it was.

>

On other hand current behavior is quite natural in the following case:

>

void foo() {
if (something|
}

>

to be converted to

>

void foo() {
if (something) {
|
}
}

>

What do you guys think?
--

>

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"

>
>
>


0

Sorry Paul I have to disagree. Try typing very fast Ctrl-Shift-Enter + Enter and Ctrl-Shift-Enter + Ctrl-Z. I bet you will find the first one very easy to get used to. The second one though will be harder. The first one you do not move your fingers. The second one you do.
Call me lazy but it is too much effort and in usability effort is king!

Jacques

0

What happens more often: entering a single line or multiple lines? I would prefer the following solution:

Pressing <Ctrl-Shift-Enter> on an empty line will
remove this line and go to the end of the previous line.

So

if (x>10) {
System.out.println("I deduce that ");
System.out.println("x is more than 10|
System.out.println("hope this is useful");
}

goes to

if (x>10) {
System.out.println("I deduce that ");
System.out.println("x is more than 10");


System.out.println("hope this is useful");
}

Pressing <Ctrl-Shift-Enter> now will "undo" the enter
which will result in

if (x>10) {
System.out.println("I deduce that ");
System.out.println("x is more than 10");

System.out.println("hope this is useful");
}

This behaviour is better if the 'code write' mode
is your "default" mode. When writing new code you have to press only one key. In 'edit mode' you have only have to press the same key twice.

0

Pressing <Ctrl-Shift-Enter> on an empty line will
remove this line and go to the end of the previous
line.


IMHO It does not seem logical that pressing Enter in some cases removes a line. Enter should only insert a new line or complete the current line.

Sincerely

Jens Peter Grosen

0

Yes, but look at hit this way: one does the first one all the time, the
second one only rarely. I don't want to have to press Ctrl-Shift-Enter +
Enter all the time, at the end of each and every line. That would be very
annoying, and would really reduce the usefulness of Ctrl-Shift-Enter
(frankly, I want Ctrl-Shift-Enter to be just my plain "Enter" in my keymap).
At any rate, if I don't want the new blank line, a simple delete-line
command (however you have that mapped) or a ctrl-z could eliminate it.
This, at least for me, would happen much less often than wanting to actually
insert a new line.

However, I really think the best solution is to just have two key maps. One
that functions as "complete the line and enter" and one that functions as
"complete the line".

"Jacques Morel" <jacmorel@yahoo.com> wrote in message
news:19253663.1049824599245.JavaMail.jrun@is.intellij.net...

Sorry Paul I have to disagree. Try typing very fast Ctrl-Shift-Enter +

Enter and Ctrl-Shift-Enter + Ctrl-Z. I bet you will find the first one very
easy to get used to. The second one though will be harder. The first one you
do not move your fingers. The second one you do.

Call me lazy but it is too much effort and in usability effort is king!

>

Jacques



0

For the same reason that I brought up before I prefer C-S-Enter+Enter more than C-S-Enter + C-Z or C-S-Enter + C-Backspace. Which one I am going to do more often (you are probably right) isn't the only thing important. The amount of effort each one requires has to factor in. The fact that I didn't use C-S-Enter + C-BackSpace (and it seems Maxim as well) tells me that to learn this way is still too much. It is just more intuitive and easier to hit another time Enter (your pickie is right on top of it) than to remember that C-BackSpace remove all whitespace and move your pickie up 2 rows to hit backspace (which I miss about 50% of the time).

However in the end I agree. Having both actions and letting the user remap the appropriate action to Ctrl-Shift-Enter or having an IDEA option governing the addition of the new line would meet everybody's need. I might also discover that I am wrong... again ;)

Jacques

0

However in the end I agree. Having both actions and
letting the user remap the appropriate action to
Ctrl-Shift-Enter or having an IDEA option governing
the addition of the new line would meet everybody's
need.


I agree with this. Two actions: 'complete only' and 'complete with newline' would satisfy me. I still think I'd use some of the other things, however, like the automatic exit block, and the 'complete, go to next parameter' feature request. Perhaps I'll write a plugin :)

I might also discover that I am wrong... again


Well, you have one supporter.

0

Hi gentlemen

"Jacques Morel" <jacmorel@yahoo.com> wrote:
news:5428447.1049933141442.JavaMail.jrun@is.intellij.net...

For the same reason that I brought up before I prefer C-S-Enter+Enter more

than C-S-Enter + C-Z or C-S-Enter + C-Backspace. Which one I am going to do
more often (you are probably right) isn't the only thing important. The
amount of effort each one requires has to factor in. The fact that I didn't
use C-S-Enter + C-BackSpace (and it seems Maxim as well) tells me that to
learn this way is still too much. It is just more intuitive and easier to
hit another time Enter (your pickie is right on top of it) than to remember
that C-BackSpace remove all whitespace and move your pickie up 2 rows to hit
backspace (which I miss about 50% of the time).

What do you think about using second C-S-Enter for newline?
I.e. hitting C-S-Enter first time -> completing statement
Hitting C-S-Enter immediately after it -> adding newline.

IMHO hitting the same keystroke twice is almost as hard as hitting it
once.
And you don't have to learn much :)

...Or I missed something?

>

However in the end I agree. Having both actions and letting the user remap

the appropriate action to Ctrl-Shift-Enter or having an IDEA option
governing the addition of the new line would meet everybody's need. I might
also discover that I am wrong... again ;)
>

Jacques



--
Best regards,
Michael





0

What I want is to just be able to remap Enter with "Smart Complete Enter",
and still have it do the right thing in all cases. I really don't see the
need for a dozen different ways to "enter". I want smart complete enter, I
want "open new line" and "break line here" and "complete this statement".
But 9 times out of 10, what i want is "smart complete enter" that just does
the right thing given the current context. If the statement is incomplete
and can be completed, then complete it and start a new line; if a statement
is incomplete and can't be completed, start a new line with the proper
indent; if a statement is completed, just start a new line. The "break line
here" and "complete this statement without adding a new line" are really
special cases that I wouldn't use that often, compared to the normal case.

As long as the different functions
("smart-enter-with-complete-and-new-line", "Complete statement", "smart
break line here", and "open new line") are available, then I can map them as
I choose. And arguably, that "Open new line" is redundant and unnecessary,
but I'm sure some people will find it useful nevertheless.

"Michael Kutuzov" <FakeAddress@4spammers.tk> wrote in message
news:b74kgt$f4m$1@is.intellij.net...

Hi gentlemen

>

"Jacques Morel" <jacmorel@yahoo.com> wrote:
news:5428447.1049933141442.JavaMail.jrun@is.intellij.net...

For the same reason that I brought up before I prefer C-S-Enter+Enter

more

than C-S-Enter + C-Z or C-S-Enter + C-Backspace. Which one I am going to

do

more often (you are probably right) isn't the only thing important. The
amount of effort each one requires has to factor in. The fact that I

didn't

use C-S-Enter + C-BackSpace (and it seems Maxim as well) tells me that to
learn this way is still too much. It is just more intuitive and easier to
hit another time Enter (your pickie is right on top of it) than to

remember

that C-BackSpace remove all whitespace and move your pickie up 2 rows to

hit

backspace (which I miss about 50% of the time).

>

What do you think about using second C-S-Enter for newline?
I.e. hitting C-S-Enter first time -> completing statement
Hitting C-S-Enter immediately after it -> adding newline.

>

IMHO hitting the same keystroke twice is almost as hard as hitting it
once.
And you don't have to learn much :)

>

...Or I missed something?

>

>

However in the end I agree. Having both actions and letting the user

remap

the appropriate action to Ctrl-Shift-Enter or having an IDEA option
governing the addition of the new line would meet everybody's need. I

might

also discover that I am wrong... again ;)
>

Jacques

>
>

--
Best regards,
Michael

>
>
>
>


0

Hi Paul

First of all, thank you for clarifying your point. Now I'm almost ready to
accept it.
(Maybe I was somewhat confused by your two-step undo :)

"Paul Bradshaw" <pbradshaw@vignette.com> wrote:
news:b77duu$2lp$1@is.intellij.net...

What I want is to just be able to remap Enter with "Smart Complete Enter",
and still have it do the right thing in all cases. I really don't see the
need for a dozen different ways to "enter". I want smart complete enter,

I

want "open new line" and "break line here" and "complete this statement".
But 9 times out of 10, what i want is "smart complete enter" that just

does

the right thing given the current context. If the statement is incomplete
and can be completed, then complete it and start a new line; if a

statement

is incomplete and can't be completed, start a new line with the proper
indent; if a statement is completed


Let's add here "or the caret is at empty line"

>, just start a new line. The "break line

here" and "complete this statement without adding a new line" are really
special cases that I wouldn't use that often, compared to the normal case.


The last is undoubtly redundant. Two statements at one line? Don't like it.

As long as the different functions
("smart-enter-with-complete-and-new-line", "Complete statement", "smart
break line here", and "open new line") are available, then I can map them

as

I choose.


These four cases seem to be clearly distinguishable. Hence it's possible to
use ENTER for each of them by default.

And arguably, that "Open new line" is redundant and unnecessary,
but I'm sure some people will find it useful nevertheless.


I believe it would better to have it. Say, for the sake of completeness :)

--
Best regards,
Michael



0

There seems a problem when using Scanner. For example, if I type scanner.useDelimiter("foo<here the caret>") and press the shortcut it doesn't work. The same problem with findInLine, but inside findAll it works fine.

0

请先登录再写评论。