Skip to content
Open
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
51 changes: 35 additions & 16 deletions Enchanted/UI/macOS/Chat/Components/InputFields_macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct InputFieldsView: View {
@State private var selectedImage: Image?
@State private var fileDropActive: Bool = false
@State private var fileSelectingActive: Bool = false
@State private var textFieldHeight: CGFloat = 40
@FocusState private var isFocusedInput: Bool

@MainActor private func sendMessage() {
Expand Down Expand Up @@ -69,27 +70,45 @@ struct InputFieldsView: View {
}

ZStack(alignment: .trailing) {
TextField("Message", text: $message.animation(.easeOut(duration: 0.3)), axis: .vertical)
.focused($isFocusedInput)
.font(.system(size: 14))
.frame(maxWidth:.infinity, minHeight: 40)
.clipped()
.textFieldStyle(.plain)
ScrollViewReader { scrollView in
ScrollView {
TextField("Message",
text: $message.animation(.easeOut(duration: 0.3)),
axis: .vertical)
.focused($isFocusedInput)
.font(.system(size: 14))
.frame(maxWidth:.infinity, minHeight: 40)
.clipped()
.textFieldStyle(.plain)
.overlay {
GeometryReader { geo in
Color.clear.onChange(of: geo.size.height) {
withAnimation {
self.textFieldHeight = geo.size.height
}
}
}
}

#if os(macOS)
.onSubmit {
if NSApp.currentEvent?.modifierFlags.contains(.shift) == true {
message += "\n"
} else {
sendMessage()
.onSubmit {
if NSApp.currentEvent?.modifierFlags.contains(.shift) == true {
message += "\n"
} else {
sendMessage()
}
}
}
#endif
/// TextField bypasses drop area
.allowsHitTesting(!fileDropActive)
/// TextField bypasses drop area
.allowsHitTesting(!fileDropActive)
#if os(macOS)
.addCustomHotkeys(hotkeys)
.addCustomHotkeys(hotkeys)
#endif
.padding(.trailing, 80)
.padding(.trailing, 80)
}
.frame(maxHeight: min(textFieldHeight, 120+10))
// plus 10 to indicate it's scrollable.
}


HStack {
Expand Down