Skip to content

Add MoveLinesUp, MoveLinesDown and DuplicateLines commands - #626

Open
mika76 wants to merge 1 commit into
AvaloniaUI:masterfrom
mika76:line-commands
Open

mika76 wants to merge 1 commit into
AvaloniaUI:masterfrom
mika76:line-commands

Conversation

@mika76

@mika76 mika76 commented Nov 5, 2026 •

Copy link
Copy Markdown

Adds three line commands to AvaloniaEditCommands, next to DeleteLine. Closes #317.

Command Default shortcut What it does
MoveLinesUp Alt+Up Moves the caret line, or the lines touched by the selection, up by one line
MoveLinesDown Alt+Down The same, down by one line
DuplicateLines Ctrl+Shift+D Inserts a copy of those lines below them
  • The caret and selection stay on the moved or copied text, so the commands can be repeated.
  • A last line with nothing selected on it isn't included, as with the other line commands.
  • Each command is one undo step.
  • Newlines are kept, and a copy of the document's last line uses the document's newline.
  • Read-only sections are respected: nothing changes if the text isn't writable.
  • Alt+Up and Alt+Down are free (box selection uses Alt+Shift on Windows and Ctrl+Shift on macOS). Ctrl+D is already DeleteLine, so duplicate is Ctrl+Shift+D.

About the default shortcuts: like DeleteLine and IndentSelection, the gestures are set on the commands, so every editor gets them. An application that already uses these keys keeps working if it handles them first, or it can remove the command bindings. If you'd rather these commands had no default gesture and left the keys to each application, that's an easy change.

Tests in LineCommandsTests cover moving and duplicating at the first and last line, with and without a final newline, with CRLF, with selections (including one that ends at the start of a line), empty lines, undo, read-only documents, and the default shortcuts.

626

Move the caret line, or the lines touched by the selection, up or down by one line (Alt+Up, Alt+Down), or insert a copy of them below (Ctrl+Shift+D). The caret and selection stay on the moved or copied text, each command is one undo step, and read-only sections are respected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

How to duplicate a line with a hotkey

1 participant