Skip to content

Add EditorCommands menu #2058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CodeEdit/Features/Editor/Models/EditorInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
1 change: 1 addition & 0 deletions CodeEdit/Features/WindowCommands/CodeEditCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct CodeEditCommands: Commands {
FindCommands()
NavigateCommands()
if sourceControlIsEnabled { SourceControlCommands() }
EditorCommands()
ExtensionCommands()
WindowCommands()
HelpCommands()
Expand Down
33 changes: 33 additions & 0 deletions CodeEdit/Features/WindowCommands/EditorCommands.swift
Original file line number Diff line number Diff line change
@@ -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])
}
}
}
}
Loading