This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 175843

Summary: add 'duplicate selection' action
Product: editor Reporter: ryr <ryr>
Component: Actions/Menu/ToolbarAssignee: Miloslav Metelka <mmetelka>
Status: REOPENED ---    
Severity: blocker CC: AvanOsch
Priority: P3    
Version: 8.2   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description ryr 2009-10-31 10:36:07 UTC
needs to implement "Duplicate line / Selection" key bind
Comment 1 Vitezslav Stejskal 2009-11-02 07:50:38 UTC
I'm sorry, I don't understand. There are shortcuts for duplicating lines or text selection - on my Mac they are
Meta-Shift-Up and Meta-Shift-Down, which on PCs should translate to Ctrl-Shift-Up, Ctrl-Shift-Down, I think. Are they
not working?
Comment 2 ryr 2009-11-05 01:44:46 UTC
They duplicate lines, but not text selection.
If there is no selection it's like a Ctrl-Shift-Up. On selection it's like Ctrl-C + Ctrl-V except for adding the selected 
text to buffer.

P.S. This shortcut is in zend 5.5, notepad++, etc., but in other ide I have not seen it.
Comment 3 Jiri Prox 2009-11-05 09:56:17 UTC
What version/build of Netbeans do you use?
In my 6.8beta this action works for selection as well
Comment 4 Vitezslav Stejskal 2009-11-05 15:11:39 UTC
Ok, so what exactly do you think these actions should do with text selection? Something like this:

012>345<6789   // text selection marked by > and <

... pressed Ctrl+Shift+Down

345

Is this what you want? If not please give us an example with as much details as possible. Thanks
Comment 5 ryr 2009-11-10 02:03:44 UTC
example 1:

012>345<6789   // text selection marked by > and <

... pressed Ctrl+D (my "Duplicate line / selection" shortcut)

0123453456789

example 2:

>123
456
789<

... pressed Ctrl+D

123
456
789
123
456
789

That's how it works in Zend 5.5 or notepad++ and i used to it.
Comment 6 Vitezslav Stejskal 2009-11-10 05:00:10 UTC
Thanks for the examples.
Comment 7 ryr 2009-11-11 03:49:40 UTC
sorry, i forgot about 3 example:

0123456789 // there is no selection

... pressed

0123456789
0123456789 // 

and in 2 example the result should be:

123
456
789123
456
789

ie if you select some text, then the following happens: 
1. action copies the selection to the buffer
2. sets the "cursor" position to the end of selection
3. inserts the data from the buffer

So to get 2 result from #5 comment the selection should be:

>123
456
789
<
Comment 8 hkongm 2013-04-11 09:39:04 UTC
i really need this useful function. the action just like ctrl+d in notepad++ will be wonderful!
Comment 9 Martin Balin 2016-07-07 07:26:37 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 10 Crazy-P 2016-12-24 00:49:00 UTC
This feature still doesn't exist.
Yes you can duplicate line up and down, however Netbeans IDE is missing the "selected duplicate" function. Preferably to use the same hotkey as duplicate line. In other IDE's they use e.g. Ctrl+D for this (often they don't have the function to decide whether to duplicate it up or down)

| = text marker position
Double marker indicates selected text:
text | text inside marker is selected | more text

Example 1:

This is a code line|  (Ctrl + Shift + Down [Ctrl + D])
This is a code line (Line duplicated)

Example 2:

This is| a code| line (Ctrl + Shift + Down [Ctrl + D])

the line above now duplicate selected text and becomes:
This is| a code| a code line 

Example 3: Same as example 2, but it can also copy paste newlines

123|     (Ctrl + Shift + Down [Ctrl + D])
456
789|

Becomes:
123
456
789
456
789
Comment 11 Crazy-P 2016-12-24 00:50:55 UTC
(In reply to Martin Balin from comment #9)
> This old bug may not be relevant anymore. If you can still reproduce it in
> 8.2 development builds please reopen this issue.
> 
> Thanks for your cooperation,
> NetBeans IDE 8.2 Release Boss

PS. happens in 8.2 as well
Comment 12 mhaid 2017-02-26 11:24:22 UTC
+1
This an essential shortcut I do not want to miss. It is useful for duplicating a small text selection in a single line as well as across multiple lines (the selection not necessary being aligned to line boundaries).

Example 1, add a function parameter, JSON property (inline) or similar:
void doSomething(>par1, <par2)
->
void doSomething(par1, par1, par2)
Then you can modify the duplicated par1 to par1a.

Example 2, multiline:
String result = >(code === 1) ?
  "found" :
  <"not found";
->
String result = (code === 1) ?
  "found" :
  (code === 1) ?
  "found" :
  "not found";
Then you can change the duplicated code: (code >= 2) ? "maybe" :

If no text is selected, the assumed selection defaults to the whole line the cursor is placed in, thus equivalent to duplicating the line downwards.

I know, this works this way in Notepad++ and Sublime Text. 

This also makes The shortcut "duplicate lines up/down" somewhat superfluous.

I really would appreciate seeing this shortcut implemented in NetBeans.
Comment 13 mhaid 2017-02-26 11:28:13 UTC
Sorry, forgotten:
As a work around you can use Ctrl-C Ctrl-V Ctrl-V or Ctrl-C left/right Ctrl-V. The disadvantage is: this modifies the clipboard.
Comment 14 yeswoman 2018-02-19 01:55:14 UTC
This feature is badly needed. Saves time and clipboard. Everyone is already used to this shortcut (Ctrl + D) from other IDEs/editors.
Thanks :)