diff --git a/CodeEdit/Features/Editor/Models/EditorInstance.swift b/CodeEdit/Features/Editor/Models/EditorInstance.swift index f8aeb8ebc..7ec13c53b 100644 --- a/CodeEdit/Features/Editor/Models/EditorInstance.swift +++ b/CodeEdit/Features/Editor/Models/EditorInstance.swift @@ -87,5 +87,15 @@ class EditorInstance: Hashable { } return (endTextLine.index - startTextLine.index) + 1 } + + func moveLinesUp() { + guard let controller = textViewController else { return } + controller.moveLinesUp() + } + + func moveLinesDown() { + guard let controller = textViewController else { return } + controller.moveLinesDown() + } } } diff --git a/CodeEdit/Features/WindowCommands/CodeEditCommands.swift b/CodeEdit/Features/WindowCommands/CodeEditCommands.swift index ef5714559..e2182de99 100644 --- a/CodeEdit/Features/WindowCommands/CodeEditCommands.swift +++ b/CodeEdit/Features/WindowCommands/CodeEditCommands.swift @@ -18,6 +18,7 @@ struct CodeEditCommands: Commands { FindCommands() NavigateCommands() if sourceControlIsEnabled { SourceControlCommands() } + EditorCommands() ExtensionCommands() WindowCommands() HelpCommands() diff --git a/CodeEdit/Features/WindowCommands/EditorCommands.swift b/CodeEdit/Features/WindowCommands/EditorCommands.swift new file mode 100644 index 000000000..607545200 --- /dev/null +++ b/CodeEdit/Features/WindowCommands/EditorCommands.swift @@ -0,0 +1,33 @@ +// +// EditorCommands.swift +// CodeEdit +// +// Created by Bogdan Belogurov on 21/05/2025. +// + +import SwiftUI +import CodeEditKit + +struct EditorCommands: Commands { + + @UpdatingWindowController var windowController: CodeEditWindowController? + private var editor: Editor? { + windowController?.workspace?.editorManager?.activeEditor + } + + var body: some Commands { + CommandMenu("Editor") { + Menu("Structure") { + Button("Move line up") { + editor?.selectedTab?.rangeTranslator?.moveLinesUp() + } + .keyboardShortcut("[", modifiers: [.command, .option]) + + Button("Move line down") { + editor?.selectedTab?.rangeTranslator?.moveLinesDown() + } + .keyboardShortcut("]", modifiers: [.command, .option]) + } + } + } +}