mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +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
menu_controller.go
merge_conflicts_controller.go
options_menu_action.go
patch_building_controller.go
patch_explorer_controller.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_sub_commits_controller.go
sync_controller.go
tags_controller.go
toggle_whitespace_action.go
undo_controller.go
vertical_scroll_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
go.mod
go.sum
main.go
88 lines
2.5 KiB
Go
88 lines
2.5 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type SuggestionsController struct {
|
|
baseController
|
|
*ListControllerTrait[*types.Suggestion]
|
|
c *ControllerCommon
|
|
}
|
|
|
|
var _ types.IController = &SuggestionsController{}
|
|
|
|
func NewSuggestionsController(
|
|
c *ControllerCommon,
|
|
) *SuggestionsController {
|
|
return &SuggestionsController{
|
|
baseController: baseController{},
|
|
ListControllerTrait: NewListControllerTrait[*types.Suggestion](
|
|
c,
|
|
c.Contexts().Suggestions,
|
|
c.Contexts().Suggestions.GetSelected,
|
|
c.Contexts().Suggestions.GetSelectedItems,
|
|
),
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
func (self *SuggestionsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
|
bindings := []*types.Binding{
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.Confirm),
|
|
Handler: func() error { return self.context().State.OnConfirm() },
|
|
GetDisabledReason: self.require(self.singleItemSelected()),
|
|
},
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.Return),
|
|
Handler: func() error { return self.context().State.OnClose() },
|
|
},
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.TogglePanel),
|
|
Handler: self.switchToConfirmation,
|
|
},
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.Remove),
|
|
Handler: func() error {
|
|
return self.context().State.OnDeleteSuggestion()
|
|
},
|
|
},
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.Edit),
|
|
Handler: func() error {
|
|
if self.context().State.AllowEditSuggestion {
|
|
if selectedItem := self.c.Contexts().Suggestions.GetSelected(); selectedItem != nil {
|
|
self.c.Contexts().Confirmation.GetView().TextArea.Clear()
|
|
self.c.Contexts().Confirmation.GetView().TextArea.TypeString(selectedItem.Value)
|
|
self.c.Contexts().Confirmation.GetView().RenderTextArea()
|
|
self.c.Contexts().Suggestions.RefreshSuggestions()
|
|
return self.switchToConfirmation()
|
|
}
|
|
}
|
|
return nil
|
|
},
|
|
},
|
|
}
|
|
|
|
return bindings
|
|
}
|
|
|
|
func (self *SuggestionsController) switchToConfirmation() error {
|
|
self.c.Views().Suggestions.Subtitle = ""
|
|
self.c.Views().Suggestions.Highlight = false
|
|
self.c.Context().Replace(self.c.Contexts().Confirmation)
|
|
return nil
|
|
}
|
|
|
|
func (self *SuggestionsController) GetOnFocusLost() func(types.OnFocusLostOpts) {
|
|
return func(types.OnFocusLostOpts) {
|
|
self.c.Helpers().Confirmation.DeactivateConfirmationPrompt()
|
|
}
|
|
}
|
|
|
|
func (self *SuggestionsController) context() *context.SuggestionsContext {
|
|
return self.c.Contexts().Suggestions
|
|
}
|