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

Keyboard shortcut to switch sidebar navigator tabs #1382

Merged
merged 24 commits into from
Sep 20, 2023

Conversation

FastestMolasses
Copy link
Member

@FastestMolasses FastestMolasses commented Jul 17, 2023

Description

Edited: This PR now adds the shortcuts to change between the sidebar navigator tabs. This also removes the old shortcut of using ⌘+index to change between files. Finally, these shortcuts are also added in the View/Navigators menu item like how Xcode has it. Each tab is now draggable and they can be reordered by the user to their preference.

The shortcut is: ⌘+ number

With number ranging from 1 - 9. Because each sidebar navigator tab is now draggable, you can rearrange the order and the following keyboard shortcuts will update accordingly.

Related Issues

Closes #1384

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

Here's how the shortcut menu looks in Xcode

xcode

Here it is in CodeEdit

Screenshot 2023-07-24 at 12 13 46 AM

Demo

Jul-24-2023 00-16-38

@austincondiff
Copy link
Collaborator

These buttons theoretically will still consume space otherwise not occupied. Maybe setting width and height to 0 and clip. We could create a custom modifier for this. However there may be a better alternative. Anyone else have any better ideas?

@FastestMolasses
Copy link
Member Author

I believe it's not taking any space due to this modifier:

.frame(width: 0, height: 0)

Here is a screenshot of my change:
Screenshot 2023-07-16 at 11 33 43 PM
And a screenshot of the original code using .hidden()
Screenshot 2023-07-16 at 11 35 35 PM

@austincondiff austincondiff requested a review from a team July 18, 2023 02:20
@matthijseikelenboom
Copy link
Contributor

There is no issue for this?

@FastestMolasses
Copy link
Member Author

There is no issue for this?

Created an issue and updated the pull request comment

@FastestMolasses
Copy link
Member Author

Updated!

@FastestMolasses FastestMolasses changed the title Switch tabs Keyboard shortcut to switch sidebar navigator tabs Jul 24, 2023
@austincondiff
Copy link
Collaborator

austincondiff commented Jul 24, 2023

Great work! Why is the Find Navigator command 4 and not command 3?

@FastestMolasses
Copy link
Member Author

I put it as 4 because in Xcode, 3 is reserved for the symbols tab, which I wasnt sure if it was going to be added to CodeEdit or not. If not I can change it to cmd+3. Lmk!

@austincondiff
Copy link
Collaborator

austincondiff commented Jul 25, 2023

I see. These keyboard shortcuts should be dynamic. You will be able to rearrange these icons. The shortcuts should always be in the order in which they appear. So say you move the Find Navigator from the third to the first position, it should then be ⌘1 instead of ⌘3.

@bombardier200
Copy link
Contributor

@FastestMolasses There are some SwiftLint errors that need to be fixed please.

@austincondiff
Copy link
Collaborator

What do we have left on this PR?

@austincondiff
Copy link
Collaborator

@matthijseikelenboom if this is the case, should we just merge this as is for now?

@matthijseikelenboom
Copy link
Contributor

@austincondiff Hmm yeah we could, but we don't know if it will ever get fixed. It can also just be a limitation of SwiftUI.

Anyway, if we merge this, we need an issue that notes everything that is broken or missing. But I think its a better idea to disable dragging icons, otherwise we have broken functionality in the app, which I'm not a favor of. More so, it wasn't part of the issue that is being addressed here.

@Wouter01
Copy link
Member

This isn't a SwiftUI issue, but rather a mistake in the code. In ViewCommands.swift, a reference to the navigatorSidebarViewModel is used, but is not observed. Thus, the commands will only be set once and won't be updated afterwards. This can be easily solved:

extension ViewCommands {
    struct NavigatorCommands: View {
        @ObservedObject var model: NavigatorSidebarViewModel
        
        var body: some View {
            Menu("Navigators", content: {
                ForEach(Array(model.items.enumerated()), id: \.element) { index, tab in
                    Button(tab.title) {
                        model.setNavigatorTab(tab: tab)
                    }
                    .keyboardShortcut(KeyEquivalent(Character(String(index + 1))))
                }
            })
        }
    }
}

And then in ViewCommands:

if let model = windowController?.navigatorSidebarViewModel {
    Divider()
    
    NavigatorCommands(model: model)
}

NavigatorCommands is provided as an extension of ViewCommands, so it doesn't clutter the global scope

Could you add these changes in your PR, @FastestMolasses ?

@FastestMolasses
Copy link
Member Author

@Wouter01 Great catch, it's working perfectly now. This PR is ready to be reviewed now.

austincondiff
austincondiff previously approved these changes Aug 30, 2023
Copy link
Collaborator

@austincondiff austincondiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @FastestMolasses! ✅

@FastestMolasses
Copy link
Member Author

Theres 1 swift lint error, where the swapTab function has 6 parameters, where only 5 are allowed. Can I add an exception to this rule, or does anyone have any ideas on how to not use a 6th parameter?

@FastestMolasses FastestMolasses force-pushed the switch-tabs branch 2 times, most recently from ac2d8b0 to 2612387 Compare September 11, 2023 10:42
@thecoolwinter
Copy link
Collaborator

@FastestMolasses yes that's an okay exception. I don't feel like adding a struct just for that function call is a good trade off, which is what I'd usually suggest in place of it. Just make sure each parameter is on a new line in that function declaration.

@FastestMolasses
Copy link
Member Author

Ready for a re-review!

Copy link
Collaborator

@austincondiff austincondiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

@FastestMolasses
Copy link
Member Author

Bumping!

@austincondiff austincondiff merged commit 29bbb08 into CodeEditApp:main Sep 20, 2023
2 checks passed
@thecoolwinter thecoolwinter added the enhancement New feature or request label Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐞 Cmd + Number shortcut doesn't work
7 participants