Skip to content

Commit

Permalink
perf(UI): replace TextField with TextEditor for OpenAI configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed May 27, 2024
1 parent 6832184 commit 1a52c8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ private struct OpenAIServiceConfigurationView: View {
placeholder: "service.configuration.openai.endpoint.placeholder"
)

// model
TextField(
"service.configuration.custom_openai.supported_models.title",
// models
TextEditorCell(
title: "service.configuration.custom_openai.supported_models.title",
text: viewModel.$availableModels ?? "",
prompt: Text("service.configuration.custom_openai.model.placeholder")
placeholder: "service.configuration.custom_openai.model.placeholder"
)
.padding(10.0)

Picker(
"service.configuration.openai.model.title",
selection: viewModel.$model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ struct TextEditorCell: View {
var body: some View {
HStack(alignment: .center, spacing: 20) {
Text(title)

TextEditorWithPlaceholder(text: $text, placeholder: placeholder, alignment: .topTrailing)
.padding(.horizontal, 3)
.padding(.vertical, 5)
.padding(.top, 5)
.padding(.bottom, 7)
.font(.body)
.lineSpacing(5)
.scrollContentBackground(.hidden) // Refer https://stackoverflow.com/a/62848618/8378840
Expand Down Expand Up @@ -50,16 +52,14 @@ struct TextEditorWithPlaceholder: View {
var alignment: Alignment = .leading

var body: some View {
HStack {
ZStack(alignment: alignment) {
if let placeholder = placeholder, text.isEmpty {
Text(placeholder)
.foregroundColor(Color(NSColor.placeholderTextColor))
.padding(3)
}

TextEditor(text: $text)
ZStack(alignment: alignment) {
if let placeholder = placeholder, text.isEmpty {
Text(placeholder)
.foregroundColor(Color(NSColor.placeholderTextColor))
.padding(3)
}

TextEditor(text: $text)
}
}
}

0 comments on commit 1a52c8f

Please sign in to comment.