Skip to content

Commit 4883c86

Browse files
authored
Fix non-sticky range select after clicking in staging view (jesseduffield#3998)
- **PR Description** When clicking in a single-file diff view to enter staging (or custom patch editing, when coming from the commit files panel), and then pressing shift-down or shift-up to select a range, it would move the selected line rather than creating a range. Only on the next press would it start to select a range from there. This is very similar to the fix we made for pressing escape in jesseduffield#3828. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents 052974b + a58770e commit 4883c86

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

pkg/gui/gui_driver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func (self *GuiDriver) Click(x, y int) {
5757
0,
5858
)
5959
self.waitTillIdle()
60+
self.gui.g.ReplayedEvents.MouseEvents <- gocui.NewTcellMouseEventWrapper(
61+
tcell.NewEventMouse(x, y, tcell.ButtonNone, 0),
62+
0,
63+
)
64+
self.waitTillIdle()
6065
}
6166

6267
// wait until lazygit is idle (i.e. all processing is done) before continuing

pkg/gui/patch_exploring/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (s *State) ToggleStickySelectRange() {
9494
}
9595

9696
func (s *State) ToggleSelectRange(sticky bool) {
97-
if s.selectMode == RANGE {
97+
if s.SelectingRange() {
9898
s.selectMode = LINE
9999
} else {
100100
s.selectMode = RANGE

pkg/integration/tests/ui/range_select.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
5050
shell.CreateFile("file1", fileContent)
5151
},
5252
Run: func(t *TestDriver, keys config.KeybindingConfig) {
53-
assertRangeSelectBehaviour := func(v *ViewDriver) {
53+
assertRangeSelectBehaviour := func(v *ViewDriver, otherView *ViewDriver, lineIdxOfFirstItem int) {
5454
v.
5555
SelectedLines(
5656
Contains("line 1"),
@@ -152,9 +152,21 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
152152
SelectedLines(
153153
Contains("line 10"),
154154
)
155+
156+
// Click in view, press shift+arrow -> nonsticky range
157+
otherView.Focus()
158+
v.Click(1, lineIdxOfFirstItem).
159+
SelectedLines(
160+
Contains("line 1"),
161+
).
162+
Press(keys.Universal.RangeSelectDown).
163+
SelectedLines(
164+
Contains("line 1"),
165+
Contains("line 2"),
166+
)
155167
}
156168

157-
assertRangeSelectBehaviour(t.Views().Commits().Focus())
169+
assertRangeSelectBehaviour(t.Views().Commits().Focus(), t.Views().Branches(), 0)
158170

159171
t.Views().Files().
160172
Focus().
@@ -163,6 +175,6 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
163175
).
164176
PressEnter()
165177

166-
assertRangeSelectBehaviour(t.Views().Staging().IsFocused())
178+
assertRangeSelectBehaviour(t.Views().Staging().IsFocused(), t.Views().Files(), 6)
167179
},
168180
})

0 commit comments

Comments
 (0)