Enhance "Duplicate Line" to allow duplication of selection

Request Features and Feature Changes

Enhance "Duplicate Line" to allow duplication of selection

Postby immortalnights » Wed Jan 12, 2011 11:05 am

The duplicate line option is useful, but when working with code quite often a single line isn't enough.

It would be nice if Duplicate Line would duplicate the selection or since the it does imply line only edits for a new option to be added that allowed duplication of a selection.
immortalnights
User
 
Posts: 39
Joined: Tue Dec 21, 2010 2:02 pm

Re: Enhance "Duplicate Line" to allow duplication of selection

Postby basweber » Sun Jan 30, 2011 1:26 pm

I also would really like this feature.

In fact, I would like to have something like in eclipse:

CTRL+ALT+<up/down> duplicates the selected lines and places them under/above them.

ALT+<up/down> moves the selected lines up or down (generalization of 'Transpose line')


I dont think that this would be hard to implement and I would try it by myself if I would get a hint where to start.
basweber
Limited User
 
Posts: 4
Joined: Sun Jan 30, 2011 1:04 pm

Re: Enhance "Duplicate Line" to allow duplication of selection

Postby cody » Sun Jan 30, 2011 7:38 pm

basweber wrote:I also would really like this feature.

In fact, I would like to have something like in eclipse:

CTRL+ALT+<up/down> duplicates the selected lines and places them under/above them.

ALT+<up/down> moves the selected lines up or down (generalization of 'Transpose line')


I dont think that this would be hard to implement and I would try it by myself if I would get a hint where to start.


Hi, the second feature already exists actually.

Ctrl+Shift+Up - Transposes current line with the line above it
Ctrl+Shift+Down = Transposes current line with line below it

For Duplicate Selection I am guessing that it would best be implemented as a sloppy selection command that acts on the whole line(s) that the selection covers as opposed to the explicit selection since it would be just as easy to do regular copy paste in that use case.
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: Enhance "Duplicate Line" to allow duplication of selection

Postby basweber » Sun Jan 30, 2011 8:19 pm

the second feature already exists actually

Ctrl+Shift+Up - Transposes current line with the line above it
Ctrl+Shift+Down = Transposes current line with line below it



Yes, I know. But often I want to move a whole block, so transposing a single line does not help.

For Duplicate Selection I am guessing that it would best be implemented as a sloppy selection command that acts on the whole line(s) that the selection covers as opposed to the explicit selection since it would be just as easy to do regular copy paste in that use case.


Hmm. Copy and paste.. would that involve the "official" buffer for copy and paste? Because I often use the history of that buffer (via the kde app klipper) and I would like to leave that history unchanged.

Which point of the documentaion is best to start, to find out where to implement this?
And: is it possible to use interactive introspection like in ipython while "hacking" editra?
basweber
Limited User
 
Posts: 4
Joined: Sun Jan 30, 2011 1:04 pm

Re: Enhance "Duplicate Line" to allow duplication of selection

Postby cody » Mon Jan 31, 2011 9:28 pm

Hi,

I never use ipython so not exactly sure, but you can modify Editra while it is running by using the PyShell plugin since it runs within the same instance of the interpreter that Editra is using.

This change would be rather simple and would just require modifying the LineMoveUp, LineMoveDown, LineTranspose methods defined in ed_stc.py to handle when multiple lines are selected.


Cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: Enhance "Duplicate Line" to allow duplication of selection

Postby immortalnights » Thu Feb 03, 2011 3:26 pm

cody wrote:For Duplicate Selection I am guessing that it would best be implemented as a sloppy selection command that acts on the whole line(s) that the selection covers as opposed to the explicit selection since it would be just as easy to do regular copy paste in that use case.


I wouldn't call it "sloppy" :P

I believe duplication of the selection (not the whole lines the selection is on) is a useful feature in the way that it's much faster to press Ctrl-D (for example) then Ctrl-C + Ctrl-P. It also means that what ever happens to be in the clipboard would remain untouched. While coding I find the need for this quite often.
immortalnights
User
 
Posts: 39
Joined: Tue Dec 21, 2010 2:02 pm

Re: Enhance "Duplicate Line" to allow duplication of selection

Postby basweber » Sat Feb 05, 2011 4:19 pm

I played around a bit. So far, I found out that LineTranspose calls the LineTranspose method in the super class which is implemented in .../python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/stc.py. There apparently a C-function is called.

So I dont know how to generalize LineTranspose to the case of multiple lines.

Of course I could implement the desired functionality directly in LineMoveUp/Down, but I guess thats no good design.
Hence I look forward to get another hint.


In the case of DuplicateLine the same problem arises: It is implemented in the same file as above and finally a C-function is called.


BTW: Starting an ipython session from within a method like LineMoveUp/Down works very well to explore and inspect interactively the involved objects.
basweber
Limited User
 
Posts: 4
Joined: Sun Jan 30, 2011 1:04 pm

Re: Enhance "Duplicate Line" to allow duplication of selection

Postby cody » Sun Feb 06, 2011 6:49 pm

Hi,

Yes, would require not using the supermethod anymore and reimplementing the new behavior.

There are enough other methods already to allow this to be reimplemented.

see: GetSelection, GetSelectedText, GetLineFromPosition, ...

Just a matter of getting the desired text, deleting it and inserting it at a different position.

Cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States


Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron