mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-21 00:30:00 +02:00
.devcontainer
.github
.vscode
cmd
demo
docs
pkg
app
cheatsheet
commands
common
config
constants
env
fakes
gui
context
controllers
helpers
attach.go
base_controller.go
basic_commits_controller.go
bisect_controller.go
branches_controller.go
command_log_controller.go
commit_description_controller.go
commit_message_controller.go
commits_files_controller.go
common.go
confirmation_controller.go
context_lines_controller.go
custom_patch_options_menu_action.go
diffing_menu_action.go
files_controller.go
filter_controller.go
filtering_menu_action.go
git_flow_controller.go
global_controller.go
jump_to_side_window_controller.go
list_controller.go
list_controller_trait.go
local_commits_controller.go
local_commits_controller_test.go
main_view_controller.go
menu_controller.go
merge_conflicts_controller.go
options_menu_action.go
patch_building_controller.go
patch_explorer_controller.go
patch_explorer_controller_test.go
quit_actions.go
reflog_commits_controller.go
remote_branches_controller.go
remotes_controller.go
rename_similarity_threshold_controller.go
screen_mode_actions.go
scroll_off_margin.go
scroll_off_margin_test.go
search_controller.go
search_prompt_controller.go
shell_command_action.go
side_window_controller.go
snake_controller.go
staging_controller.go
stash_controller.go
status_controller.go
sub_commits_controller.go
submodules_controller.go
suggestions_controller.go
switch_to_diff_files_controller.go
switch_to_focused_main_view_controller.go
switch_to_sub_commits_controller.go
sync_controller.go
tags_controller.go
toggle_whitespace_action.go
undo_controller.go
vertical_scroll_controller.go
view_selection_controller.go
workspace_reset_controller.go
worktree_options_controller.go
worktrees_controller.go
filetree
keybindings
mergeconflicts
modes
patch_exploring
popup
presentation
services
status
style
types
background.go
command_log_panel.go
context.go
context_config.go
controllers.go
dummies.go
editors.go
extras_panel.go
global_handlers.go
gui.go
gui_common.go
gui_driver.go
information_panel.go
keybindings.go
layout.go
main_panels.go
menu_panel.go
options_map.go
pty.go
pty_windows.go
recent_repos_panel.go
tasks_adapter.go
test_mode.go
view_helpers.go
views.go
i18n
integration
jsonschema
logs
snake
tasks
theme
updates
utils
schema
scripts
test
vendor
.codespellrc
.editorconfig
.gitattributes
.gitignore
.golangci.yml
.goreleaser.yml
CODE-OF-CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE
Makefile
README.md
VISION.md
go.mod
go.sum
main.go
The default binding for ConfirmInEditor is <a-enter>, which has two problems: - some terminal emulators don't support it, including the default terminal on Mac (Terminal.app) - on Windows it is bound to toggling full-screen Ideally we would use <c-enter> instead (and Command-Enter on Mac), but neither is possible without https://github.com/gdamore/tcell/issues/671, so for the time being add an alternate keybinding which works everywhere. Show both bindings in the footer of the commit description panel if they are both non-null. While we're at it, fix the footer for the case where either or both of the keybindings are set to <disabled>. And finally, change "commit" to "submit" in that footer; we use the same panel also for creating tags, in which case "commit" is not quite right.
147 lines
5.0 KiB
Go
147 lines
5.0 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/gocui"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
)
|
|
|
|
type CommitDescriptionController struct {
|
|
baseController
|
|
c *ControllerCommon
|
|
}
|
|
|
|
var _ types.IController = &CommitMessageController{}
|
|
|
|
func NewCommitDescriptionController(
|
|
c *ControllerCommon,
|
|
) *CommitDescriptionController {
|
|
return &CommitDescriptionController{
|
|
baseController: baseController{},
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
func (self *CommitDescriptionController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
|
bindings := []*types.Binding{
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.TogglePanel),
|
|
Handler: self.handleTogglePanel,
|
|
},
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.Return),
|
|
Handler: self.close,
|
|
},
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.ConfirmInEditor),
|
|
Handler: self.confirm,
|
|
},
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.ConfirmInEditorAlt),
|
|
Handler: self.confirm,
|
|
},
|
|
{
|
|
Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
|
|
Handler: self.openCommitMenu,
|
|
},
|
|
}
|
|
|
|
return bindings
|
|
}
|
|
|
|
func (self *CommitDescriptionController) Context() types.Context {
|
|
return self.c.Contexts().CommitDescription
|
|
}
|
|
|
|
func (self *CommitDescriptionController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
|
return []*gocui.ViewMouseBinding{
|
|
{
|
|
ViewName: self.Context().GetViewName(),
|
|
Key: gocui.MouseLeft,
|
|
Handler: self.onClick,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (self *CommitDescriptionController) GetOnFocus() func(types.OnFocusOpts) {
|
|
return func(types.OnFocusOpts) {
|
|
footer := ""
|
|
if self.c.UserConfig().Keybinding.Universal.ConfirmInEditor != "<disabled>" || self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt != "<disabled>" {
|
|
if self.c.UserConfig().Keybinding.Universal.ConfirmInEditor == "<disabled>" {
|
|
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter,
|
|
map[string]string{
|
|
"confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt),
|
|
})
|
|
} else if self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt == "<disabled>" {
|
|
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter,
|
|
map[string]string{
|
|
"confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor),
|
|
})
|
|
} else {
|
|
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooterTwoBindings,
|
|
map[string]string{
|
|
"confirmInEditorKeybinding1": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor),
|
|
"confirmInEditorKeybinding2": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt),
|
|
})
|
|
}
|
|
}
|
|
self.c.Views().CommitDescription.Footer = footer
|
|
}
|
|
}
|
|
|
|
func (self *CommitDescriptionController) switchToCommitMessage() error {
|
|
self.c.Context().Replace(self.c.Contexts().CommitMessage)
|
|
return nil
|
|
}
|
|
|
|
func (self *CommitDescriptionController) handleTogglePanel() error {
|
|
// The default keybinding for this action is "<tab>", which means that we
|
|
// also get here when pasting multi-line text that contains tabs. In that
|
|
// case we don't want to toggle the panel, but insert the tab as a character
|
|
// (somehow, see below).
|
|
//
|
|
// Only do this if the TogglePanel command is actually mapped to "<tab>"
|
|
// (the default). If it's not, we can only hope that it's mapped to some
|
|
// ctrl key or fn key, which is unlikely to occur in pasted text. And if
|
|
// they mapped some *other* command to "<tab>", then we're totally out of
|
|
// luck.
|
|
if self.c.GocuiGui().IsPasting && self.c.UserConfig().Keybinding.Universal.TogglePanel == "<tab>" {
|
|
// Handling tabs in pasted commit messages is not optimal, but hopefully
|
|
// good enough for now. We simply insert 4 spaces without worrying about
|
|
// column alignment. This works well enough for leading indentation,
|
|
// which is common in pasted code snippets.
|
|
view := self.Context().GetView()
|
|
for range 4 {
|
|
view.Editor.Edit(view, gocui.KeySpace, ' ', 0)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
return self.switchToCommitMessage()
|
|
}
|
|
|
|
func (self *CommitDescriptionController) close() error {
|
|
self.c.Helpers().Commits.CloseCommitMessagePanel()
|
|
return nil
|
|
}
|
|
|
|
func (self *CommitDescriptionController) confirm() error {
|
|
return self.c.Helpers().Commits.HandleCommitConfirm()
|
|
}
|
|
|
|
func (self *CommitDescriptionController) openCommitMenu() error {
|
|
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
|
|
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
|
|
}
|
|
|
|
func (self *CommitDescriptionController) onClick(opts gocui.ViewMouseBindingOpts) error {
|
|
// Activate the description panel when the commit message panel is currently active
|
|
if self.c.Context().Current().GetKey() == context.COMMIT_MESSAGE_CONTEXT_KEY {
|
|
self.c.Context().Replace(self.c.Contexts().CommitDescription)
|
|
}
|
|
|
|
return nil
|
|
}
|