Skip to content

Commit

Permalink
Fix non-sticky range select after clicking in staging view (#3998)
Browse files Browse the repository at this point in the history
- **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 #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
  • Loading branch information
stefanhaller authored Oct 18, 2024
2 parents 052974b + a58770e commit 4883c86
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/gui/gui_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (self *GuiDriver) Click(x, y int) {
0,
)
self.waitTillIdle()
self.gui.g.ReplayedEvents.MouseEvents <- gocui.NewTcellMouseEventWrapper(
tcell.NewEventMouse(x, y, tcell.ButtonNone, 0),
0,
)
self.waitTillIdle()
}

// wait until lazygit is idle (i.e. all processing is done) before continuing
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/patch_exploring/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *State) ToggleStickySelectRange() {
}

func (s *State) ToggleSelectRange(sticky bool) {
if s.selectMode == RANGE {
if s.SelectingRange() {
s.selectMode = LINE
} else {
s.selectMode = RANGE
Expand Down
18 changes: 15 additions & 3 deletions pkg/integration/tests/ui/range_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
shell.CreateFile("file1", fileContent)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
assertRangeSelectBehaviour := func(v *ViewDriver) {
assertRangeSelectBehaviour := func(v *ViewDriver, otherView *ViewDriver, lineIdxOfFirstItem int) {
v.
SelectedLines(
Contains("line 1"),
Expand Down Expand Up @@ -152,9 +152,21 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
SelectedLines(
Contains("line 10"),
)

// Click in view, press shift+arrow -> nonsticky range
otherView.Focus()
v.Click(1, lineIdxOfFirstItem).
SelectedLines(
Contains("line 1"),
).
Press(keys.Universal.RangeSelectDown).
SelectedLines(
Contains("line 1"),
Contains("line 2"),
)
}

assertRangeSelectBehaviour(t.Views().Commits().Focus())
assertRangeSelectBehaviour(t.Views().Commits().Focus(), t.Views().Branches(), 0)

t.Views().Files().
Focus().
Expand All @@ -163,6 +175,6 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
).
PressEnter()

assertRangeSelectBehaviour(t.Views().Staging().IsFocused())
assertRangeSelectBehaviour(t.Views().Staging().IsFocused(), t.Views().Files(), 6)
},
})

0 comments on commit 4883c86

Please sign in to comment.