From 2b6f449260d59e5ac7cb57d433522bc748ac9c23 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Thu, 26 Dec 2024 22:09:42 +0530 Subject: add keyboard shortcuts --- iGopherBrowser/BrowserView.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/iGopherBrowser/BrowserView.swift b/iGopherBrowser/BrowserView.swift index e633108..17bc89e 100644 --- a/iGopherBrowser/BrowserView.swift +++ b/iGopherBrowser/BrowserView.swift @@ -56,6 +56,8 @@ struct BrowserView: View { @State var currentTask: Task? + @FocusState private var isURLFocused: Bool + let client = GopherClient() var body: some View { @@ -261,6 +263,7 @@ struct BrowserView: View { Label("Home", systemImage: "house") .labelStyle(.iconOnly) } + .keyboardShortcut("r", modifiers: [.command]) Spacer() Button { goBack(); @@ -269,6 +272,7 @@ struct BrowserView: View { Label("Back", systemImage: "chevron.left") .labelStyle(.iconOnly) } + .keyboardShortcut("[", modifiers: [.command]) .disabled(backwardStack.count < 2) Spacer() Button { @@ -277,6 +281,7 @@ struct BrowserView: View { Label("Forward", systemImage: "chevron.right") .labelStyle(.iconOnly) } + .keyboardShortcut("]", modifiers: [.command]) .disabled(forwardStack.isEmpty) Spacer() if shareThroughProxy { @@ -326,6 +331,7 @@ struct BrowserView: View { Label("Home", systemImage: "house") .labelStyle(.iconOnly) } + .keyboardShortcut("r", modifiers: [.command]) #if os(visionOS) Button { @@ -342,6 +348,7 @@ struct BrowserView: View { Label("Back", systemImage: "chevron.left") .labelStyle(.iconOnly) } + .keyboardShortcut("[", modifiers: [.command]) .disabled(backwardStack.count < 2) Button { @@ -350,6 +357,7 @@ struct BrowserView: View { Label("Forward", systemImage: "chevron.right") .labelStyle(.iconOnly) } + .keyboardShortcut("]", modifiers: [.command]) .disabled(forwardStack.isEmpty) TextField("Enter a URL", text: $url) @@ -357,8 +365,9 @@ struct BrowserView: View { .keyboardType(.URL) .autocapitalization(.none) #endif + .focused($isURLFocused) .padding(10) - } + } //.background(Color.white) .cornerRadius(30) if shareThroughProxy { -- cgit v1.2.3