Skip to content

Commit 9356d65

Browse files
Add EditorCommands menu
Update `EditorInstance` to be able to move lines up and down
1 parent f2850b0 commit 9356d65

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

CodeEdit/Features/Editor/Models/EditorInstance.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,15 @@ class EditorInstance: Hashable {
8787
}
8888
return (endTextLine.index - startTextLine.index) + 1
8989
}
90+
91+
func moveLinesUp() {
92+
guard let controller = textViewController else { return }
93+
controller.moveLinesUp()
94+
}
95+
96+
func moveLinesDown() {
97+
guard let controller = textViewController else { return }
98+
controller.moveLinesDown()
99+
}
90100
}
91101
}

CodeEdit/Features/WindowCommands/CodeEditCommands.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct CodeEditCommands: Commands {
1818
FindCommands()
1919
NavigateCommands()
2020
if sourceControlIsEnabled { SourceControlCommands() }
21+
EditorCommands()
2122
ExtensionCommands()
2223
WindowCommands()
2324
HelpCommands()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// EditorCommands.swift
3+
// CodeEdit
4+
//
5+
// Created by Bogdan Belogurov on 21/05/2025.
6+
//
7+
8+
import SwiftUI
9+
import CodeEditKit
10+
11+
struct EditorCommands: Commands {
12+
13+
@UpdatingWindowController var windowController: CodeEditWindowController?
14+
private var editor: Editor? {
15+
windowController?.workspace?.editorManager?.activeEditor
16+
}
17+
18+
var body: some Commands {
19+
CommandMenu("Editor") {
20+
Menu("Structure") {
21+
Button("Move line up") {
22+
editor?.selectedTab?.rangeTranslator?.moveLinesUp()
23+
}
24+
.keyboardShortcut("[", modifiers: [.command, .option])
25+
26+
Button("Move line down") {
27+
editor?.selectedTab?.rangeTranslator?.moveLinesDown()
28+
}
29+
.keyboardShortcut("]", modifiers: [.command, .option])
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)