@@ -59,12 +59,14 @@ struct SessionEditor: View {
59
59
@State private var badURL = false
60
60
@State private var insecureURL = false
61
61
62
+ @FocusState private var isURLFieldFocused : Bool
63
+
62
64
63
65
var body : some View {
64
66
NavigationStack {
65
67
Form {
66
68
LabeledContent {
67
- TextField ( " https://df.myserver.com " , text: Binding (
69
+ TextField ( " " , text: Binding (
68
70
get: {
69
71
if url? . scheme == nil || url? . scheme == " " {
70
72
return " "
@@ -75,22 +77,24 @@ struct SessionEditor: View {
75
77
let temp = URL ( string: $0)
76
78
if temp? . scheme != nil && temp? . scheme != " " {
77
79
url = temp
78
- if ( url? . scheme? . lowercased ( ) ) == ( " http " ) {
79
- insecureURL = true
80
- } else {
81
- insecureURL = false
82
- }
80
+ insecureURL = ( url? . scheme? . lowercased ( ) ) == ( " http " )
83
81
}
84
82
}
85
- ) )
86
- . disableAutocorrection ( true )
87
- . textInputAutocapitalization ( . never)
88
- . accessibilityIdentifier ( " urlTextField " )
83
+ ) , prompt: Text ( verbatim: " https://df.example.com " ) )
84
+ . focused ( $isURLFieldFocused)
85
+ . onChange ( of: isURLFieldFocused) { wasFocused, isFocused in
86
+ if isFocused && url == nil {
87
+ url = URL ( string: " https:// " )
88
+ }
89
+ }
90
+ . disableAutocorrection ( true )
91
+ . textInputAutocapitalization ( . never)
92
+ . accessibilityIdentifier ( " urlTextField " )
89
93
} label: {
90
94
Text ( " URL: " )
91
95
}
92
96
if insecureURL {
93
- let warningMessage = " ⚠️ We strongly recommend using HTTPS . "
97
+ let warningMessage = " ⚠️ HTTPS strongly recommend. "
94
98
TextField ( " " , text: Binding (
95
99
get: { warningMessage } ,
96
100
set: { _ in } // Prevents user from modifying the text
@@ -105,13 +109,18 @@ struct SessionEditor: View {
105
109
}
106
110
ToolbarItem ( placement: . confirmationAction) {
107
111
Button ( action: {
108
- if url != nil
109
- {
112
+ // Remove trailing slash if present
113
+ if var urlString = url? . absoluteString {
114
+ if urlString. hasSuffix ( " / " ) {
115
+ urlString. removeLast ( )
116
+ url = URL ( string: urlString)
117
+ }
118
+ }
119
+ if url != nil {
110
120
withAnimation {
111
121
save ( )
112
122
}
113
- }
114
- else {
123
+ } else {
115
124
badURL. toggle ( )
116
125
}
117
126
} )
0 commit comments