mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-21 04:46:29 +03:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
f794d3460d
commit
cbb214a08a
5 files changed
+79
-9
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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"),
|
||||
)
|
||||
},
|
||||
})
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -297,6 +297,7 @@ var tests = []*components.IntegrationTest{
|
||||
file.DiscardUnstagedRangeSelect,
|
||||
file.DiscardVariousChanges,
|
||||
file.DiscardVariousChangesRangeSelect,
|
||||
file.DoubleClickTogglesStaging,
|
||||
file.ExcludeWithoutInfoDir,
|
||||
file.ExplainNestedRepositories,
|
||||
file.ExplainUntrackedDirectory,
|
||||
|
||||
Reference in new issue
Block a user