native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refocus to name editor after closing command popovers

onevcat d3160d7e 4d8fd2d7

+49 -29
+49 -29
supacode/Features/Settings/Views/RepositorySettingsView.swift
··· 14 14 @State private var pendingShortcutConflict: CustomCommandShortcutConflict? 15 15 @State private var pendingShortcut: PendingCustomShortcut? 16 16 @State private var iconPickerCommandID: UserCustomCommand.ID? 17 - @State private var iconPickerReturnResponder: NSResponder? 18 17 @State private var customCommandsFocusAnchor: NSView? 18 + @State private var popoverRefocusTask: Task<Void, Never>? 19 19 @State private var commandEditorCommandID: UserCustomCommand.ID? 20 20 @State private var editingNameCommandID: UserCustomCommand.ID? 21 21 @FocusState private var focusedNameEditorCommandID: UserCustomCommand.ID? ··· 283 283 } 284 284 .onDisappear { 285 285 stopRecorderMonitor() 286 + popoverRefocusTask?.cancel() 287 + popoverRefocusTask = nil 286 288 focusedNameEditorCommandID = nil 287 289 } 288 290 .alert( ··· 400 402 get: { iconPickerCommandID == command.id }, 401 403 set: { isPresented in 402 404 if !isPresented { 403 - dismissIconPicker() 405 + closePopoverAndRefocusName(for: command.id) 404 406 } 405 407 } 406 408 ), 407 409 arrowEdge: .bottom 408 410 ) { 409 - iconEditorPopover(for: binding) 411 + iconEditorPopover(for: binding, commandID: command.id) 410 412 } 411 413 } else { 412 414 InlineEditableCellButton( ··· 474 476 get: { commandEditorCommandID == command.id }, 475 477 set: { isPresented in 476 478 if !isPresented { 477 - commandEditorCommandID = nil 479 + closePopoverAndRefocusName(for: command.id) 478 480 } 479 481 } 480 482 ), ··· 644 646 return firstLine.isEmpty ? "Click to set command script" : firstLine 645 647 } 646 648 647 - private func iconEditorPopover(for command: Binding<UserCustomCommand>) -> some View { 649 + private func iconEditorPopover( 650 + for command: Binding<UserCustomCommand>, 651 + commandID: UserCustomCommand.ID 652 + ) -> some View { 648 653 VStack(alignment: .leading, spacing: 10) { 649 654 Text("Icon") 650 655 .font(.headline) ··· 668 673 ForEach(Self.symbolPresets, id: \.self) { symbol in 669 674 Button { 670 675 command.wrappedValue.systemImage = symbol 671 - dismissIconPicker() 676 + closePopoverAndRefocusName(for: commandID) 672 677 } label: { 673 678 Image(systemName: symbol) 674 679 .frame(width: 24, height: 24) ··· 747 752 748 753 private func toggleIconEditor(for commandID: UserCustomCommand.ID) { 749 754 if iconPickerCommandID == commandID { 750 - dismissIconPicker() 755 + closePopoverAndRefocusName(for: commandID) 751 756 return 752 757 } 753 - iconPickerReturnResponder = NSApp.keyWindow?.firstResponder as? NSResponder 754 758 iconPickerCommandID = commandID 755 759 commandEditorCommandID = nil 756 760 endNameEditing() ··· 761 765 762 766 private func toggleCommandEditor(for commandID: UserCustomCommand.ID) { 763 767 if commandEditorCommandID == commandID { 764 - commandEditorCommandID = nil 768 + closePopoverAndRefocusName(for: commandID) 765 769 return 766 770 } 767 771 commandEditorCommandID = commandID ··· 787 791 focusedNameEditorCommandID = nil 788 792 } 789 793 790 - private func dismissIconPicker() { 791 - iconPickerCommandID = nil 792 - Task { @MainActor in 794 + private func closePopoverAndRefocusName(for commandID: UserCustomCommand.ID) { 795 + popoverRefocusTask?.cancel() 796 + 797 + var transaction = Transaction() 798 + transaction.animation = nil 799 + withTransaction(transaction) { 800 + iconPickerCommandID = nil 801 + commandEditorCommandID = nil 802 + } 803 + focusCustomCommandsArea() 804 + scheduleNameRefocus(for: commandID) 805 + } 806 + 807 + private func focusCustomCommandsArea() { 808 + guard let window = NSApp.keyWindow else { 809 + return 810 + } 811 + if let customCommandsFocusAnchor, 812 + customCommandsFocusAnchor.window === window 813 + { 814 + _ = window.makeFirstResponder(customCommandsFocusAnchor) 815 + return 816 + } 817 + _ = window.makeFirstResponder(nil) 818 + } 819 + 820 + private func scheduleNameRefocus(for commandID: UserCustomCommand.ID) { 821 + popoverRefocusTask = Task { @MainActor in 793 822 await Task.yield() 794 - guard iconPickerCommandID == nil else { 823 + guard !Task.isCancelled else { 795 824 return 796 825 } 797 - guard let window = NSApp.keyWindow else { 798 - iconPickerReturnResponder = nil 826 + guard iconPickerCommandID == nil, commandEditorCommandID == nil else { 799 827 return 800 828 } 801 - 802 - let preferredResponder = iconPickerReturnResponder 803 - iconPickerReturnResponder = nil 804 - 805 - if let preferredResponder, 806 - window.makeFirstResponder(preferredResponder) 807 - { 829 + guard store.userSettings.customCommands.contains(where: { $0.id == commandID }) else { 808 830 return 809 831 } 810 832 811 - if let customCommandsFocusAnchor, 812 - customCommandsFocusAnchor.window === window, 813 - window.makeFirstResponder(customCommandsFocusAnchor) 814 - { 815 - return 833 + var transaction = Transaction() 834 + transaction.animation = nil 835 + withTransaction(transaction) { 836 + selectCustomCommand(commandID) 837 + beginNameEditing(for: commandID) 816 838 } 817 - 818 - _ = window.makeFirstResponder(nil) 819 839 } 820 840 } 821 841