diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-01-24 08:26:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-24 08:26:33 +0100 |
commit | 74d937881edf7e3271976fa7484286c82650fb2e (patch) | |
tree | 58989a61a94ce6d1bf712d428b52c0a25eac3de8 | |
parent | 9cd69e46df8fda7ba7208e1cfa54b8f1f0c6824b (diff) | |
parent | e72c759541cb93e11940a32c18660f1358afa47a (diff) |
Make range selections created with the mouse non-sticky (#3234)
- **PR Description**
I prefer this because I almost never use sticky range selections, but
I'm not sure everybody agrees. Also, this fixes the issue that just
clicking a line in a diff (without dragging) already creates a range
selection. It still does, technically, but it's no longer a problem
because a non-sticky one-line range selection behaves the same as a
non-range selection.
See #3233.
-rw-r--r-- | pkg/gui/controllers/patch_explorer_controller.go | 2 | ||||
-rw-r--r-- | pkg/gui/patch_exploring/state.go | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/pkg/gui/controllers/patch_explorer_controller.go b/pkg/gui/controllers/patch_explorer_controller.go index caac1f51c..957705bd1 100644 --- a/pkg/gui/controllers/patch_explorer_controller.go +++ b/pkg/gui/controllers/patch_explorer_controller.go @@ -274,7 +274,7 @@ func (self *PatchExplorerController) HandleMouseDown() error { } func (self *PatchExplorerController) HandleMouseDrag() error { - self.context.GetState().SelectLine(self.context.GetViewTrait().SelectedLineIdx()) + self.context.GetState().DragSelectLine(self.context.GetViewTrait().SelectedLineIdx()) return nil } diff --git a/pkg/gui/patch_exploring/state.go b/pkg/gui/patch_exploring/state.go index ccd30d03f..730deb0c1 100644 --- a/pkg/gui/patch_exploring/state.go +++ b/pkg/gui/patch_exploring/state.go @@ -49,12 +49,10 @@ func NewState(diff string, selectedLineIdx int, oldState *State, log *logrus.Ent } selectMode := LINE - rangeIsSticky := false // if we have clicked from the outside to focus the main view we'll pass in a non-negative line index so that we can instantly select that line if selectedLineIdx >= 0 { selectMode = RANGE rangeStartLineIdx = selectedLineIdx - rangeIsSticky = true } else if oldState != nil { // if we previously had a selectMode of RANGE, we want that to now be line again if oldState.selectMode == HUNK { @@ -70,7 +68,7 @@ func NewState(diff string, selectedLineIdx int, oldState *State, log *logrus.Ent selectedLineIdx: selectedLineIdx, selectMode: selectMode, rangeStartLineIdx: rangeStartLineIdx, - rangeIsSticky: rangeIsSticky, + rangeIsSticky: false, diff: diff, } } @@ -150,7 +148,12 @@ func (s *State) SelectNewLineForRange(newSelectedLineIdx int) { s.rangeStartLineIdx = newSelectedLineIdx s.selectMode = RANGE - s.rangeIsSticky = true + + s.selectLineWithoutRangeCheck(newSelectedLineIdx) +} + +func (s *State) DragSelectLine(newSelectedLineIdx int) { + s.selectMode = RANGE s.selectLineWithoutRangeCheck(newSelectedLineIdx) } |