Repository navigation
feat: add a command palette and shortcuts for the common commands - #57
Merged
Merged
Conversation
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Press Ctrl+Shift+P (Cmd+Shift+P on a Mac) for a command palette: type a few words of what you want to do and pick it with the arrows and Enter, or click it. It lists every button of the toolbar and what its right-click menus offer (pull with rebase, push to a remote, force push, push tags), the tabs (open a repository, new, close, next, previous), committing, and everything the right-click menu of the selected commit and its branches and tags offers, named after the commit (
Commit 4a53126 › Cherry-pick commit,Commit 4a53126 › Reset current branch to this commit › Hard: discard all changes). A command that cannot run now is listed greyed out, so the list does not jump while you type.The common commands also have a shortcut, shown next to them in the palette and in the tooltips of the toolbar:
While a text field has the keyboard (the commit message, the search), the field keeps its keys (Ctrl+Z undoes typing, Ctrl+W deletes a word), apart from Ctrl+Enter, which commits. No shortcut works while a dialog is open. While git is busy, what a key or the palette runs waits its turn, as clicks in menus already do; only undo and redo wait until git is done, because what they do depends on where it leaves
HEAD.How it is built, with as little new code as it needs:
commands.rsnames each command once, with its shortcut and its action (orNonewhile it cannot run). The toolbar now draws its buttons from that same list, so the toolbar, the keys and the palette cannot drift apart.(name, action)(graph::commit_items,graph::ref_items), drawn by onegraph::menu, which puts items namedsubmenu › itemin a submenu. The sidebar's own menu helper is gone.Action::Copy), so the palette can do it too; "Open a repository…" isAction::PickRepo, for the start screen's button and Ctrl+O alike. The form's commit isWorkspace::commit, for the button and Ctrl+Enter.This is part 1 of "Keyboard" on the roadmap; part 2 adds shortcuts in the views (stage and discard in a diff, next and previous file, close) and the start screen's clone and create.
How it is tested
the_command_palette_finds_a_command_by_words_of_its_name: Ctrl+Shift+P opens it with the keyboard in its field; "new br" lists only "New branch…", Enter opens the branch dialog and the branch gets made; words that match nothing say so, Enter then does nothing, and Escape closes the palette without reaching anything behind it.the_command_palette_has_what_the_selected_commit_offers: with an older commit selected, "reset" lists its three resets; down and up go round at both ends while the keyboard stays in the field, and Enter on the hard reset asks first. "tag" lists the commit's tag to delete and "Create tag here…"; "Copy commit SHA" puts the full SHA on the clipboard; after the palette closes, Ctrl+Z undoes again.shortcuts_run_commands_but_leave_a_text_field_its_keys: Ctrl+Z undoes a commit and Ctrl+Shift+Z redoes it (it fails when Ctrl+Z is checked first, since egui matches Ctrl+Shift+Z for it too); typing a message, Ctrl+T does nothing and Ctrl+Enter commits (it fails without the check on typing); then Ctrl+T, Ctrl+Tab, Ctrl+Shift+Tab and Ctrl+W open, go through and close the tabs.while_git_is_busy_the_keyboard_queues_what_it_runs_apart_from_undo: with a reload running, stash, fetch and new branch can run and undo cannot; Ctrl+Shift+S then stashes.All tests of the toolbar and the right-click menus pass unchanged.
Tried in the app on Linux with the demo repository: the palette from the keyboard, "reset" with the arrows, "new br" and Enter (the branch dialog), Ctrl+T and Ctrl+Tab, the shortcut in the Fetch tooltip, and Ctrl+Shift+F straight after switching tabs (it fetched).
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepassIt adds as little code as the change needs, and removes what it makes unnecessary
Nothing in it comes from GitKraken or another closed-source client (see CONTRIBUTING.md)