mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-16 04:20:30 +00:00
69 lines
1.8 KiB
Swift
69 lines
1.8 KiB
Swift
//
|
|
// ScriptEditorView.swift
|
|
// StikDebug
|
|
//
|
|
// Created by s s on 2025/7/4.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CodeEditorView
|
|
import LanguageSupport
|
|
|
|
struct ScriptEditorView: View {
|
|
let scriptURL: URL
|
|
|
|
@State private var scriptContent: String = ""
|
|
@State private var position: CodeEditor.Position = .init()
|
|
@State private var messages: Set<TextLocated<Message>> = []
|
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
CodeEditor(
|
|
text: $scriptContent,
|
|
position: $position,
|
|
messages: $messages,
|
|
language: .swift()
|
|
)
|
|
.font(.system(.footnote, design: .monospaced))
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.environment(
|
|
\.codeEditorTheme,
|
|
colorScheme == .dark ? Theme.defaultDark : Theme.defaultLight
|
|
)
|
|
|
|
Divider()
|
|
|
|
HStack {
|
|
Button("Cancel") {
|
|
dismiss()
|
|
}
|
|
.buttonStyle(.bordered)
|
|
|
|
Spacer()
|
|
|
|
Button("Save") {
|
|
saveScript()
|
|
dismiss()
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.foregroundColor(.black)
|
|
}
|
|
.padding()
|
|
}
|
|
.navigationTitle(scriptURL.lastPathComponent)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.onAppear(perform: loadScript)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
|
|
private func loadScript() {
|
|
scriptContent = (try? String(contentsOf: scriptURL)) ?? ""
|
|
}
|
|
|
|
private func saveScript() {
|
|
try? scriptContent.write(to: scriptURL, atomically: true, encoding: .utf8)
|
|
}
|
|
}
|