From cbb214a08a08c36b0c48a43aab1b5de74604da68 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 10 Nov 2026 09:35:32 +0100 Subject: [PATCH] Toggle the staging of a file on double-click again Since 0.66, double-clicking a file in the files panel focuses its diff in the main view. Before that, it staged or unstaged the file, like pressing space. Users who staged files with the mouse no longer have a way to do that (see #6115 and #6200). The change made double-click consistent with enter, as in the other panels. Mouse users don't need it to get to the diff, though; clicking the diff in the main view focuses it too. Make double-click toggle the staged state again. Space refuses to stage a nested repository, and double-click has to do the same. Check the same disabled reason before staging, and show it as a toast like the keybinding does. Co-Authored-By: Claude Opus 5.5 --- pkg/gui/controllers/files_controller.go | 10 ++- .../file/double_click_toggles_staging.go | 61 +++++++++++++++++++ .../tests/file/stage_nested_repository.go | 8 +++ .../enter_and_double_click_focus_file_diff.go | 8 --- pkg/integration/tests/test_list.go | 1 + 5 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 pkg/integration/tests/file/double_click_toggles_staging.go diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 3037943c5..5ed7109b2 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -473,7 +473,15 @@ func (self *FilesController) GetFocusedMainViewDiffSource() types.FocusedMainVie } func (self *FilesController) GetOnDoubleClick() func() error { - return self.enter + return self.withItemGraceful(func(node *filetree.FileNode) error { + nodes := []*filetree.FileNode{node} + if disabledReason := self.canStageSelection(nodes); disabledReason != nil { + self.c.ErrorToast(self.c.Tr.DisabledMenuItemPrefix + disabledReason.Text) + return nil + } + + return self.press(nodes) + }) } // if we are dealing with a status for which there is no key in this map, diff --git a/pkg/integration/tests/file/double_click_toggles_staging.go b/pkg/integration/tests/file/double_click_toggles_staging.go new file mode 100644 index 000000000..84386414a --- /dev/null +++ b/pkg/integration/tests/file/double_click_toggles_staging.go @@ -0,0 +1,61 @@ +package file + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DoubleClickTogglesStaging = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Double-clicking a file or directory toggles whether it is staged", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFile("dir/file1", "") + shell.CreateFile("dir/file2", "") + shell.CreateFile("file3", "") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Lines( + Equals("▼ /").IsSelected(), + Equals(" ▼ dir"), + Equals(" ?? file1"), + Equals(" ?? file2"), + Equals(" ?? file3"), + ). + DoubleClick(6, 4). + Lines( + Equals("▼ /"), + Equals(" ▼ dir"), + Equals(" ?? file1"), + Equals(" ?? file2"), + Equals(" A file3").IsSelected(), + ). + DoubleClick(5, 1). + Lines( + Equals("▼ /"), + Equals(" ▼ dir").IsSelected(), + Equals(" A file1"), + Equals(" A file2"), + Equals(" A file3"), + ). + DoubleClick(6, 4). + Lines( + Equals("▼ /"), + Equals(" ▼ dir"), + Equals(" A file1"), + Equals(" A file2"), + Equals(" ?? file3").IsSelected(), + ). + DoubleClick(5, 1). + Lines( + Equals("▼ /"), + Equals(" ▼ dir").IsSelected(), + Equals(" ?? file1"), + Equals(" ?? file2"), + Equals(" ?? file3"), + ) + }, +}) diff --git a/pkg/integration/tests/file/stage_nested_repository.go b/pkg/integration/tests/file/stage_nested_repository.go index 7776af656..c51d64df3 100644 --- a/pkg/integration/tests/file/stage_nested_repository.go +++ b/pkg/integration/tests/file/stage_nested_repository.go @@ -38,6 +38,14 @@ var StageNestedRepository = NewIntegrationTest(NewIntegrationTestArgs{ Tap(func() { t.ExpectToast(Equals("Disabled: Can't stage 'modules/sub' because it is a git repository of its own. Discard it with d, or ignore it with i.")) }). + DoubleClick(5, 1). + Tap(func() { + t.ExpectToast(Equals("Disabled: Can't stage 'modules/sub' because it is a git repository of its own. Discard it with d, or ignore it with i.")) + }). + Lines( + Equals("?? file"), + Equals("?? modules/sub (removed submodule)").IsSelected(), + ). // Staging all files works if the nested repository is filtered out FilterOrSearch("file"). Lines( diff --git a/pkg/integration/tests/main_view/enter_and_double_click_focus_file_diff.go b/pkg/integration/tests/main_view/enter_and_double_click_focus_file_diff.go index cfcebfa57..e408dcde4 100644 --- a/pkg/integration/tests/main_view/enter_and_double_click_focus_file_diff.go +++ b/pkg/integration/tests/main_view/enter_and_double_click_focus_file_diff.go @@ -30,14 +30,6 @@ var EnterAndDoubleClickFocusFileDiff = NewIntegrationTest(NewIntegrationTestArgs SelectedLines(Contains("-base")). PressEscape() - t.Views().Files(). - IsFocused(). - DoubleClick(3, 0) - t.Views().Main(). - IsFocused(). - SelectedLines(Contains("-base")). - PressEscape() - t.Views().Commits(). Focus(). Lines( diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 79d40de3e..ac42aa5ae 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -297,6 +297,7 @@ var tests = []*components.IntegrationTest{ file.DiscardUnstagedRangeSelect, file.DiscardVariousChanges, file.DiscardVariousChangesRangeSelect, + file.DoubleClickTogglesStaging, file.ExcludeWithoutInfoDir, file.ExplainNestedRepositories, file.ExplainUntrackedDirectory,