forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditableText.swift
More file actions
72 lines (67 loc) · 2.35 KB
/
EditableText.swift
File metadata and controls
72 lines (67 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Foundation
import SwiftUI
// Hack to disable smart quotes and dashes in TextEditor
extension NSTextView {
open override var frame: CGRect {
didSet {
self.isAutomaticQuoteSubstitutionEnabled = false
self.isAutomaticDashSubstitutionEnabled = false
}
}
}
struct EditableText: View {
var text: Binding<String>
@State var isEditing: Bool = false
var body: some View {
Button(action: {
isEditing = true
}) {
HStack(alignment: .top) {
Text(text.wrappedValue)
.font(Font.system(.body, design: .monospaced))
.padding(4)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
.background {
RoundedRectangle(cornerRadius: 4)
.fill(Color(nsColor: .textBackgroundColor))
}
.overlay {
RoundedRectangle(cornerRadius: 4)
.stroke(Color(nsColor: .separatorColor), style: .init(lineWidth: 1))
}
Image(systemName: "square.and.pencil")
.resizable()
.scaledToFit()
.frame(width: 14)
.padding(4)
.background(
Color.primary.opacity(0.1),
in: RoundedRectangle(cornerRadius: 4)
)
}
}
.buttonStyle(.plain)
.sheet(isPresented: $isEditing) {
VStack {
TextEditor(text: text)
.font(Font.system(.body, design: .monospaced))
.padding(4)
.frame(minHeight: 120)
.multilineTextAlignment(.leading)
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(Color(nsColor: .separatorColor), lineWidth: 1)
)
Button(action: {
isEditing = false
}) {
Text("Done")
}
}
.padding()
.frame(width: 600, height: 500)
.background(Color(nsColor: .windowBackgroundColor))
}
}
}