zed icon indicating copy to clipboard operation
zed copied to clipboard

Ability to Duplicate Line Upward

Open EvanZhouDev opened this issue 1 year ago • 3 comments

Check for existing issues

  • [X] Completed

Describe the feature

In addition to the editor::DuplicateLine command, also have an editor::DuplicateLineUpward, which copies the line above the current line, and moves the cursor up to the line above. Like the default alt-shift-up behavior in VSCode.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

EvanZhouDev avatar Jan 21 '24 05:01 EvanZhouDev

I have some notion of how this would be done. Starting here, the function could be duplicated to create a duplicate_line_up func.

My thinking is that these lines would need to be changed somehow to copy the line to the right place:

            let start = Point::new(rows.start, 0);
            let end = Point::new(rows.end - 1, buffer.line_len(rows.end - 1));
            let text = buffer
                .text_for_range(start..end)
                .chain(Some("\n"))
                .collect::<String>();
            edits.push((start..start, text));

I would be happy to tackle this if someone was willing to jump on and pair with me to get me started. I could take it over the finish line.

t-eckert avatar Jan 25 '24 01:01 t-eckert

@t-eckert Any updates? This is genuinely one of the only features left (never knew I was so reliant on such an obscure thing!) that would get me to migrate to VSCode (other than Copilot Chat, but that's slightly less priority)... please let me know if you have any ideas.

EvanZhouDev avatar Mar 01 '24 00:03 EvanZhouDev

You can do the following to get the desired functionality:

"bindings": {
    "shift-alt-down": "editor::DuplicateLine",
    "shift-alt-up": ["workspace::SendKeystrokes", "shift-alt-down up"],
}

ExplodedViewMelon avatar Mar 01 '24 22:03 ExplodedViewMelon

Do these default keymaps satisfy this feature request? DuplicateLine has been extended to include the duplication direction configuration.

{
  "alt-shift-up": [
    "editor::DuplicateLine",
    {
      "move_upwards": true
    }
  ],
  "alt-shift-down": "editor::DuplicateLine"
}

Moshyfawn avatar Mar 21 '24 14:03 Moshyfawn

@Moshyfawn this looks great! Thank you.

EvanZhouDev avatar Mar 22 '24 14:03 EvanZhouDev