krasa / StringManipulation

IntelliJ plugin - https://plugins.jetbrains.com/plugin/2162
Apache License 2.0
699 stars 81 forks source link

Inconsistency with "Duplicate Line" #133

Open BernhardBln opened 3 years ago

BernhardBln commented 3 years ago

Describe the bug I feel there is some inconsistency regarding the "duplicate and increment" feature.

In the docs it is mentioned that it "duplicates the line" which it does when you just have the cursor in the current line. It does not duplicate the full lines however when you make a selection.

IntelliJ internally has two different commands, "duplicate" and "duplicate line", where the latter always duplicates the full lines.

I think it would make more sense to duplicate full lines rather than just selections (or at least make it configurable in the settings).

To Reproduce Steps to reproduce the behavior:

  1. Have a statement that takes more than one line, e.g.
int x1 = 5;
int x2 = 10;
System.out.println("some very very very very very very long text plus the content of " +
    x1);
  1. Now you want both lines 3 and 4 duplicated and x1 turned into x2.

In case you properly select everything:

image

and then choose "duplicate and increment", this will work as expected:

System.out.println("some very very very very very very long text plus the content of " +
    x1);
System.out.println("some very very very very very very long text plus the content of " +
    x2);

However, if you just select just somewhere in the middle, like this:

image

this will produce broken code:

      int x1 = 5;
      int x2 = 10;
      System.out.println("some very very very very very very long text plus the content of " + 
           x1y very very very very long text plus the content of " + x2);

Expected behavior

The line duplication should work the same way as the "duplicate line" feature in IntelliJ, duplicating whole lines instead of just the selection.

Environment : IntelliJ IDEA 2020.3.3 (Ultimate Edition) Build #IU-203.7717.56, built on March 15, 2021 Licensed to Bernhard Streit Subscription is active until April 24, 2021. Runtime version: 11.0.10+8-b1145.96 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 10.16 GC: ParNew, ConcurrentMarkSweep Memory: 5391M Cores: 16 Registry: analyze.exceptions.on.the.fly=true, ide.tooltip.initialDelay=674, ide.appIcon.requestAttention=false Non-Bundled Plugins: AceJump, IdeaVIM, org.jetbrains.IdeaVim-EasyMotion, com.github.holgerbrandl.pasteimages/, google-java-format, com.crunch42.openapi, EclipseCodeFormatter, GrepConsole, String Manipulation, com.dubreuia, com.krrrr38.idea.mockito.postfix, com.sunny.plugin.MockitoGenPlugin, com.jetbrains.codeWithMe, idea.plugin.protoeditor, org.sonarlint.idea, MavenRunHelper, intellij.prettierJS, org.jetbrains.kotlin, org.bitstrings.idea.plugins.TestInsanity, org.mapstruct.intellij, PlantUML integration

krasa commented 3 years ago

Where is mentioned that it duplicates the line?

krasa commented 3 years ago

Oh, found it :) That is wrong :-)

BernhardBln commented 3 years ago

Not quite the fix I hoped for but fair enough 😂

krasa commented 3 years ago

Duplicating selection is more universal, not sure if it is worth to make a line feature.

BernhardBln commented 3 years ago

I agree, easiest solution would be to have a "duplicate selection / whole line" toggle button in the settings where you could change this globally for all StringManipulation duplicate actions.

Would love to help, but honestly never done an IntelliJ plugin...