Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password manager: Fix tabbing between text fields #3724

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Use NSHostingView subclass to cover more cases and avoid DispatchQueu…
…e hack
  • Loading branch information
noisysocks committed Jan 20, 2025
commit 296129ff09f753911f7166ddd2d60140055165b1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// AutoRecalculatingKeyViewHostingView.swift
//
// Copyright © 2025 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftUI

final class AutoRecalculatingKeyViewHostingView<Content: View>: NSHostingView<Content> {
override func layout() {
super.layout()

// Fix not being able to tab between TextFields by manually updating key view loop after SwiftUI has finished layout. This doesn't happen automatically because MainWindow sets autorecalculatesKeyViewLoop to false.
self.window?.recalculateKeyViewLoop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ final class PasswordManagementViewController: NSViewController {

self.itemModel = itemModel

let view = NSHostingView(rootView: PasswordManagementLoginItemView().environmentObject(itemModel))
let view = AutoRecalculatingKeyViewHostingView(rootView: PasswordManagementLoginItemView().environmentObject(itemModel))
replaceItemContainerChildView(with: view)
}

Expand All @@ -478,7 +478,7 @@ final class PasswordManagementViewController: NSViewController {

self.itemModel = itemModel

let view = NSHostingView(rootView: PasswordManagementIdentityItemView().environmentObject(itemModel))
let view = AutoRecalculatingKeyViewHostingView(rootView: PasswordManagementIdentityItemView().environmentObject(itemModel))
replaceItemContainerChildView(with: view)
}

Expand All @@ -494,7 +494,7 @@ final class PasswordManagementViewController: NSViewController {

self.itemModel = itemModel

let view = NSHostingView(rootView: PasswordManagementNoteItemView().environmentObject(itemModel))
let view = AutoRecalculatingKeyViewHostingView(rootView: PasswordManagementNoteItemView().environmentObject(itemModel))
replaceItemContainerChildView(with: view)
}

Expand All @@ -510,7 +510,7 @@ final class PasswordManagementViewController: NSViewController {

self.itemModel = itemModel

let view = NSHostingView(rootView: PasswordManagementCreditCardItemView().environmentObject(itemModel))
let view = AutoRecalculatingKeyViewHostingView(rootView: PasswordManagementCreditCardItemView().environmentObject(itemModel))
replaceItemContainerChildView(with: view)
}

Expand All @@ -531,11 +531,6 @@ final class PasswordManagementViewController: NSViewController {
itemContainer.addSubview(view)
itemContainer.wantsLayer = true
itemContainer.layer?.masksToBounds = false

// MainWindow sets autorecalculatesKeyViewLoop to false, so need to call recalculateKeyViewLoop() when view changes.
DispatchQueue.main.async {
view.window?.recalculateKeyViewLoop()
}
}

private func doSaveCredentials(_ credentials: SecureVaultModels.WebsiteCredentials) {
Expand Down
Loading