1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-23 12:18:51 +02:00

Allow using </> and ,/. in sticky range select mode in patch explorer (#3837)

- **PR Description**

Don't cancel sticky range select when pressing `<`/`>`, `,`/`.` in the
patch explorer view. This was already working correctly in list views.

Fixes #3823.
This commit is contained in:
Stefan Haller 2024-08-24 10:59:48 +02:00 committed by GitHub
commit db40653202
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 9 deletions

View File

@ -244,14 +244,12 @@ func (self *PatchExplorerController) HandleScrollRight() error {
} }
func (self *PatchExplorerController) HandlePrevPage() error { func (self *PatchExplorerController) HandlePrevPage() error {
self.context.GetState().SetLineSelectMode()
self.context.GetState().AdjustSelectedLineIdx(-self.context.GetViewTrait().PageDelta()) self.context.GetState().AdjustSelectedLineIdx(-self.context.GetViewTrait().PageDelta())
return nil return nil
} }
func (self *PatchExplorerController) HandleNextPage() error { func (self *PatchExplorerController) HandleNextPage() error {
self.context.GetState().SetLineSelectMode()
self.context.GetState().AdjustSelectedLineIdx(self.context.GetViewTrait().PageDelta()) self.context.GetState().AdjustSelectedLineIdx(self.context.GetViewTrait().PageDelta())
return nil return nil

View File

@ -123,6 +123,12 @@ func (s *State) SetLineSelectMode() {
s.selectMode = LINE s.selectMode = LINE
} }
func (s *State) DismissHunkSelectMode() {
if s.SelectingHunk() {
s.selectMode = LINE
}
}
// For when you move the cursor without holding shift (meaning if we're in // For when you move the cursor without holding shift (meaning if we're in
// a non-sticky range select, we'll cancel it) // a non-sticky range select, we'll cancel it)
func (s *State) SelectLine(newSelectedLineIdx int) { func (s *State) SelectLine(newSelectedLineIdx int) {
@ -239,6 +245,7 @@ func (s *State) CurrentLineNumber() int {
} }
func (s *State) AdjustSelectedLineIdx(change int) { func (s *State) AdjustSelectedLineIdx(change int) {
s.DismissHunkSelectMode()
s.SelectLine(s.selectedLineIdx + change) s.SelectLine(s.selectedLineIdx + change)
} }
@ -255,12 +262,12 @@ func (s *State) PlainRenderSelected() string {
} }
func (s *State) SelectBottom() { func (s *State) SelectBottom() {
s.SetLineSelectMode() s.DismissHunkSelectMode()
s.SelectLine(s.patch.LineCount() - 1) s.SelectLine(s.patch.LineCount() - 1)
} }
func (s *State) SelectTop() { func (s *State) SelectTop() {
s.SetLineSelectMode() s.DismissHunkSelectMode()
s.SelectLine(0) s.SelectLine(0)
} }

View File

@ -14,6 +14,7 @@ import (
// (sticky range, press 'v') -> no range // (sticky range, press 'v') -> no range
// (sticky range, press 'escape') -> no range // (sticky range, press 'escape') -> no range
// (sticky range, press arrow) -> sticky range // (sticky range, press arrow) -> sticky range
// (sticky range, press `<`/`>` or `,`/`.`) -> sticky range
// (sticky range, press shift+arrow) -> nonsticky range // (sticky range, press shift+arrow) -> nonsticky range
// (nonsticky range, press 'v') -> no range // (nonsticky range, press 'v') -> no range
// (nonsticky range, press 'escape') -> no range // (nonsticky range, press 'escape') -> no range
@ -138,19 +139,18 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
SelectedLines( SelectedLines(
Contains("line 8"), Contains("line 8"),
). ).
// (sticky range, press '>') -> sticky range
Press(keys.Universal.ToggleRangeSelect). Press(keys.Universal.ToggleRangeSelect).
SelectedLines( Press(keys.Universal.GotoBottom).
Contains("line 8"),
).
SelectNextItem().
SelectedLines( SelectedLines(
Contains("line 8"), Contains("line 8"),
Contains("line 9"), Contains("line 9"),
Contains("line 10"),
). ).
// (sticky range, press 'escape') -> no range // (sticky range, press 'escape') -> no range
PressEscape(). PressEscape().
SelectedLines( SelectedLines(
Contains("line 9"), Contains("line 10"),
) )
} }