From f94131a0521ebeb10861a7929ec87869b3d72ede Mon Sep 17 00:00:00 2001 From: Bogdan Belogurov Date: Sun, 8 Jun 2025 09:08:52 +0200 Subject: [PATCH] Add EditorCommands menu Update `EditorInstance` to be able to move lines up and down --- .../Editor/Models/EditorInstance.swift | 10 ++++++ .../WindowCommands/CodeEditCommands.swift | 1 + .../WindowCommands/EditorCommands.swift | 33 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 CodeEdit/Features/WindowCommands/EditorCommands.swift 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]) + } + } + } +}