Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editor command: Duplicate code #4

Open
justcla opened this issue Jun 29, 2016 · 20 comments
Open

Add editor command: Duplicate code #4

justcla opened this issue Jun 29, 2016 · 20 comments
Assignees

Comments

@justcla
Copy link
Owner

justcla commented Jun 29, 2016

Suggested key binding: Ctrl+D

@justcla
Copy link
Owner Author

justcla commented Jul 8, 2016

Aakash will look into this.

@aakash-1906 aakash-1906 self-assigned this Jul 15, 2016
@pramod-hegde pramod-hegde self-assigned this Jul 15, 2016
@pramod-hegde
Copy link
Collaborator

need to handle block selection after paste

@aakash-1906
Copy link
Collaborator

Resolved the issue. Pls refer the screenshots in attachment of working version.!
Works a little better than Resharper. And that too for multi-line vertical select and for Forward/Reverse select too.!
Resharper doesn't do it properly for reverse select OR multi-line vertical block select.!
Let me know your comments.!
And sorry if you aren't able to view attachment. In that case pls ping me

Select Words inside single line.docx

@justcla
Copy link
Owner Author

justcla commented Jul 20, 2016

Nice work Aakash.
I think multi-line select duplicate should apply single line duplicate to each line - and not apply nice line breaks (as in the documented example #3).

@aakash-1906
Copy link
Collaborator

Done with as you suggested and checked in

@aakash-1906
Copy link
Collaborator

Done with both Ctrl+D and Ctrl+Shift+D

@carsonal
Copy link
Collaborator

Is this closed?

@aakash-1906
Copy link
Collaborator

Justin should make a call. Its working fine for Text editors. Not for XML based files though. So, I feel we may close this now and open a new one for XML (or) just leave this open if fixing for XML is something very simple and if anyone could help with some pointers on it.

@verysimplenick
Copy link

verysimplenick commented Dec 16, 2016

Duplicate line works not so perfectly (as Resharper for example), I don't want get duplicated line in copy-paste buffer. Bug: put line in copy-paste buffer only if I don't have selection. If I select text and then press Ctrl+D, then my copy-paste buffer not overrides.

@justcla
Copy link
Owner Author

justcla commented Dec 16, 2016

Hey Nick. I agree about it not adding to the copy-paste buffer. In fact, I would say, even if there is no selection, it should still not add to the buffer.
Do you think you could pull down the source and code that in?

@aakash-1906
Copy link
Collaborator

Ha well Justin. It getting added to copy-paste buffer is something we didn't think about earlier. I feel, we will be able to remove the recent item from that copy-paste buffer, and that shall resolve it.

However, this is better than Resharper in some ways. For it supports block (horizontal block) selection , in addition to multi-line select. And works perfectly for forward and reverse selection too.!

@justcla
Copy link
Owner Author

justcla commented Dec 16, 2016

I think if we use:

editorOperations.InsertText(selectedText);

instead of

            editorOperations.CopySelection();
            editorOperations.MoveToNextCharacter(false);
            editorOperations.Paste();
            editorOperations.MoveToPreviousCharacter(false);

that should do the trick.

Not sure about moving the position of the caret, though. I was trying to test it now, but I notice it is referencing Dev15 assemblies because I upgraded it to VS2017.
Might need to wind that back to Dev14 so it works on both VS2015 and VS2017.

@justcla
Copy link
Owner Author

justcla commented Dec 16, 2016

The feature works really well, I must admit.

Although, the code could probably be cleaned up a bit.
For instance, there is no need for the variable "singleLine". Those two if blocks can be merged.
Also, there seems to be no need for "text". It is just a copy of "selectedText".
And finally, I wonder if there is a lot of duplicate of code in those blocks that deal with single selection or multi-line selection. Perhaps a good chunk of the "code and paste and move next" work could be moved to a method and called from a few places to reduce redundant code.
Those are my thoughts.

@yannduran
Copy link

This works perfectly for me so far 👍

@verysimplenick
Copy link

verysimplenick commented Dec 19, 2016

This works perfectly for me so far

@yannduran, Yes it's works, but replacing copy-paste buffer if you not select line. I'm really sad about this :(

@justcla As I can see it's one if body with variable singleLine. When you can release fix?

@justcla
Copy link
Owner Author

justcla commented Dec 19, 2016

@verysimplenick I can release a fix as soon as you code it up for me! :-D
This is a community project. We value your input and contributions.
If you can submit a pull request, I'll test it, accept it and release it pronto.
Thanks

@verysimplenick
Copy link

verysimplenick commented Dec 19, 2016

@justcla , I don't have addin sdk for now.
Added:
Install sdk only for this fix.
See #55

@justcla
Copy link
Owner Author

justcla commented Dec 19, 2016

Thanks for the pull request Nick.
I've merged it into a new branch called "FixDuplicateLine".

I've also had a go at fixing the caret position.
Two issues:

  • If the caret starts at the beginning of the line, it gets moved down one line too many.
  • Duplicate Line does not work well on the last line. It needs to add a Cr/Lf.

@justcla
Copy link
Owner Author

justcla commented Dec 19, 2016

Once we've fixed the caret position and the Last-Line issue, I will merge it into Master.

@justcla
Copy link
Owner Author

justcla commented Dec 20, 2016

I've fixed the caret position issue. And I've included a hack to get around the issue of the last line not having a newline character.
Branch marged to Master.
New release created: v1.1.4
and now available on Marketplace.
:-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants