Skip to content

Commit a6c3304

Browse files
committed
update
1 parent 9b5efd9 commit a6c3304

5 files changed

Lines changed: 110 additions & 98 deletions

File tree

CodeApp/Containers/MainScene.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ struct MainScene: View {
123123
App.terminalManager.applyThemeToAll(rawTheme: theme.dictionary)
124124
}
125125
)
126+
.onReceive(
127+
NotificationCenter.default.publisher(
128+
for: Notification.Name("editor.commandPalette"),
129+
object: nil
130+
)
131+
) { _ in
132+
Task {
133+
await App.monacoInstance._toggleCommandPalatte()
134+
}
135+
}
126136
}
127137
}
128138

CodeApp/Managers/TerminalInstance.swift

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate,
9595
public var executor: Executor? = nil
9696
private var terminalMessageHandlerAdded = false
9797
public var openEditor: ((URL) -> Void)? = nil
98+
public var onShowCommandPalette: (() -> Void)? = nil
99+
public var onCreateTerminal: (() -> Void)? = nil
100+
public var onCloseTerminal: (() -> Void)? = nil
98101

99102
var isInteractive = false
100103

@@ -245,45 +248,69 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate,
245248
}
246249

247250
private func buildContextMenu(hasSelection: Bool) -> UIMenu {
248-
var actions: [UIMenuElement] = []
249-
250-
actions.append(
251+
let commandActions: [UIAction] = [
251252
UIAction(
252-
title: NSLocalizedString("Copy", comment: ""),
253-
image: UIImage(systemName: "doc.on.doc")
253+
title: NSLocalizedString("Command Palette...", comment: ""),
254+
image: UIImage(systemName: "command")
254255
) { [weak self] _ in
255-
self?.copySelectionToPasteboard()
256-
})
256+
self?.onShowCommandPalette?()
257+
},
257258

258-
actions.append(
259259
UIAction(
260-
title: NSLocalizedString("Paste", comment: ""),
261-
image: UIImage(systemName: "doc.on.clipboard")
260+
title: NSLocalizedString("New Terminal", comment: ""),
261+
image: UIImage(systemName: "plus.rectangle.on.rectangle")
262262
) { [weak self] _ in
263-
guard let text = UIPasteboard.general.string else { return }
264-
self?.type(text: text)
265-
})
263+
self?.onCreateTerminal?()
264+
},
266265

267-
actions.append(
268266
UIAction(
269-
title: NSLocalizedString("Select All", comment: ""),
270-
image: UIImage(systemName: "selection.pin.in.out")
267+
title: NSLocalizedString("Close Terminal", comment: ""),
268+
image: UIImage(systemName: "xmark.rectangle"),
269+
attributes: .destructive
271270
) { [weak self] _ in
272-
self?.executeScript("term.selectAll()")
273-
})
271+
self?.onCloseTerminal?()
272+
},
273+
]
274274

275-
actions.append(
275+
let terminalActions: [UIAction] = [
276276
UIAction(
277-
title: NSLocalizedString("Clear", comment: ""),
277+
title: NSLocalizedString("Clear Terminal", comment: ""),
278278
image: UIImage(systemName: "trash")
279279
) { [weak self] _ in
280280
self?.executeScript("term.clear()")
281-
})
281+
},
282+
283+
UIAction(
284+
title: NSLocalizedString("Reset Terminal", comment: ""),
285+
image: UIImage(systemName: "arrow.clockwise")
286+
) { [weak self] _ in
287+
self?.reset()
288+
},
289+
290+
UIAction(
291+
title: NSLocalizedString("Send Interrupt", comment: ""),
292+
image: UIImage(systemName: "stop.circle")
293+
) { [weak self] _ in
294+
self?.sendInterrupt()
295+
},
296+
297+
UIAction(
298+
title: NSLocalizedString("Show in Files App", comment: ""),
299+
image: UIImage(systemName: "folder")
300+
) { [weak self] _ in
301+
guard let currentDirectory = self?.executor?.currentWorkingDirectory else {
302+
return
303+
}
304+
self?.openSharedFilesApp(urlString: currentDirectory.absoluteString)
305+
},
306+
]
282307

283308
return UIMenu(
284309
title: "",
285-
options: .displayInline,
286-
children: actions
310+
children: [
311+
UIMenu(title: "", options: .displayInline, children: commandActions),
312+
UIMenu(title: "", options: .displayInline, children: terminalActions),
313+
]
287314
)
288315
}
289316

CodeApp/Managers/TerminalManager.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ class TerminalManager: ObservableObject {
9292

9393
private func createTerminalInstance(name: String) -> TerminalInstance {
9494
let terminal = TerminalInstance(root: rootURL, options: options, name: name)
95+
terminal.onShowCommandPalette = {
96+
NotificationCenter.default.post(
97+
name: Notification.Name("editor.commandPalette"),
98+
object: nil
99+
)
100+
}
101+
terminal.onCreateTerminal = { [weak self] in
102+
DispatchQueue.main.async {
103+
_ = self?.createTerminal()
104+
}
105+
}
106+
terminal.onCloseTerminal = { [weak self, weak terminal] in
107+
guard let terminal else { return }
108+
DispatchQueue.main.async {
109+
self?.closeTerminal(id: terminal.id)
110+
}
111+
}
95112
// We do not support creating remote terminal instances for now
96113
return terminal
97114
}

CodeApp/Utilities/wasm.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ func safeWASMCurrentDirectory(_ currentDirectory: String) -> String {
534534
let fileManager = FileManager.default
535535
let runtimeRootURL = wasmTemporaryRuntimeURL(fileManager: fileManager)
536536
let runtimeRootPath = runtimeRootURL.path
537-
let runtimeHomeURL = runtimeRootURL.appendingPathComponent("home", isDirectory: true)
537+
let runtimeTempURL = runtimeRootURL.appendingPathComponent("tmp", isDirectory: true)
538538
let runtimeFallbackPath =
539-
wasmEnsureHostDirectory(runtimeHomeURL.path) ? runtimeHomeURL.path : runtimeRootPath
539+
wasmEnsureHostDirectory(runtimeTempURL.path) ? runtimeTempURL.path : runtimeRootPath
540540

541541
if wasmHostDirectoryExists(currentDirectory), wasmHostPathIsWasmRuntime(currentDirectory) {
542542
return currentDirectory
@@ -723,16 +723,19 @@ func setupWASMSysroot(currentDirectory: String, gpuBackend: String? = nil) {
723723
}
724724

725725
let wasmCWD: String
726-
if let guestPath = wasmGuestPath(
727-
forHostPath: wasmCWDHost, hostRoot: runtimeHomePath, guestRoot: "/home")
726+
if wasmHostPathIsUsableByWasmer(runtimeHomePath),
727+
let guestPath = wasmGuestPath(
728+
forHostPath: wasmCWDHost, hostRoot: runtimeHomePath, guestRoot: "/home")
728729
{
729730
wasmCWD = guestPath
730-
} else if let guestPath = wasmGuestPath(
731-
forHostPath: wasmCWDHost, hostRoot: tempURL.path, guestRoot: "/tmp")
731+
} else if wasmHostPathIsUsableByWasmer(tempURL.path),
732+
let guestPath = wasmGuestPath(
733+
forHostPath: wasmCWDHost, hostRoot: tempURL.path, guestRoot: "/tmp")
732734
{
733735
wasmCWD = guestPath
734-
} else if let guestPath = wasmGuestPath(
735-
forHostPath: wasmCWDHost, hostRoot: runtimeRootPath, guestRoot: "/")
736+
} else if wasmHostPathIsUsableByWasmer(runtimeRootPath),
737+
let guestPath = wasmGuestPath(
738+
forHostPath: wasmCWDHost, hostRoot: runtimeRootPath, guestRoot: "/")
736739
{
737740
wasmCWD = guestPath
738741
} else if wasmHostPathIsUsableByWasmer(wasmCWDHost) {

CodeApp/Views/EditorContextMenu.swift

Lines changed: 22 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ class EditorContextMenu {
2222
func buildContextMenu(hasSelection: Bool) -> UIMenu {
2323
var menuItems: [UIMenuElement] = []
2424

25+
let commandSection = buildCommandSection()
26+
menuItems.append(commandSection)
27+
2528
// AI Features Section (if has selection)
2629
if hasSelection {
2730
let aiSection = buildAISection()
2831
menuItems.append(aiSection)
2932
}
3033

31-
// Basic Editing Section
32-
let editingSection = buildEditingSection(hasSelection: hasSelection)
33-
menuItems.append(editingSection)
34-
3534
// Code Actions Section
3635
if hasSelection {
3736
let codeActionsSection = buildCodeActionsSection()
@@ -93,62 +92,38 @@ class EditorContextMenu {
9392
)
9493
}
9594

96-
private func buildEditingSection(hasSelection: Bool) -> UIMenu {
97-
var actions: [UIAction] = []
98-
99-
if hasSelection {
100-
let cutAction = UIAction(
101-
title: NSLocalizedString("Cut", comment: ""),
102-
image: UIImage(systemName: "scissors")
103-
) { [weak self] _ in
104-
Task {
105-
await self?.editorImplementation?.cutSelection()
106-
}
107-
}
108-
actions.append(cutAction)
109-
110-
let copyAction = UIAction(
111-
title: NSLocalizedString("Copy", comment: ""),
112-
image: UIImage(systemName: "doc.on.doc")
113-
) { [weak self] _ in
114-
Task {
115-
if let text = await self?.editorImplementation?.copySelection() {
116-
UIPasteboard.general.string = text
117-
}
118-
}
95+
private func buildCommandSection() -> UIMenu {
96+
let commandPaletteAction = UIAction(
97+
title: NSLocalizedString("Command Palette...", comment: ""),
98+
image: UIImage(systemName: "command")
99+
) { [weak self] _ in
100+
Task {
101+
await self?.editorImplementation?._toggleCommandPalatte()
119102
}
120-
actions.append(copyAction)
121103
}
122104

123-
let pasteAction = UIAction(
124-
title: NSLocalizedString("Paste", comment: ""),
125-
image: UIImage(systemName: "doc.on.clipboard")
105+
let goToLineAction = UIAction(
106+
title: NSLocalizedString("Go to Line...", comment: ""),
107+
image: UIImage(systemName: "number")
126108
) { [weak self] _ in
127-
if let text = UIPasteboard.general.string {
128-
Task {
129-
await self?.editorImplementation?.pasteText(text: text)
130-
}
109+
Task {
110+
await self?.editorImplementation?._toggleGoToLineWidget()
131111
}
132112
}
133-
actions.append(pasteAction)
134113

135-
if hasSelection {
136-
let deleteAction = UIAction(
137-
title: NSLocalizedString("Delete", comment: ""),
138-
image: UIImage(systemName: "trash"),
139-
attributes: .destructive
140-
) { [weak self] _ in
141-
Task {
142-
await self?.editorImplementation?.deleteSelection()
143-
}
114+
let formatDocumentAction = UIAction(
115+
title: NSLocalizedString("Format Document", comment: ""),
116+
image: UIImage(systemName: "doc.text")
117+
) { [weak self] _ in
118+
Task {
119+
await self?.editorImplementation?.formatDocument()
144120
}
145-
actions.append(deleteAction)
146121
}
147122

148123
return UIMenu(
149124
title: "",
150125
options: .displayInline,
151-
children: actions
126+
children: [commandPaletteAction, goToLineAction, formatDocumentAction]
152127
)
153128
}
154129

@@ -194,26 +169,6 @@ class EditorContextMenu {
194169
}
195170
actions.append(renameAction)
196171

197-
let formatDocumentAction = UIAction(
198-
title: NSLocalizedString("Format Document", comment: ""),
199-
image: UIImage(systemName: "doc.text")
200-
) { [weak self] _ in
201-
Task {
202-
await self?.editorImplementation?.formatDocument()
203-
}
204-
}
205-
actions.append(formatDocumentAction)
206-
207-
let commandPaletteAction = UIAction(
208-
title: NSLocalizedString("Command Palette...", comment: ""),
209-
image: UIImage(systemName: "command")
210-
) { [weak self] _ in
211-
Task {
212-
await self?.editorImplementation?._toggleCommandPalatte()
213-
}
214-
}
215-
actions.append(commandPaletteAction)
216-
217172
return UIMenu(
218173
title: "",
219174
options: .displayInline,

0 commit comments

Comments
 (0)