commit c59c43aba6f404adc6ce14565834aee2948ead2b
parent 0fd5843561d2cb514325a3b4cbe35f69c7f2a6f5
Author: FIGBERT <figbert@figbert.com>
Date: Mon, 17 Oct 2022 10:54:51 -0700
Split out submitURLBar
Diffstat:
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift
@@ -52,31 +52,7 @@ struct ContentView: View {
.textFieldStyle(.roundedBorder)
.autocorrectionDisabled(true)
.onHover(perform: { hovering in hoveringURLBar = hovering })
- .onSubmit {
- Task {
- if let url = URL(string: data.tab.urlBar) {
- if var components = URLComponents(url: url, resolvingAgainstBaseURL: false) {
- if components.scheme?.isEmpty ?? true {
- if components.host?.isEmpty ?? true {
- let index = components.path.firstIndex(of: "/") ?? components.path.endIndex
- components.host = String(components.path[..<index])
- components.path = String(components.path[index...])
- }
- components.scheme = "gemini"
- }
- if let url = components.url {
- await data.openURL(url)
- }
- }
- } else {
- var components = URLComponents(string: "gemini://geminispace.info/search")
- components?.query = data.tab.urlBar
- if let url = components?.url {
- await data.openURL(url)
- }
- }
- }
- }
+ .onSubmit { Task { await submitURLBar() } }
if data.tab.response != nil && hoveringURLBar {
Button(action: { Task { await data.reload() } }) {
Label("Reload page", systemImage: "arrow.clockwise")
@@ -113,6 +89,30 @@ struct ContentView: View {
Task { await data.openURL(url) }
})
}
+
+ private func submitURLBar() async {
+ if let url = URL(string: data.tab.urlBar) {
+ if var components = URLComponents(url: url, resolvingAgainstBaseURL: false) {
+ if components.scheme?.isEmpty ?? true {
+ if components.host?.isEmpty ?? true {
+ let index = components.path.firstIndex(of: "/") ?? components.path.endIndex
+ components.host = String(components.path[..<index])
+ components.path = String(components.path[index...])
+ }
+ components.scheme = "gemini"
+ }
+ if let url = components.url {
+ await data.openURL(url)
+ }
+ }
+ } else {
+ var components = URLComponents(string: "gemini://geminispace.info/search")
+ components?.query = data.tab.urlBar
+ if let url = components?.url {
+ await data.openURL(url)
+ }
+ }
+ }
}
struct ContentView_Previews: PreviewProvider {